File: extension_test.go

package info (click to toggle)
golang-github-smallstep-crypto 0.57.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,284 kB
  • sloc: sh: 53; makefile: 36
file content (88 lines) | stat: -rw-r--r-- 2,205 bytes parent folder | download | duplicates (2)
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
package skae

import (
	"crypto/x509"
	"crypto/x509/pkix"
	"encoding/asn1"
	"math/big"
	"reflect"
	"testing"

	"github.com/smallstep/go-attestation/attest"
)

func TestCreateSubjectKeyAttestationEvidenceExtension(t *testing.T) {
	t.Skip("skipping because SKAE is not complete yet")
	akCert := &x509.Certificate{
		Issuer: pkix.Name{
			CommonName: "AK Test Issuer",
		},
		SerialNumber: big.NewInt(1337),
		OCSPServer: []string{
			"https://www.example.com/ocsp/1",
			"https://www.example.com/ocsp/2",
		},
		IssuingCertificateURL: []string{
			"https://www.example.com/issuing/cert1",
		},
	}
	type args struct {
		akCert        *x509.Certificate
		params        attest.CertificationParameters
		shouldEncrypt bool
	}
	tests := []struct {
		name    string
		args    args
		want    pkix.Extension
		wantErr bool
	}{
		{
			name: "attest",
			args: args{
				akCert: akCert,
				params: attest.CertificationParameters{
					CreateAttestation: []byte("test-fake-create-attestation"),
					CreateSignature:   []byte("test-fake-create-signature"),
				},
				shouldEncrypt: false,
			},
			want: pkix.Extension{
				Id:       asn1.ObjectIdentifier{2, 23, 133, 6, 1, 1},
				Critical: false,
				Value:    []byte{},
			},
			wantErr: false,
		},
		{
			name: "enveloped-attest",
			args: args{
				akCert: akCert,
				params: attest.CertificationParameters{
					CreateAttestation: []byte("test-fake-create-attestation"),
					CreateSignature:   []byte("test-fake-create-signature"),
				},
				shouldEncrypt: true,
			},
			// want: pkix.Extension{
			// 	Id:       asn1.ObjectIdentifier{2, 23, 133, 6, 1, 1},
			// 	Critical: false,
			// 	Value:    []byte{},
			// },
			want:    pkix.Extension{},
			wantErr: true,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := CreateSubjectKeyAttestationEvidenceExtension(tt.args.akCert, tt.args.params, tt.args.shouldEncrypt)
			if (err != nil) != tt.wantErr {
				t.Errorf("CreateSubjectKeyAttestationEvidenceExtension() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if !reflect.DeepEqual(got, tt.want) {
				t.Errorf("CreateSubjectKeyAttestationEvidenceExtension() = %v, want %v", got, tt.want)
			}
		})
	}
}