2023-03-09 03:47:28 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package choose
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/asn1"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-21 07:46:49 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/idkeydigest"
|
2023-03-29 03:30:13 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/variant"
|
2023-03-09 03:47:28 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIssuer(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant variant.Variant
|
2023-03-09 03:47:28 -05:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"aws-nitro-tpm": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.AWSNitroTPM{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"azure-sev-snp": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.AzureSEVSNP{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"azure-trusted-launch": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.AzureTrustedLaunch{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"gcp-sev-es": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.GCPSEVES{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"qemu-vtpm": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.QEMUVTPM{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"dummy": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.Dummy{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"unknown": {
|
|
|
|
variant: unknownVariant{},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
issuer, err := Issuer(tc.variant, nil)
|
|
|
|
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
assert.True(issuer.OID().Equal(tc.variant.OID()))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidator(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant variant.Variant
|
2023-03-09 03:47:28 -05:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"aws-nitro-tpm": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.AWSNitroTPM{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"azure-sev-snp": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.AzureSEVSNP{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"azure-trusted-launch": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.AzureTrustedLaunch{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"gcp-sev-es": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.GCPSEVES{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"qemu-vtpm": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.QEMUVTPM{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"dummy": {
|
2023-03-29 03:30:13 -04:00
|
|
|
variant: variant.Dummy{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"unknown": {
|
|
|
|
variant: unknownVariant{},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
2023-03-21 07:46:49 -04:00
|
|
|
validator, err := Validator(tc.variant, nil, idkeydigest.Config{}, nil)
|
2023-03-09 03:47:28 -05:00
|
|
|
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
assert.True(validator.OID().Equal(tc.variant.OID()))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type unknownVariant struct{}
|
|
|
|
|
|
|
|
func (unknownVariant) OID() asn1.ObjectIdentifier {
|
|
|
|
return asn1.ObjectIdentifier{1, 3, 9900, 9999, 9999}
|
|
|
|
}
|
2023-03-29 03:30:13 -04:00
|
|
|
|
|
|
|
func (unknownVariant) String() string {
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (unknownVariant) Equal(other variant.Getter) bool {
|
|
|
|
return other.OID().Equal(unknownVariant{}.OID())
|
|
|
|
}
|