<commit_before>##############################################################################
#
# Copyright 2015 spf-tools team (see AUTHORS)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.
#
##############################################################################

a="/$0"; a=${a%/*}; a=${a#/}; a=${a:-.}; BINDIR=$(cd $a; pwd)
tmp=$(mktemp /tmp/spf-test-unit-XXXXXXXXX)
trap "rm $tmp*" EXIT
. $BINDIR/../include/despf.inc.sh
export LC_ALL=C
export LANG=C

testexpect() {
  IN=0
  test $1 = "-n" && { shift; > $tmp-out; } || cat > $tmp-out
  EXPRET=$1
  shift

  echo .. Testing $* ...
  set +e
  eval "$@" > $tmp-real 2>&1
  RETURN=$?
  set -e
  test -s $tmp-out && { sort $tmp-real | diff -u $tmp-out -; }
  test $EXPRET -eq $RETURN
  echo .... OK
}

testexpect 0 mydig -t TXT spf-tools.ml <<EOF
"v=spf1 include:spf1.spf-tools.ml ~all"
EOF

testexpect 0 "mydig -t NS spf-tools.ml | sort" <<EOF
chris.ns.cloudflare.com.
dawn.ns.cloudflare.com.
EOF

#testexpect 0 "mydig_notshort -t A cname.spf-tools.ml @dawn.ns.cloudflare.com." <<EOF
#cname.spf-tools.ml.	300	IN	CNAME	both.spf-tools.ml.
#both.spf-tools.ml.	300	IN	A	1.2.3.4
#EOF

testexpect 0 findns one.spf-tools.ml <<EOF
ns1.he.net.
EOF

testexpect -n 1 findns orig.non-existent.nonnon

cat > $tmp <<EOF
1.2.3.4
fdf8:f53e:61e4::18
EOF
testexpect 0 "cat $tmp | printip" <<EOF
ip4:1.2.3.4
ip6:fdf8:f53e:61e4::18
EOF

cat > $tmp <<EOF
1.2.3.4
test
fdf8:f53e:61e4::18
EOF
testexpect 1 "cat $tmp | printip" <<EOF
ip4:1.2.3.4
EOF

testexpect 0 dea both.spf-tools.ml <<EOF
ip4:1.2.3.4
ip6:fdf8:f53e:61e4::18
EOF

testexpect 0 dea cname.spf-tools.ml <<EOF
ip4:1.2.3.4
ip6:fdf8:f53e:61e4::18
EOF

testexpect 0 demx mx.spf-tools.ml <<EOF
ip4:5.6.7.8
ip6:fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b
EOF

testexpect 0 parsepf spf-tools.ml <<EOF
v=spf1 include:spf1.spf-tools.ml ~all
EOF

# This tests the correct process of iteration
# between different NS servers if one is not
# responding
testexpect 0 parsepf morens.spf-tools.ml <<EOF
v=spf1 include:spf1.spf-tools.ml ~all
EOF

testexpect -n 1 parsepf mail.spf-tools.ml

testexpect -n 1 isincidrange.sh 172.16.31.10 172.16.58.3 32

testexpect -n 0 isincidrange.sh 192.168.5.1 192.168.0.0 16<commit_msg>test-unit.sh: Add tests for cidr parameters of dea and demx<commit_after>##############################################################################
#
# Copyright 2015 spf-tools team (see AUTHORS)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.
#
##############################################################################

a="/$0"; a=${a%/*}; a=${a#/}; a=${a:-.}; BINDIR=$(cd $a; pwd)
tmp=$(mktemp /tmp/spf-test-unit-XXXXXXXXX)
trap "rm $tmp*" EXIT
. $BINDIR/../include/despf.inc.sh
export LC_ALL=C
export LANG=C

testexpect() {
  IN=0
  test $1 = "-n" && { shift; > $tmp-out; } || cat > $tmp-out
  EXPRET=$1
  shift

  echo .. Testing $* ...
  set +e
  eval "$@" > $tmp-real 2>&1
  RETURN=$?
  set -e
  test -s $tmp-out && { sort $tmp-real | diff -u $tmp-out -; }
  test $EXPRET -eq $RETURN
  echo .... OK
}

testexpect 0 mydig -t TXT spf-tools.ml <<EOF
"v=spf1 include:spf1.spf-tools.ml ~all"
EOF

testexpect 0 "mydig -t NS spf-tools.ml | sort" <<EOF
chris.ns.cloudflare.com.
dawn.ns.cloudflare.com.
EOF

#testexpect 0 "mydig_notshort -t A cname.spf-tools.ml @dawn.ns.cloudflare.com." <<EOF
#cname.spf-tools.ml.	300	IN	CNAME	both.spf-tools.ml.
#both.spf-tools.ml.	300	IN	A	1.2.3.4
#EOF

testexpect 0 findns one.spf-tools.ml <<EOF
ns1.he.net.
EOF

testexpect -n 1 findns orig.non-existent.nonnon

cat > $tmp <<EOF
1.2.3.4
fdf8:f53e:61e4::18
EOF
testexpect 0 "cat $tmp | printip" <<EOF
ip4:1.2.3.4
ip6:fdf8:f53e:61e4::18
EOF

cat > $tmp <<EOF
1.2.3.4
test
fdf8:f53e:61e4::18
EOF
testexpect 1 "cat $tmp | printip" <<EOF
ip4:1.2.3.4
EOF

testexpect 0 dea both.spf-tools.ml <<EOF
ip4:1.2.3.4
ip6:fdf8:f53e:61e4::18
EOF

testexpect 0 dea cname.spf-tools.ml <<EOF
ip4:1.2.3.4
ip6:fdf8:f53e:61e4::18
EOF

testexpect 0 dea cname.spf-tools.ml 24 <<EOF
ip4:1.2.3.4/24
ip6:fdf8:f53e:61e4::18/24
EOF

testexpect 0 demx mx.spf-tools.ml <<EOF
ip4:5.6.7.8
ip6:fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b
EOF

testexpect 0 demx mx.spf-tools.ml 24 <<EOF
ip4:5.6.7.8/24
ip6:fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b/24
EOF

testexpect 0 demx spf-tools.ml 24 <<EOF
ip4:192.168.3.11/24
ip4:172.16.17.32/24
ip4:172.16.17.32/24
ip4:64.38.239.85/24
ip4:192.168.127.12/24
ip4:172.16.31.10/24
EOF

testexpect 0 parsepf spf-tools.ml <<EOF
v=spf1 include:spf1.spf-tools.ml ~all
EOF

# This tests the correct process of iteration
# between different NS servers if one is not
# responding
testexpect 0 parsepf morens.spf-tools.ml <<EOF
v=spf1 include:spf1.spf-tools.ml ~all
EOF

testexpect -n 1 parsepf mail.spf-tools.ml

testexpect -n 1 isincidrange.sh 172.16.31.10 172.16.58.3 32

testexpect -n 0 isincidrange.sh 192.168.5.1 192.168.0.0 16
{'fraction_non_alphanumeric': 0.19623931623931623, 'fraction_numerical': 0.08341880341880342, 'mean_word_length': 3.756910569105691, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 32, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '189074', 'n_tokens_mistral': 2652, 'n_tokens_neox': 2421, 'n_words': 635}