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-05-03 05:11:53 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
|
2023-06-09 09:41:02 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
2023-04-06 11:00:56 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
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
|
|
|
|
}{
|
2023-06-09 09:41:02 -04:00
|
|
|
"aws-sev-snp": {
|
|
|
|
variant: variant.AWSSEVSNP{},
|
|
|
|
},
|
2023-03-09 03:47:28 -05:00
|
|
|
"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
|
|
|
},
|
2024-01-24 09:10:15 -05:00
|
|
|
"azure-tdx": {
|
|
|
|
variant: variant.AzureTDX{},
|
|
|
|
},
|
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
|
|
|
},
|
2024-04-16 12:13:47 -04:00
|
|
|
"gcp-sev-snp": {
|
|
|
|
variant: variant.GCPSEVSNP{},
|
|
|
|
},
|
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-05-03 05:11:53 -04:00
|
|
|
cfg config.AttestationCfg
|
2023-03-09 03:47:28 -05:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"aws-nitro-tpm": {
|
2023-05-03 05:11:53 -04:00
|
|
|
cfg: &config.AWSNitroTPM{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"azure-sev-snp": {
|
2023-05-03 05:11:53 -04:00
|
|
|
cfg: &config.AzureSEVSNP{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
2024-01-24 09:10:15 -05:00
|
|
|
"azure-tdx": {
|
|
|
|
cfg: &config.AzureTDX{},
|
|
|
|
},
|
2023-03-09 03:47:28 -05:00
|
|
|
"azure-trusted-launch": {
|
2023-05-03 05:11:53 -04:00
|
|
|
cfg: &config.AzureTrustedLaunch{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"gcp-sev-es": {
|
2023-05-03 05:11:53 -04:00
|
|
|
cfg: &config.GCPSEVES{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
2024-04-16 12:13:47 -04:00
|
|
|
"gcp-sev-snp": {
|
|
|
|
cfg: &config.GCPSEVSNP{},
|
|
|
|
},
|
2023-03-09 03:47:28 -05:00
|
|
|
"qemu-vtpm": {
|
2023-05-03 05:11:53 -04:00
|
|
|
cfg: &config.QEMUVTPM{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"dummy": {
|
2023-05-03 05:11:53 -04:00
|
|
|
cfg: &config.DummyCfg{},
|
2023-03-09 03:47:28 -05:00
|
|
|
},
|
|
|
|
"unknown": {
|
2023-05-03 05:11:53 -04:00
|
|
|
cfg: unknownConfig{},
|
2023-03-09 03:47:28 -05:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
2023-05-03 05:11:53 -04:00
|
|
|
validator, err := Validator(tc.cfg, nil)
|
2023-03-09 03:47:28 -05:00
|
|
|
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
2023-05-03 05:11:53 -04:00
|
|
|
assert.True(validator.OID().Equal(tc.cfg.GetVariant().OID()))
|
2023-03-09 03:47:28 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
}
|
2023-05-03 05:11:53 -04:00
|
|
|
|
|
|
|
type unknownConfig struct{}
|
|
|
|
|
|
|
|
func (unknownConfig) GetVariant() variant.Variant {
|
|
|
|
return unknownVariant{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (unknownConfig) GetMeasurements() measurements.M {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (unknownConfig) SetMeasurements(measurements.M) {}
|
|
|
|
|
|
|
|
func (unknownConfig) EqualTo(config.AttestationCfg) (bool, error) { return false, nil }
|