mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-21 21:29:27 -04:00
Add measurement reader (#1381)
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
5bad5f768b
commit
8c87bba755
12 changed files with 216 additions and 9 deletions
78
measurement-reader/internal/tpm/tpm_test.go
Normal file
78
measurement-reader/internal/tpm/tpm_test.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package tpm
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
|
||||
"github.com/edgelesssys/constellation/v2/measurement-reader/internal/sorted"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSortMeasurements(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
input measurements.M
|
||||
want []sorted.Measurement
|
||||
}{
|
||||
"pre sorted": {
|
||||
input: measurements.M{
|
||||
0: measurements.WithAllBytes(0x11, false),
|
||||
1: measurements.WithAllBytes(0x22, false),
|
||||
2: measurements.WithAllBytes(0x33, false),
|
||||
},
|
||||
want: []sorted.Measurement{
|
||||
{
|
||||
Index: "PCR[00]",
|
||||
Value: bytes.Repeat([]byte{0x11}, 32),
|
||||
},
|
||||
{
|
||||
Index: "PCR[01]",
|
||||
Value: bytes.Repeat([]byte{0x22}, 32),
|
||||
},
|
||||
{
|
||||
Index: "PCR[02]",
|
||||
Value: bytes.Repeat([]byte{0x33}, 32),
|
||||
},
|
||||
},
|
||||
},
|
||||
"unsorted": {
|
||||
input: measurements.M{
|
||||
1: measurements.WithAllBytes(0x22, false),
|
||||
0: measurements.WithAllBytes(0x11, false),
|
||||
2: measurements.WithAllBytes(0x33, false),
|
||||
},
|
||||
want: []sorted.Measurement{
|
||||
{
|
||||
Index: "PCR[00]",
|
||||
Value: bytes.Repeat([]byte{0x11}, 32),
|
||||
},
|
||||
{
|
||||
Index: "PCR[01]",
|
||||
Value: bytes.Repeat([]byte{0x22}, 32),
|
||||
},
|
||||
{
|
||||
Index: "PCR[02]",
|
||||
Value: bytes.Repeat([]byte{0x33}, 32),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
got := sortMeasurements(tc.input)
|
||||
for i := range got {
|
||||
assert.Equal(got[i].Index, tc.want[i].Index)
|
||||
assert.Equal(got[i].Value, tc.want[i].Value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue