Skip to content

Commit

Permalink
ci: fix TF attestation version assertion in integration test (#3237)
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead authored Jul 10, 2024
1 parent 5d25ede commit 051cb20
Showing 1 changed file with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SPDX-License-Identifier: AGPL-3.0-only
package provider

import (
"errors"
"strconv"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -16,6 +18,30 @@ func TestAccAttestationSource(t *testing.T) {
// Set the path to the Terraform binary for acceptance testing when running under Bazel.
bazelPreCheck := func() { bazelSetTerraformBinaryPath(t) }

assertNonZeroValue := func(attr string) resource.TestCheckFunc {
return resource.TestCheckResourceAttrWith(
"data.constellation_attestation.test",
attr,
func(value string) error {
parsedValue, err := strconv.ParseUint(value, 10, 8)
if err == nil && parsedValue == 0 {
return errors.New("expected non-zero value")
}
return err
},
)
}
assertUint8Value := func(attr string) resource.TestCheckFunc {
return resource.TestCheckResourceAttrWith(
"data.constellation_attestation.test",
attr,
func(value string) error {
_, err := strconv.ParseUint(value, 10, 8)
return err
},
)
}

testCases := map[string]resource.TestCase{
"azure sev-snp success": {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Expand All @@ -36,12 +62,10 @@ func TestAccAttestationSource(t *testing.T) {
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.variant", "azure-sev-snp"),

resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.bootloader_version", "3"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.microcode_version", "115"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.snp_version", "8"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.tee_version", "0"),

assertNonZeroValue("attestation.bootloader_version"),
assertNonZeroValue("attestation.microcode_version"),
assertNonZeroValue("attestation.snp_version"),
assertUint8Value("attestation.tee_version"), // the valid value is 0 at the moment
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.azure_firmware_signer_config.accepted_key_digests.0", "0356215882a825279a85b300b0b742931d113bf7e32dde2e50ffde7ec743ca491ecdd7f336dc28a6e0b2bb57af7a44a3"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.azure_firmware_signer_config.enforcement_policy", "MAAFallback"),

Expand Down Expand Up @@ -128,7 +152,10 @@ func TestAccAttestationSource(t *testing.T) {
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.variant", "gcp-sev-snp"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.bootloader_version", "3"),
assertNonZeroValue("attestation.bootloader_version"),
assertNonZeroValue("attestation.microcode_version"),
assertNonZeroValue("attestation.snp_version"),
assertUint8Value("attestation.tee_version"), // the valid value is 0 at the moment
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.measurements.1.expected", "3695dcc55e3aa34027c27793c85c723c697d708c42d1f73bd6fa4f26608a5b24"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.measurements.1.warn_only", "true"),
),
Expand Down

0 comments on commit 051cb20

Please sign in to comment.