-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·67 lines (52 loc) · 1.73 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
#!/bin/sh
# Accept password saved as bcrypt, also a second attempt (cached)
test=$(
cat <<EOF | node ./index.js http-basic-auth --realm='"node-red"' --username='"test"' --password='"$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6"'
{"req":{"headers":{"authorization":"Basic $(printf 'test:test' | base64 -w 0)"}}}
{"req":{"headers":{"authorization":"Basic $(printf 'test:test' | base64 -w 0)"}}}
EOF
)
if [ "$test" = "" ]; then
echo 'ERROR 1'
exit 1
fi
# Accept password saved as plain-text
test=$(
cat <<EOF | node ./index.js http-basic-auth --realm='"node-red"' --username='"test"' --password='"test"'
{"req":{"headers":{"authorization":"Basic $(printf 'test:test' | base64 -w 0)"}}}
EOF
)
if [ "$test" = "" ]; then
echo 'ERROR 2'
exit 1
fi
# Reject wrong user
test=$(
cat <<EOF | node ./index.js http-basic-auth --realm='"node-red"' --username='"wrong"' --password='"test"'
{"req":{"headers":{"authorization":"Basic $(printf 'test:test' | base64 -w 0)"}}}
EOF
)
if [ "$test" != "" ]; then
echo 'ERROR 3'
exit 1
fi
# Reject wrong password
test=$(
cat <<EOF | node ./index.js http-basic-auth --realm='"node-red"' --username='"test"' --password='"wrong"'
{"req":{"headers":{"authorization":"Basic $(printf 'test:test' | base64 -w 0)"}}}
EOF
)
if [ "$test" != "" ]; then
echo 'ERROR 4'
exit 1
fi
# Do not accept bcrypt passwords as input (only plain-text passwords)
test=$(
cat <<EOF | node ./index.js http-basic-auth --realm='"node-red"' --username='"test"' --password='"$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6"'
{"req":{"headers":{"authorization":"Basic $(printf 'test:$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6' | base64 -w 0)"}}}
EOF
)
if [ "$test" != "" ]; then
echo 'ERROR 5'
exit 1
fi