Skip to content

Commit

Permalink
chore: add measurement comparison tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jan 15, 2025
1 parent 284ce4e commit a98dc52
Showing 1 changed file with 61 additions and 12 deletions.
73 changes: 61 additions & 12 deletions pkg/attestation/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,66 @@ import (
"github.com/stretchr/testify/assert"
)

func TestMainNitroVerifier(t *testing.T) {
payload := `{
"version": "v0.0.1",
"format": "https://tinfoil.sh/predicate/aws-nitro-enclave/v1",
"body": "hEShATgioFkQ/6lpbW9kdWxlX2lkeCdpLTA4NGVlNTIxZDVmOTIxMDk2LWVuYzAxOTM2OTdkZjhlNDcwNjNmZGlnZXN0ZlNIQTM4NGl0aW1lc3RhbXAbAAABlE5MLItkcGNyc7AAWDBEBqggqpahA/zWQPqijfY4TjNZPThn2EzFnat6rM6oiXR01AWKMXRm6vEjSlbMII4BWDBLTVs2YbPvwSkgkAyA4Sbkzng8Ui3mwCoqW/evOiuTJ7hndvGI5L4cHEBKEp29pJMCWDDBHp3xYXzzMFM+Rcdcr8LaJLBN9OsKhmhIGxZp0x30ppDor2h4VTGPszX7K71Zb/sDWDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEWDDM5N5yesCUnVB1HrTnLihT3IzVWB8CbCUa7Zb7u2461AdTQ9WN6naoGN2rWMuzlRYFWDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGWDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHWDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIWDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJWDAAAAAAAAA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MxDDAKBgNVBAsMA0FXUzEPMA0GA1UECgwGQW1hem9uMQswCQYDVQQGEwJVUzELMAkGA1UECAwCV0ExEDAOBgNVBAcMB1NlYXR0bGUwHhcNMjUwMTA5MTYyMDQ0WhcNMjUwMTEwMTYyMDQ0WjCBjjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxDzANBgNVBAoMBkFtYXpvbjEMMAoGA1UECwwDQVdTMTkwNwYDVQQDDDBpLTA4NGVlNTIxZDVmOTIxMDk2LnVzLWVhc3QtMi5hd3Mubml0cm8tZW5jbGF2ZXMwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAASm6jRWRmZsKWV3gz8w99hrO0C0tyCKIri+4duo37r/r8Y/ODJf54sbvVU3o1BO9EcM/iOtPmre57qlYziMMorSl1NC/isUA3694XLRg3rBG5F1DfBIibhHk+OuY0SCShWjZjBkMBIGA1UdEwEB/wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgIEMB0GA1UdDgQWBBQVeqBm82IKX6mNBq8eEsqYX4lPmzAfBgNVHSMEGDAWgBQ1x9fEA2r0+s7OwmXOgAEKMa5fszAKBggqhkjOPQQDAwNoADBlAjAUUr7SWXmsYpuh4u9HsEnj9jXiIzQsEiKp5TUirDMAMD+EzZDEq2g7hWhkhqxj/5wCMQC/EoFi7JoD70rrf8hr50W+gul+QcGShsIDQ6GMbMOMXC0oIncopLINc5DVcPKhXwFqcHVibGljX2tlefZpdXNlcl9kYXRh9mVub25jZfZYYKyfchEsQ43Iq5aEasXCc5MvGGZ2aiWgWacnaT7CbG4Ac+Z/05zHjJemTGHd4U46Ms7LZO7+M2Mt04vxWs9F153/g4bZgjBjYqZpirp4NyI+mbDW0OAa5t9BldElnx6DVg=="
}`
func TestMeasurementEquals(t *testing.T) {
tests := []struct {
name string
m1 *Measurement
m2 *Measurement
wantErr error
}{
{
name: "same measurements",
m1: &Measurement{
Type: AWSNitroEnclaveV1,
Registers: []string{"reg1", "reg2"},
},
m2: &Measurement{
Type: AWSNitroEnclaveV1,
Registers: []string{"reg1", "reg2"},
},
wantErr: nil,
},
{
name: "different types",
m1: &Measurement{
Type: AWSNitroEnclaveV1,
Registers: []string{"reg1", "reg2"},
},
m2: &Measurement{
Type: "other-type",
Registers: []string{"reg1", "reg2"},
},
wantErr: ErrFormatMismatch,
},
{
name: "different register lengths",
m1: &Measurement{
Type: AWSNitroEnclaveV1,
Registers: []string{"reg1", "reg2"},
},
m2: &Measurement{
Type: AWSNitroEnclaveV1,
Registers: []string{"reg1"},
},
wantErr: ErrMeasurementMismatch,
},
{
name: "different register values",
m1: &Measurement{
Type: AWSNitroEnclaveV1,
Registers: []string{"reg1", "reg2"},
},
m2: &Measurement{
Type: AWSNitroEnclaveV1,
Registers: []string{"reg1", "reg3"},
},
wantErr: ErrMeasurementMismatch,
},
}

undo := mockNitroVerifier()
defer undo()

attestation, err := VerifyAttestationJSON([]byte(payload))
assert.Nil(t, err)
assert.Equal(t, 3, len(attestation.Registers))
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.ErrorIs(t, tt.m1.Equals(tt.m2), tt.wantErr)
})
}
}

0 comments on commit a98dc52

Please sign in to comment.