Skip to content

Commit

Permalink
attestation: allow "go test" to work with CGO disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 committed Aug 18, 2023
1 parent 1d5f244 commit 75ed8c9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/attestation/aws/nitrotpm/issuer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package nitrotpm
import (
"context"
"errors"
"os"
"testing"

"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
Expand All @@ -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)

Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions internal/attestation/aws/snp/issuer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package snp
import (
"context"
"errors"
"os"
"testing"

"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
Expand All @@ -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)

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/attestation/azure/snp/issuer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"io"
"os"
"testing"

"github.com/edgelesssys/constellation/v2/internal/attestation/simulator"
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions internal/attestation/azure/snp/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"testing"

"github.com/edgelesssys/constellation/v2/internal/attestation/idkeydigest"
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"crypto/x509/pkix"
"io"
"net/http"
"os"
"testing"
"time"

Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions internal/attestation/initialize/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package initialize
import (
"errors"
"io"
"os"
"testing"

"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions internal/attestation/vtpm/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"errors"
"fmt"
"io"
"os"
"testing"

tpmclient "github.com/google/go-tpm-tools/client"
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 75ed8c9

Please sign in to comment.