attestation: allow "go test" to work with CGO disabled

This commit is contained in:
Malte Poll 2023-08-18 16:16:46 +02:00 committed by Malte Poll
parent 1d5f244879
commit 75ed8c9f3e
7 changed files with 55 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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

View File

@ -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