-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathattestation_statement_test.go
36 lines (32 loc) · 1.08 KB
/
attestation_statement_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
package webauthn
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAttestationStatement_UnmarshalCertificate(t *testing.T) {
t.Run("valid", func(t *testing.T) {
response := readTestAuthenticatorAttestationResponse(t, "Packed")
attestationObject, err := response.UnmarshalAttestationObject()
require.NoError(t, err)
certs, err := attestationObject.Statement.UnmarshalCertificates()
assert.NoError(t, err)
assert.Equal(t,
"CN=FT BioPass FIDO2 USB,OU=Authenticator Attestation,O=Feitian Technologies,C=CN",
certs[0].Subject.String())
})
t.Run("missing x5c", func(t *testing.T) {
_, err := AttestationStatement{}.UnmarshalCertificates()
assert.ErrorIs(t, err, ErrMissingCertificate)
})
t.Run("invalid x5c", func(t *testing.T) {
_, err := AttestationStatement{
"x5c": "NOT_A_CERTIFICATE",
}.UnmarshalCertificates()
assert.ErrorIs(t, err, ErrInvalidCertificate)
_, err = AttestationStatement{
"x5c": []byte("NOT_A_CERTIFICATE"),
}.UnmarshalCertificates()
assert.ErrorIs(t, err, ErrInvalidCertificate)
})
}