-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrevocation_test.go
123 lines (107 loc) · 5.01 KB
/
revocation_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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//go:build certificateExpired
// +build certificateExpired
// TODO: Rework tests, these currently fail because of expired certificate
package sign
import (
"crypto/x509"
"encoding/pem"
"testing"
"github.com/digitorus/pdfsign/revocation"
)
const certPem = `-----BEGIN CERTIFICATE-----
MIIGKDCCBRCgAwIBAgIMW8J4m7huCPO5f+wbMA0GCSqGSIb3DQEBCwUAMEsxCzAJ
BgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSEwHwYDVQQDExhH
bG9iYWxTaWduIENBIDIgZm9yIEFBVEwwHhcNMTcwNzA2MDk0MDUyWhcNMjAwNzA2
MDk0MDUyWjCBpzELMAkGA1UEBhMCR0IxDTALBgNVBAgTBEtlbnQxEjAQBgNVBAcT
CU1haWRzdG9uZTEfMB0GA1UEChMWR01PIEdsb2JhbFNpZ24gTGltaXRlZDEfMB0G
A1UEAxMWUGF1bCBWYW4gQnJvdXdlcnNoYXZlbjEzMDEGCSqGSIb3DQEJARYkcGF1
bC52YW5icm91d2Vyc2hhdmVuQGdsb2JhbHNpZ24uY29tMIIBIjANBgkqhkiG9w0B
AQEFAAOCAQ8AMIIBCgKCAQEAr5jbAIZDjkWngxlwJqneE9VEDTvmMIGwvgy71g5j
k+igHxB6tTfaqGD87oIm2wcrlZHpPJG9n2Rh9FhFmvx8ZXiceNI9Ks5Ho5iYNFUk
y2JuVfFPxtp6amqpL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CdcpzRuy20CI7E4uygD8
-----END CERTIFICATE-----`
func TestEmbedRevocationStatus(t *testing.T) {
var ia revocation.InfoArchival
err := DefaultEmbedRevocationStatusFunction(pemToCert(certPem), pemToCert(issuerPem), &ia)
if err != nil {
t.Errorf("%s", err.Error())
}
if len(ia.OCSP) != 1 {
t.Errorf("Expected one OCSP status")
}
}
func TestEmbedOCSPRevocationStatus(t *testing.T) {
var ia revocation.InfoArchival
err := embedOCSPRevocationStatus(pemToCert(certPem), pemToCert(issuerPem), &ia)
if err != nil {
t.Errorf("%s", err.Error())
}
if len(ia.OCSP) != 1 {
t.Errorf("Expected one OCSP status")
}
}
func TestEmbedCRLRevocationStatus(t *testing.T) {
var ia revocation.InfoArchival
err := embedCRLRevocationStatus(pemToCert(certPem), nil, &ia)
if err != nil {
t.Errorf("%s", err.Error())
}
if len(ia.CRL) != 1 {
t.Errorf("Expected one CRL")
}
}
func pemToCert(p string) *x509.Certificate {
block, _ := pem.Decode([]byte(p))
cert, _ := x509.ParseCertificate(block.Bytes)
return cert
}