-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcertificate_test.go
50 lines (41 loc) · 1.15 KB
/
certificate_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
package webauthn
import (
"crypto/ed25519"
"crypto/x509"
"crypto/x509/pkix"
"math/big"
"math/rand"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_getCertificateAAGUID(t *testing.T) {
random := rand.New(rand.NewSource(1))
pub, priv, err := ed25519.GenerateKey(random)
require.NoError(t, err)
t.Run("missing", func(t *testing.T) {
tpl := &x509.Certificate{
SerialNumber: big.NewInt(1),
}
bs, err := x509.CreateCertificate(random, tpl, tpl, pub, priv)
require.NoError(t, err)
certificate, err := x509.ParseCertificate(bs)
require.NoError(t, err)
_, err = getCertificateAAGUID(certificate)
assert.ErrorIs(t, err, errMissingAAGUID)
})
t.Run("marked critical", func(t *testing.T) {
tpl := &x509.Certificate{
SerialNumber: big.NewInt(1),
ExtraExtensions: []pkix.Extension{
{Id: oidAAGUID, Critical: true},
},
}
bs, err := x509.CreateCertificate(random, tpl, tpl, pub, priv)
require.NoError(t, err)
certificate, err := x509.ParseCertificate(bs)
require.NoError(t, err)
_, err = getCertificateAAGUID(certificate)
assert.ErrorIs(t, err, errAAGUIDMarkedCritical)
})
}