forked from ltb-project/ppm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_tests.sh
executable file
·100 lines (74 loc) · 2.25 KB
/
unit_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# Launch unitary tests
#
CONFIG_FILE="ppm.conf"
LIB_PATH="."
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
RESULT=0
PPM_CONF_1='minQuality 3
maxLength 0
checkRDN 0
forbiddenChars
maxConsecutivePerClass 0
useCracklib 0
cracklibDict /var/cache/cracklib/cracklib_dict
class-upperCase ABCDEFGHIJKLMNOPQRSTUVWXYZ 0 1
class-lowerCase abcdefghijklmnopqrstuvwxyz 0 1
class-digit 0123456789 0 1
class-special <>,?;.:/!§ù%*µ^¨$£²&é~"#'\''{([-|è`_\ç^à@)]°=}+ 0 1'
PPM_CONF_2='minQuality 3
maxLength 20
checkRDN 0
forbiddenChars à
maxConsecutivePerClass 5
useCracklib 0
cracklibDict /var/cache/cracklib/cracklib_dict
class-upperCase ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 4
class-lowerCase abcdefghijklmnopqrstuvwxyz 3 4
class-digit 0123456789 2 4
class-special <>,?;.:/!§ù%*µ^¨$£²&é~"#'\''{([-|è`_\ç^à@)]°=}+ 0 4'
echo "$PPM_CONF_1" > ppm1.conf
echo "$PPM_CONF_2" > ppm2.conf
launch_test()
{
# launch tests
# FORMAT: launch_test [conf_file] [password] [expected_result]
# [expected_result] = [PASS|FAIL]
local CONF="$1"
local PASS="$2"
local EXPECT="$3"
[[ $EXPECT == "PASS" ]] && EXP="0" || EXP="1"
PPM_CONFIG_FILE="${CONF}" LD_LIBRARY_PATH="${LIB_PATH}" ./ppm_test "${PASS}"
RES="$?"
if [ "$RES" -eq "$EXP" ] ; then
echo -e "conf=${CONF} pass=${PASS} expect=${EXPECT}... ${GREEN}PASS${NC}"
else
echo -e "conf=${CONF} pass=${PASS} expect=${EXPECT}... ${RED}FAIL${NC}"
((RESULT+=1))
fi
echo
}
launch_test "ppm1.conf" "azerty" "FAIL"
launch_test "ppm1.conf" "azeRTY" "FAIL"
launch_test "ppm1.conf" "azeRTY123" "PASS"
launch_test "ppm1.conf" "azeRTY." "PASS"
launch_test "ppm2.conf" "AAaaa01AAaaa01AAaaa0" "PASS"
# too long
launch_test "ppm2.conf" "AAaaa01AAaaa01AAaaa01" "FAIL"
# forbidden char
launch_test "ppm2.conf" "AAaaa01AAaaa01AAaaaà" "FAIL"
# too much consecutive for upper
launch_test "ppm2.conf" "AAaaa01AAaaa01AAAAAA" "FAIL"
# not enough upper
launch_test "ppm2.conf" "Aaaaa01aaaaa01aa.;.;" "FAIL"
# not enough lower
launch_test "ppm2.conf" "aaAAA01BB0123AAA.;.;" "FAIL"
# not enough digit
launch_test "ppm2.conf" "1AAAA.;BBB.;.;AA.;.;" "FAIL"
# not enough points (no point for digit)
launch_test "ppm2.conf" "AAaaaBBBBaaa01AAaaaa" "FAIL"
echo "${RESULT} error(s) encountered"
rm ppm1.conf ppm2.conf
exit ${RESULT}