-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtests.bats
executable file
·62 lines (53 loc) · 1.83 KB
/
tests.bats
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
#!/usr/bin/env bats
setup() {
PATH="$BATS_TEST_DIRNAME:$PATH"
WORKDIR=$(mktemp -d)
cd "$WORKDIR" || exit
}
teardown() {
rm -rf "$WORKDIR"
}
@test "Run without arguments" {
run ownca
[[ $status == 1 ]]
}
@test "Generate CA" {
ownca ca
test -f certindex.txt
test -d certs
test -d private
test -f private/cakey.crt
openssl x509 -in cacert.crt -noout -text | grep "Subject: CN = OwnCA"
}
@test "Generate CA with custom subject" {
ownca ca "/C=NL/CN=My Custom CA"
test -f certindex.txt
test -d certs
test -d private
test -f private/cakey.crt
openssl x509 -in cacert.crt -noout -text | grep "Subject: C = NL, CN = My Custom CA"
openssl x509 -in cacert.crt -noout -text | grep "CA:TRUE"
}
@test "Call cert without an argument" {
run ownca cert
[[ $status == 1 ]]
}
@test "Call cert without a CA" {
run ownca cert host.example.com
[[ $status == 2 ]]
}
@test "Generate certificate" {
ownca ca
ownca cert host.example.com
echo
echo "Generated certificate - verifying"
test -f serial
test -f host.example.com/host.example.com.req
test -f host.example.com/host.example.com.key
test -f host.example.com/host.example.com.crt
openssl x509 -in host.example.com/host.example.com.crt -noout -text
openssl x509 -in host.example.com/host.example.com.crt -noout -text | grep -q "Issuer: CN = OwnCA"
openssl x509 -in host.example.com/host.example.com.crt -noout -text | grep -q "Subject: CN = host.example.com"
openssl x509 -in host.example.com/host.example.com.crt -noout -text | grep -q "CA:FALSE"
openssl x509 -in host.example.com/host.example.com.crt -noout -text | grep -q "DNS:host.example.com"
}