-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.sh
executable file
·74 lines (54 loc) · 1.75 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
#!/bin/sh
#
# Test harness to verify that gen-webid-cert.sh is working
#
# Avoid clobbering an existing key/certificate
if [ -e webid.pem -o -e webid.p12 ]; then
echo >&2 "Error: webid.pem or webid.p12 exists."
echo >&2 "Please remove before running the test suite."
exit 1
fi
failures=0
assert() {
eval "${1}"
if [ $? -eq 0 ]; then
echo " ✓ ${2}"
else
echo " ✗ ${2}"
failures=$((failures+1))
fi
}
# Settings
name="Test User"
uri="http://example.com/test#id"
cn=""
genp12='N'
addtokeychain='N'
# Run the script
input="$name\n$uri\n$cn\n$genp12\n$addtokeychain\n"
output="$(printf "$input" | ./gen-webid-cert.sh 2>&1)"
result="$?"
# Verify that it worked
assert "[ '$result' -eq 0 ]" "Script returns status of 0"
assert "[ -e webid.pem ]" "Creates a file called webid.pem"
assert "echo '$output' | grep -Eq '<foaf:name>Test User</foaf:name>'" "RDF output contains <foaf:name>"
subject="$(openssl x509 -noout -subject -in webid.pem 2>&1)"
assert "echo '$subject' | grep -Eq '$name'" "Cert subject contains the user's name"
# Clean up any files we created
rm -f webid.pem webid.p12
# Run the script with a custom name
cn="Custom CN"
input="$name\n$uri\n$cn\n$genp12\n$addtokeychain\n"
output="$(printf "$input" | ./gen-webid-cert.sh 2>&1)"
result="$?"
# Verify that it worked
assert "[ '$result' -eq 0 ]" "Script returns status of 0"
assert "[ -e webid.pem ]" "Creates a file called webid.pem"
assert "echo '$output' | grep -Eq '<foaf:name>Test User</foaf:name>'" "RDF output contains <foaf:name>"
subject="$(openssl x509 -noout -subject -in webid.pem 2>&1)"
assert "echo '$subject' | grep -Eq '$cn'" "Cert subject contains the custom CN"
# Clean up any files we created
rm -f webid.pem webid.p12
echo
echo "$failures tests failed"
exit $failures