-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cert_test.go
72 lines (63 loc) · 1.81 KB
/
cert_test.go
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
package cert
import (
"crypto/x509"
"crypto/x509/pkix"
"math/big"
"testing"
"time"
)
func TestCA_IsExpired(t *testing.T) {
isMacOS = func() bool { return true }
ca := CA{
cert: &x509.Certificate{
SerialNumber: big.NewInt(123),
Subject: pkix.Name{
Organization: []string{"Symfony tests"},
OrganizationalUnit: []string{"Symfony tests"},
},
NotBefore: time.Now(),
NotAfter: time.Now().AddDate(0, 0, 825),
},
}
if got, want := ca.IsExpired(), false; got != want {
t.Errorf("IsExpired() = %v, want %v", got, want)
}
if got, want := ca.MustBeRegenerated(), false; got != want {
t.Errorf("MustBeRegenerated() = %v, want %v", got, want)
}
ca = CA{
cert: &x509.Certificate{
SerialNumber: big.NewInt(123),
Subject: pkix.Name{
Organization: []string{"Symfony tests"},
OrganizationalUnit: []string{"Symfony tests"},
},
NotBefore: time.Unix(0, 0),
NotAfter: time.Unix(0, 0).AddDate(0, 0, 3650),
},
}
if got, want := ca.IsExpired(), true; got != want {
t.Errorf("IsExpired() = %v, want %v", got, want)
}
if got, want := ca.MustBeRegenerated(), false; got != want {
t.Errorf("MustBeRegenerated() = %v, want %v", got, want)
}
ca = CA{
cert: &x509.Certificate{
SerialNumber: big.NewInt(123),
Subject: pkix.Name{
Organization: []string{"Symfony tests"},
OrganizationalUnit: []string{"Symfony tests"},
},
NotBefore: time.Date(2019, 8, 1, 0, 0, 0, 0, time.UTC),
NotAfter: time.Date(2029, 8, 1, 0, 0, 0, 0, time.UTC),
},
}
if got, want := ca.MustBeRegenerated(), true; got != want {
t.Errorf("MustBeRegenerated() [for macOS] = %v, want %v", got, want)
}
isMacOS = func() bool { return false }
if got, want := ca.MustBeRegenerated(), false; got != want {
t.Errorf("MustBeRegenerated() [for non macOS] = %v, want %v", got, want)
}
}