-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_test.go
49 lines (41 loc) · 1.2 KB
/
format_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
//go:build cddltest
// +build cddltest
package smolcert
import (
"os"
"os/exec"
"testing"
"time"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/ed25519"
)
// cddl certificates/spec.cddl validate certificates/cert.cbor
func TestValidGoCertificateFormat(t *testing.T) {
notBefore := time.Now().UTC().Add(time.Hour * -12)
notAfter := time.Now().UTC().Add(time.Hour * 12)
pubKey := ed25519.PublicKey([]byte{0x00, 0x42, 0x23, 0x05})
cert := &Certificate{
Version: smolcertVersion,
Issuer: "connctd",
PubKey: pubKey,
SerialNumber: 12,
Signature: []byte{0x55, 0x42, 0x07},
Subject: "device",
Extensions: []Extension{},
Validity: &Validity{NotBefore: NewTime(notBefore), NotAfter: NewTime(notAfter)},
}
certFile, err := os.Create("./cert.cbor")
require.NoError(t, err)
defer certFile.Close()
defer func() {
require.NoError(t, os.Remove("cert.cbor"))
}()
require.NotZero(t, certFile)
require.NoError(t, Serialize(cert, certFile))
certFile.Close()
cmd := exec.Command("cddl", "spec.cddl", "validate", "cert.cbor")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err = cmd.Run()
require.NoError(t, err, "Certificate does not match specification")
}