-
Notifications
You must be signed in to change notification settings - Fork 7
/
triples_test.go
86 lines (66 loc) · 2.59 KB
/
triples_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
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
// Copyright 2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package comid
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/veraison/corim/extensions"
)
func TestTriples_extensions(t *testing.T) {
triples := Triples{}
triplesExt := &struct{}{}
extMap := extensions.NewMap().
Add(ExtTriples, triplesExt).
Add(ExtReferenceValue, &struct{}{}).
Add(ExtReferenceValueFlags, &struct{}{}).
Add(ExtEndorsedValue, &struct{}{}).
Add(ExtEndorsedValueFlags, &struct{}{})
err := triples.RegisterExtensions(extMap)
assert.NoError(t, err)
assert.Equal(t, triplesExt, triples.GetExtensions())
badMap := extensions.NewMap().Add(extensions.Point("test"), &struct{}{})
err = triples.RegisterExtensions(badMap)
assert.EqualError(t, err, `unexpected extension point: "test"`)
}
func TestTriples_marshaling(t *testing.T) {
triples := Triples{}
extMap := extensions.NewMap().
Add(ExtReferenceValue, &struct{}{}).
Add(ExtEndorsedValue, &struct{}{})
require.NoError(t, triples.RegisterExtensions(extMap))
data, err := triples.MarshalCBOR()
assert.NoError(t, err)
assert.Equal(t, data, []byte{0xa0})
data, err = triples.MarshalJSON()
assert.NoError(t, err)
assert.JSONEq(t, "{}", string(data))
}
func TestTriples_Valid(t *testing.T) {
triples := Triples{}
triples.ReferenceValues = &ValueTriples{}
triples.EndorsedValues = &ValueTriples{}
err := triples.Valid()
assert.EqualError(t, err, "triples struct must not be empty")
triples.ReferenceValues.Add(&ValueTriple{})
err = triples.Valid()
assert.EqualError(t, err, "reference values: error at index 0: environment validation failed: environment must not be empty")
triples.ReferenceValues = nil
triples.EndorsedValues.Add(&ValueTriple{})
err = triples.Valid()
assert.EqualError(t, err, "endorsed values: error at index 0: environment validation failed: environment must not be empty")
triples.EndorsedValues = nil
triples.AttestVerifKeys = &KeyTriples{{}}
err = triples.Valid()
assert.EqualError(t, err, "attestation verification key at index 0: environment validation failed: environment must not be empty")
triples.AttestVerifKeys = nil
triples.DevIdentityKeys = &KeyTriples{{}}
err = triples.Valid()
assert.EqualError(t, err, "device identity key at index 0: environment validation failed: environment must not be empty")
}
func TestTriples_adders(t *testing.T) {
triples := Triples{}
triples.AddReferenceValue(ValueTriple{}).AddEndorsedValue(ValueTriple{})
assert.Len(t, triples.ReferenceValues.Values, 1)
assert.Len(t, triples.EndorsedValues.Values, 1)
}