-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshunit2-tests.sh
96 lines (79 loc) · 2.85 KB
/
shunit2-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
#!/bin/bash
t_="./ssh-vulnkey"
# prefixed by SHUNIT_TMPDIR
e_="id_rsa.pub"
ne_="nonexistend.pub"
oneTimeSetUp() {
# prefix variables because SHUNIT_TMPDIR is empty before shunit2 is sourced at the end of this file
e_="$SHUNIT_TMPDIR/$e_"
ne_="$SHUNIT_TMPDIR/$ne_"
# create one working key to test with
ssh-keygen -t rsa -b 1024 -C user@host -N "" -f $e_ >/dev/null
ret_=$?
assertEquals "problem creating test input keys for rsa 1024 bit" 0 $ret_
}
setUp() {
export TEST_ORIGINAL_PATH=$PATH
PATH=$PWD:$PWD/mock:$PATH
}
tearDown()
{
PATH=$TEST_ORIGINAL_PATH
}
testBasicFunctionality() {
$t_ $e_
ret_=$?
assertEquals 0 $ret_
}
testStrangeKeySizes() {
for i in 1025 2047; do
ssh-keygen -t rsa -b $i -C user@host -N "" -f $SHUNIT_TMPDIR/id_rsa${i}.pub >/dev/null
ret_=$?
assertEquals "problem creating test input keys rsa $i bits" 0 $ret_
$t_ $SHUNIT_TMPDIR/id_rsa${i}.pub 2>/dev/null
ret_=$?
assertEquals 0 $ret_
done
}
_testFailsWhenKeyFileDoesNotExist() {
local orig_args_="$@"
local ret_expected_=$1
shift
[[ $# == 3 ]] || fail "internal error, expected only 3 args but got $# (+1): $orig_args_"
$t_ "$@" &>/dev/null
ret_=$?
assertEquals "$t_ $* -" $ret_expected_ $ret_
}
testFailsWhenKeyFileDoesNotExist() {
[ -e $ne_ ] && fail "file $ne_ must not exist"
fixture_=('a=(1 $ne_ $ne_ $e_)' 'a=(1 $ne_ $e_ $ne_)' 'a=(1 $e_ $ne_ $ne_)' 'a=(0 $e_ $e_ $e_)')
for i in "${fixture_[@]}"; do
eval $i
_testFailsWhenKeyFileDoesNotExist ${a[@]}
done
}
testBlackBoxVulnerableKeyRSA1024() {
out_=$(TEST_PRINT_VULNERABLE_KEY=RSA1024 $t_ mocked_in_vulnerable_key 2>&1)
ret_=$?
assertEquals "AA:AA:AA:AA:AA:AA:42:fe:2d:91:b9:94:60:c8:4e:a0 mocked_in_vulnerable_key IS VULNERABLE" "$out_"
assertEquals "$t_ must return an error on vulnerable keys - " 1 "$ret_"
}
testBlackBoxVulnerableKeyRSA2048() {
out_=$(TEST_PRINT_VULNERABLE_KEY=RSA2048 $t_ mocked_in_vulnerable_key 2>&1)
ret_=$?
assertEquals "AA:AA:AA:AA:AA:AA:42:fe:9c:8b:c7:70:59:a6:11:9d mocked_in_vulnerable_key IS VULNERABLE" "$out_"
assertEquals "$t_ must return an error on vulnerable keys - " 1 "$ret_"
}
testBlackBoxVulnerableKeyRSA4096() {
out_=$(TEST_PRINT_VULNERABLE_KEY=RSA4096 $t_ mocked_in_vulnerable_key 2>&1)
ret_=$?
assertEquals "AA:AA:AA:AA:AA:AA:42:fe:f8:89:61:f3:8c:ff:0f:96 mocked_in_vulnerable_key IS VULNERABLE" "$out_"
assertEquals "$t_ must return an error on vulnerable keys - " 1 "$ret_"
}
testBlackBoxVulnerableKeyDSA1024() {
out_=$(TEST_PRINT_VULNERABLE_KEY=DSA1024 $t_ mocked_in_vulnerable_key 2>&1)
ret_=$?
assertEquals "AA:AA:AA:AA:AA:AA:42:fe:51:b4:8d:03:39:c7:d8:fd mocked_in_vulnerable_key IS VULNERABLE" "$out_"
assertEquals "$t_ must return an error on vulnerable keys - " 1 "$ret_"
}
. shunit2