From 75ed8c9f3e2e33cb7d36adfa1354cca4a36440bb Mon Sep 17 00:00:00 2001 From: Malte Poll Date: Fri, 18 Aug 2023 16:16:46 +0200 Subject: [PATCH] attestation: allow "go test" to work with CGO disabled --- internal/attestation/aws/nitrotpm/issuer_test.go | 9 +++++++++ internal/attestation/aws/snp/issuer_test.go | 9 +++++++++ internal/attestation/azure/snp/issuer_test.go | 5 +++++ internal/attestation/azure/snp/validator_test.go | 9 +++++++++ .../azure/trustedlaunch/trustedlaunch_test.go | 5 +++++ internal/attestation/initialize/initialize_test.go | 9 +++++++++ internal/attestation/vtpm/attestation_test.go | 9 +++++++++ 7 files changed, 55 insertions(+) diff --git a/internal/attestation/aws/nitrotpm/issuer_test.go b/internal/attestation/aws/nitrotpm/issuer_test.go index d1a00439d4..59b5b7e476 100644 --- a/internal/attestation/aws/nitrotpm/issuer_test.go +++ b/internal/attestation/aws/nitrotpm/issuer_test.go @@ -9,6 +9,7 @@ package nitrotpm import ( "context" "errors" + "os" "testing" "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" @@ -20,6 +21,10 @@ import ( ) func TestGetAttestationKey(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled") + } require := require.New(t) assert := assert.New(t) @@ -42,6 +47,10 @@ func TestGetAttestationKey(t *testing.T) { } func TestGetInstanceInfo(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } testCases := map[string]struct { client stubMetadataAPI wantErr bool diff --git a/internal/attestation/aws/snp/issuer_test.go b/internal/attestation/aws/snp/issuer_test.go index 29d17b5e19..548b26f286 100644 --- a/internal/attestation/aws/snp/issuer_test.go +++ b/internal/attestation/aws/snp/issuer_test.go @@ -9,6 +9,7 @@ package snp import ( "context" "errors" + "os" "testing" "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" @@ -20,6 +21,10 @@ import ( ) func TestGetAttestationKey(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } require := require.New(t) assert := assert.New(t) @@ -42,6 +47,10 @@ func TestGetAttestationKey(t *testing.T) { } func TestGetInstanceInfo(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } testCases := map[string]struct { client stubMetadataAPI wantErr bool diff --git a/internal/attestation/azure/snp/issuer_test.go b/internal/attestation/azure/snp/issuer_test.go index 2c52a4ede0..06aa78b6b4 100644 --- a/internal/attestation/azure/snp/issuer_test.go +++ b/internal/attestation/azure/snp/issuer_test.go @@ -11,6 +11,7 @@ import ( "encoding/json" "errors" "io" + "os" "testing" "github.com/edgelesssys/constellation/v2/internal/attestation/simulator" @@ -115,6 +116,10 @@ func TestGetSNPAttestation(t *testing.T) { // Testing anything else will only verify that the simulator works as expected, since getAkPub // only retrieves the attestation key from the TPM. func TestGetHCLAttestationKey(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } require := require.New(t) assert := assert.New(t) diff --git a/internal/attestation/azure/snp/validator_test.go b/internal/attestation/azure/snp/validator_test.go index f4390e3a44..3ceb008430 100644 --- a/internal/attestation/azure/snp/validator_test.go +++ b/internal/attestation/azure/snp/validator_test.go @@ -16,6 +16,7 @@ import ( "encoding/json" "errors" "fmt" + "os" "testing" "github.com/edgelesssys/constellation/v2/internal/attestation/idkeydigest" @@ -31,6 +32,10 @@ import ( ) func TestTrustedKeyFromSNP(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } require := require.New(t) tpm, err := simulator.OpenSimulatedTPM() @@ -237,6 +242,10 @@ func TestTrustedKeyFromSNP(t *testing.T) { } func TestValidateAk(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } require := require.New(t) tpm, err := simulator.OpenSimulatedTPM() diff --git a/internal/attestation/azure/trustedlaunch/trustedlaunch_test.go b/internal/attestation/azure/trustedlaunch/trustedlaunch_test.go index 0c25a6f451..023bb785f7 100644 --- a/internal/attestation/azure/trustedlaunch/trustedlaunch_test.go +++ b/internal/attestation/azure/trustedlaunch/trustedlaunch_test.go @@ -15,6 +15,7 @@ import ( "crypto/x509/pkix" "io" "net/http" + "os" "testing" "time" @@ -32,6 +33,10 @@ import ( ) func TestGetAttestationCert(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } require := require.New(t) tpm, err := simulator.OpenSimulatedTPM() require.NoError(err) diff --git a/internal/attestation/initialize/initialize_test.go b/internal/attestation/initialize/initialize_test.go index 4d2bd92b1b..bd31e60f00 100644 --- a/internal/attestation/initialize/initialize_test.go +++ b/internal/attestation/initialize/initialize_test.go @@ -9,6 +9,7 @@ package initialize import ( "errors" "io" + "os" "testing" "github.com/edgelesssys/constellation/v2/internal/attestation/measurements" @@ -29,6 +30,10 @@ func (s simTPMNOPCloser) Close() error { } func TestMarkNodeAsBootstrapped(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } assert := assert.New(t) require := require.New(t) @@ -57,6 +62,10 @@ func TestFailOpener(t *testing.T) { } func TestIsNodeInitialized(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } testCases := map[string]struct { pcrValueClusterID []byte wantInitialized bool diff --git a/internal/attestation/vtpm/attestation_test.go b/internal/attestation/vtpm/attestation_test.go index 15128aee38..9eeeef3b83 100644 --- a/internal/attestation/vtpm/attestation_test.go +++ b/internal/attestation/vtpm/attestation_test.go @@ -13,6 +13,7 @@ import ( "errors" "fmt" "io" + "os" "testing" tpmclient "github.com/google/go-tpm-tools/client" @@ -58,6 +59,10 @@ func fakeGetInstanceInfo(_ context.Context, _ io.ReadWriteCloser, _ []byte) ([]b } func TestValidate(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } require := require.New(t) fakeValidateCVM := func(AttestationDocument, *attest.MachineState) error { return nil } @@ -421,6 +426,10 @@ func TestGetSHA256QuoteIndex(t *testing.T) { } func TestGetSelectedMeasurements(t *testing.T) { + cgo := os.Getenv("CGO_ENABLED") + if cgo == "0" { + t.Skip("skipping test because CGO is disabled and tpm simulator requires it") + } testCases := map[string]struct { openFunc TPMOpenFunc pcrSelection tpm2.PCRSelection