forked from mozilla-services/pkcs7
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathparse_test.go
31 lines (25 loc) · 10.3 KB
/
parse_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
//go:build !go1.23
// +build !go1.23
package pkcs7
import (
"encoding/base64"
"testing"
)
func TestParseWindowsSCEPCertificateRequest(t *testing.T) {
// base64 encoded SCEP requests from a Windows device
b64 := `MIIcwQYJKoZIhvcNAQcCoIIcsjCCHK4CAQExCzAJBgUrDgMCGgUAMIIXSAYJKoZIhvcNAQcBoIIXOQSCFzUwghcxBgkqhkiG9w0BBwOgghciMIIXHgIBADGCAWUwggFhAgEAMEkwNDEQMA4GA1UEChMHU2Ftc2FyYTEgMB4GA1UEAxMXU2Ftc2FyYSBJbnRlcm1lZGlhdGUgQ0ECEQCRyXJ1g0nOjYBF0maXP1+oMA0GCSqGSIb3DQEBBzAABIIBAFU6gkMRWK9MP3v+jHehxa41LMR48q2647Bijo+SX/5sS94QDt1kfZrRCkQgGcecyCIw8f2TlCoiPK/fcm95btM7k3dYn7fy9uBFfYHY+qYNTqGNbPlvRluvjxNYKUzp4dEfmLXIa3gdtN2A6oYAsptYlgCi6uHzwWUhcYs3Mvv7hLGZeho9qHLXpov2qc6tXFlbbmgiT81eZvhwA7OWmVnc/xrzu7rjedAdgPaFUCYPNI83Rem5yBhzhpjHdDkQsriB4GhtD5kFdYEsxRk8YrVQn5BBzmWBxplINS5z5z5QvqigUv32GWdFNwcO8g+/rt+p/WLI8RSo8qTtWMvAo8UwghWuBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAECBBCsHo6ioyhyrIR1M8pdj97wgIIVgFH68BN0FfIUB3arcfeltwe/7N2nN34xkX43OPYnGmB7jlKhOD4AWJRRrxUenw7N5IPUryJl9ENVbYvKn4spUdODc1NPADBrO2yX5+P8c4nmMbCYDulU5AfufC9eqCUWj47N/af5XICyvvFZqD3wnLdN6ctPv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WNlNmI0MmEwMmQxNGZiZjANBgkqhkiG9w0BAQEFAASCAQA2hGuBgHFQJG/v6CeXrCbdvZ38jf3U97kMfFKjKuD/8Ljuv47D26hEmXPA+rFNuGQSQ+/QXMNky18DMaWGlkZ96LKnZSl6cOCHFVJMUHRks+MRAquzPM8nvD6i7Hb4tPARWRlRTXpBPsvlyXn/hqnqABiKR+cVySwJ6Q/qTvVjgh3rC6HYEVi/e+MBQjnrRQJTkyVsHiMVWAq2So2UcWm/RJX6GQN9Eyn6LXEH9N2cjSaJ4te5gU2gGApwdc4FdlwnM71YLLeK79ZvbGp9f1kLS4qyclsVWqvAPKx+T6lVrSofjCwrejrdpYmneu+6xMkjXhlbBBMpQOaH3UhYE+Nh`
data, err := base64.StdEncoding.DecodeString(b64)
if err != nil {
t.Errorf("failed decoding base64 SCEP request data: %v", err)
}
p7, err := Parse(data)
if err != nil {
t.Errorf("failed parsing SCEP request data: %v", err)
}
if len(p7.Certificates) != 1 {
t.Errorf("expected a single certificate; got %d", len(p7.Certificates))
}
if cn := p7.Certificates[0].Subject.CommonName; cn != "SCEP Protocol Certificate" {
t.Errorf("expected certificate subject common name to be SCEP Protocol Certificate; got %v", cn)
}
}