mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 14:26:23 -04:00
Add new generate measurements matrix CI/CD action (now with AWS support) (#641)
This commit is contained in:
parent
6af54142f2
commit
89b25f8ebb
11 changed files with 533 additions and 322 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/goleak"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
@ -147,3 +148,68 @@ func TestPrintPCRs(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintPCRsWithMetadata(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
format string
|
||||
csp string
|
||||
image string
|
||||
}{
|
||||
"json": {
|
||||
format: "json",
|
||||
csp: "azure",
|
||||
image: "v2.0.0",
|
||||
},
|
||||
"yaml": {
|
||||
csp: "gcp",
|
||||
image: "v2.0.0-testimage",
|
||||
format: "yaml",
|
||||
},
|
||||
"empty format": {
|
||||
format: "",
|
||||
csp: "qemu",
|
||||
image: "v2.0.0-testimage",
|
||||
},
|
||||
"empty": {},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
pcrs := measurements.M{
|
||||
0: measurements.WithAllBytes(0xAA, true),
|
||||
1: measurements.WithAllBytes(0xBB, true),
|
||||
2: measurements.WithAllBytes(0xCC, true),
|
||||
}
|
||||
|
||||
outputWithMetadata := measurements.WithMetadata{
|
||||
CSP: tc.csp,
|
||||
Image: tc.image,
|
||||
Measurements: pcrs,
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
err := printPCRsWithMetadata(&out, outputWithMetadata, tc.format)
|
||||
assert.NoError(err)
|
||||
|
||||
var unmarshalledOutput measurements.WithMetadata
|
||||
if tc.format == "" || tc.format == "json" {
|
||||
require.NoError(json.Unmarshal(out.Bytes(), &unmarshalledOutput))
|
||||
} else if tc.format == "yaml" {
|
||||
require.NoError(yaml.Unmarshal(out.Bytes(), &unmarshalledOutput))
|
||||
}
|
||||
|
||||
assert.NotNil(unmarshalledOutput.CSP)
|
||||
assert.NotNil(unmarshalledOutput.Image)
|
||||
assert.Equal(tc.csp, unmarshalledOutput.CSP)
|
||||
assert.Equal(tc.image, unmarshalledOutput.Image)
|
||||
|
||||
for idx, pcr := range pcrs {
|
||||
assert.Contains(out.String(), fmt.Sprintf("%d", idx))
|
||||
assert.Contains(out.String(), hex.EncodeToString(pcr.Expected[:]))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue