MCPcopy Create free account
hub / github.com/conforma/cli / TestValidateImageCommand_VSAFormat_DSSE

Function TestValidateImageCommand_VSAFormat_DSSE

cmd/validate/image_test.go:1638–1689  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1636}
1637
1638func TestValidateImageCommand_VSAFormat_DSSE(t *testing.T) {
1639 // Test that --attestation-format=dsse generates DSSE envelopes (existing behavior)
1640 t.Setenv("COSIGN_PASSWORD", "")
1641
1642 // Mock the expensive loadPrivateKey operation
1643 originalLoadPrivateKey := vsa.LoadPrivateKey
1644 defer func() { vsa.LoadPrivateKey = originalLoadPrivateKey }()
1645
1646 vsa.LoadPrivateKey = func(keyBytes, password []byte, _ *[]signature.LoadOption) (signature.SignerVerifier, error) {
1647 return &simpleFakeSigner{}, nil
1648 }
1649
1650 validateImageCmd := validateImageCmd(happyValidator())
1651 cmd := setUpCobra(validateImageCmd)
1652
1653 fs := afero.NewMemMapFs()
1654 ctx := utils.WithFS(context.Background(), fs)
1655
1656 // Create a test VSA signing key
1657 err := afero.WriteFile(fs, "/tmp/vsa-key.pem", []byte(testECKey), 0o600)
1658 require.NoError(t, err)
1659
1660 client := fake.FakeClient{}
1661 commonMockClient(&client)
1662
1663 // Add ResolveDigest expectation for VSA processing
1664 digest, _ := name.NewDigest(testImageDigest)
1665 client.On("ResolveDigest", mock.Anything).Return(digest.String(), nil)
1666
1667 ctx = oci.WithClient(ctx, &client)
1668 cmd.SetContext(ctx)
1669
1670 cmd.SetArgs([]string{
1671 "validate", "image",
1672 "--image", "registry/image:tag",
1673 "--policy", fmt.Sprintf(`{"publicKey": %s}`, utils.TestPublicKeyJSON),
1674 "--vsa",
1675 "--attestation-format", "dsse",
1676 "--vsa-signing-key", "/tmp/vsa-key.pem",
1677 "--vsa-upload", "local@/tmp/vsa-test",
1678 })
1679
1680 var out bytes.Buffer
1681 cmd.SetOut(&out)
1682
1683 utils.SetTestRekorPublicKey(t)
1684
1685 // Execute - the command should attempt to generate DSSE envelopes
1686 _ = cmd.Execute()
1687 // We don't assert no error because VSA generation might fail in test environment,
1688 // but we're testing that the DSSE code path is executed
1689}
1690
1691func TestValidateImageCommand_VSAFormat_Predicate(t *testing.T) {
1692 // Test that --attestation-format=predicate generates raw predicates

Callers

nothing calls this directly

Calls 8

WithFSFunction · 0.92
WithClientFunction · 0.92
SetTestRekorPublicKeyFunction · 0.92
validateImageCmdFunction · 0.85
happyValidatorFunction · 0.85
commonMockClientFunction · 0.85
setUpCobraFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected