Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add additional policy verification test #341

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import (
)

func TestVerify(t *testing.T) {
policy, functionarySigner := makepolicyRSA(t)
policyEnvelope, policySigner := signPolicyRSA(t, policy)
testPolicy, functionarySigner := makepolicyRSA(t)
policyEnvelope, policySigner := signPolicyRSA(t, testPolicy)
policyVerifier, err := policySigner.Verifier()
require.NoError(t, err)
workingDir := t.TempDir()
Expand Down Expand Up @@ -132,6 +132,46 @@ func TestVerify(t *testing.T) {

require.Error(t, err, fmt.Sprintf("passed with results: %+v", results))
})

t.Run("Fail with missing attestation", func(t *testing.T) {
functionaryVerifier, err := functionarySigner.Verifier()
require.NoError(t, err)
functionaryKeyID, err := functionaryVerifier.KeyID()
require.NoError(t, err)
functionaryPublicKey, err := functionaryVerifier.Bytes()
require.NoError(t, err)
failPolicy := makepolicy(policy.Functionary{
Type: "PublicKey",
PublicKeyID: functionaryKeyID,
},
policy.PublicKey{
KeyID: functionaryKeyID,
Key: functionaryPublicKey,
},
map[string]policy.Root{},
)

step1 := failPolicy.Steps["step01"]
step1.Attestations = append(step1.Attestations, policy.Attestation{Type: "nonexistent atttestation"})
failPolicy.Steps["step01"] = step1
failPolicyEnvelope, failPolicySigner := signPolicyRSA(t, failPolicy)
failPolicyVerifier, err := failPolicySigner.Verifier()
require.NoError(t, err)

memorySource := source.NewMemorySource()
require.NoError(t, memorySource.LoadEnvelope("step01", step1Result.SignedEnvelope))
require.NoError(t, memorySource.LoadEnvelope("step02", step2Result.SignedEnvelope))

results, err := Verify(
context.Background(),
failPolicyEnvelope,
[]cryptoutil.Verifier{failPolicyVerifier},
VerifyWithCollectionSource(memorySource),
VerifyWithSubjectDigests(subjects),
)

require.Error(t, err, fmt.Sprintf("passed with results: %+v", results))
})
}

func makepolicy(functionary policy.Functionary, publicKey policy.PublicKey, roots map[string]policy.Root) policy.Policy {
Expand Down