2022-03-22 11:03:15 -04:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-04-22 05:06:55 -04:00
|
|
|
"github.com/edgelesssys/constellation/coordinator/attestation/simulator"
|
2022-03-22 11:03:15 -04:00
|
|
|
"github.com/edgelesssys/constellation/coordinator/attestation/vtpm"
|
|
|
|
"github.com/google/go-tpm-tools/client"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTrustedKeyFromSNP(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
2022-04-22 05:06:55 -04:00
|
|
|
tpm, err := simulator.OpenSimulatedTPM()
|
2022-03-22 11:03:15 -04:00
|
|
|
require.NoError(err)
|
|
|
|
defer tpm.Close()
|
|
|
|
key, err := client.AttestationKeyRSA(tpm)
|
|
|
|
require.NoError(err)
|
|
|
|
defer key.Close()
|
|
|
|
akPub, err := key.PublicArea().Encode()
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
key []byte
|
|
|
|
instanceInfo []byte
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr bool
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"success": {
|
|
|
|
key: akPub,
|
|
|
|
instanceInfo: []byte{},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: false,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
key, err := trustedKeyFromSNP(tc.key, tc.instanceInfo)
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.NotNil(key)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateAzureCVM(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
attDoc vtpm.AttestationDocument
|
|
|
|
wantErr bool
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"success": {
|
2022-04-26 10:54:05 -04:00
|
|
|
attDoc: vtpm.AttestationDocument{},
|
|
|
|
wantErr: false,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
err := validateAzureCVM(tc.attDoc)
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|