-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·107 lines (87 loc) · 1.97 KB
/
test.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
100
101
102
103
104
105
106
107
#!/bin/sh
test_status=0
red() {
echo "$(tput setaf 1)$1$(tput sgr 0)\c"
test_status=1
}
green() {
echo "$(tput setaf 2)$1$(tput sgr 0)\c"
}
assert() {
if [ $# -ne 2 ]; then
red "[KO] "
return 0
fi
if [ -z "$1" ]; then
red "[KO] "
return 0
fi
if [ -z "$2" ]; then
red "[KO] "
return 0
fi
if [ "$1" = "$2" ]; then
green "[OK] "
else
red "[KO] "
fi
}
# assert_ok() {
# assert $1 "OK"
# }
#
# assert_error() {
# assert $1 "Error"
# }
#
assert_md5() {
assert `./ft_ssl md5 $1 2>&1` `md5 $1 2>&1`
}
assert_sha256() {
assert `./ft_ssl md5 $1 2>&1` `openssl sha -sha256 $1 2>&1`
}
echo "Usage: \c"
assert "`./ft_ssl 2>&1`" "usage: ./ft_ssl command [command opts] [command args]"
assert "`./ft_ssl foo 2>&1`"<<EOF
ft_ssl: Error: 'foo' is an invalid command.
Standard commands:
Message Digest commands:
md5
sha256
Cipher commands:
EOF
echo "\nArgument Error: \c"
assert_md5 "-a"
assert_md5 "-foo"
assert_md5 "-foo foobar.tmp"
assert_md5 "-foo README.md"
assert_md5 "foobar.tmp"
echo "\nFiles: \c"
assert_md5 "README.md"
assert_md5 "README.md LICENCE"
assert_md5 "README.md foobar.tmp LICENCE"
echo "\nQuiet: \c"
assert_md5 "-q foobar.tmp"
assert_md5 "-q README.md"
assert_md5 "-q README.md LICENCE"
assert_md5 "-q README.md foobar.tmp LICENCE"
echo "\nString: \c"
assert_md5 "-s bonjour"
assert_md5 "-s bonjour -s 'aurevoir'"
assert_md5 "-sbonjour -s'aurevoir'"
assert_md5 "-s\"bonjour\" -syo'aurevoir'"
echo "\nReverse: \c"
assert_md5 "-r -s bonjour"
assert_md5 "-r -s bonjour -s 'aurevoir'"
assert_md5 "-sbonjour -rs'aurevoir'"
assert_md5 "-r -rs\"bonjour\" -syo'aurevoir'"
assert_md5 "-r README.md"
assert_md5 "README.md -r LICENCE"
assert_md5 "README.md -r fowbar.tmp -r LICENCE"
assert_md5 "-q -r README.md"
echo "\nPipe: \c"
echo "yoyoyo" | assert_md5 "-p -r -s bonjour"
echo "vvvvvvvvvv" | assert_md5 "-sbonjour -p -rs'aurevoir'"
echo "asdfkajhsdfjh" | assert_md5 "-p README.md -r fowbar.tmp -r LICENCE"
echo "helpplz" | assert_md5 "-p -r README.md"
exit $test_status