|
| 1 | +package verification |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/cli/cli/v2/pkg/cmd/attestation/io" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +// Note: Tests that require network access and TUF client initialization |
| 11 | +// are in sigstore_integration_test.go with the //go:build integration tag. |
| 12 | +// These unit tests focus on testing the logic without requiring network access. |
| 13 | + |
| 14 | +// TestChooseVerifierWithNilPublicGood tests that chooseVerifier returns an error |
| 15 | +// when a PGI attestation is encountered but the PGI verifier is nil (failed initialization). |
| 16 | +func TestChooseVerifierWithNilPublicGood(t *testing.T) { |
| 17 | + verifier := &LiveSigstoreVerifier{ |
| 18 | + Logger: io.NewTestHandler(), |
| 19 | + NoPublicGood: false, |
| 20 | + PublicGood: nil, // Simulate failed PGI initialization |
| 21 | + GitHub: nil, // Not needed for this test |
| 22 | + } |
| 23 | + |
| 24 | + _, err := verifier.chooseVerifier(PublicGoodIssuerOrg) |
| 25 | + |
| 26 | + require.Error(t, err) |
| 27 | + require.ErrorContains(t, err, "public good verifier is not available") |
| 28 | +} |
| 29 | + |
| 30 | +// TestChooseVerifierWithGitHubIssuer tests that chooseVerifier can select |
| 31 | +// GitHub verifier even when PGI verifier is nil. |
| 32 | +func TestChooseVerifierWithGitHubIssuer(t *testing.T) { |
| 33 | + // We'll test this scenario with the actual initialization |
| 34 | + // to ensure GitHub verifier is properly created |
| 35 | + t.Skip("This requires integration test with actual TUF client - covered by integration tests") |
| 36 | +} |
| 37 | + |
| 38 | +// TestChooseVerifierUnrecognizedIssuer tests that an error is returned |
| 39 | +// for unrecognized issuers. |
| 40 | +func TestChooseVerifierUnrecognizedIssuer(t *testing.T) { |
| 41 | + verifier := &LiveSigstoreVerifier{ |
| 42 | + Logger: io.NewTestHandler(), |
| 43 | + NoPublicGood: false, |
| 44 | + } |
| 45 | + |
| 46 | + _, err := verifier.chooseVerifier("unknown-issuer") |
| 47 | + |
| 48 | + require.Error(t, err) |
| 49 | + require.ErrorContains(t, err, "leaf certificate issuer is not recognized") |
| 50 | +} |
| 51 | + |
| 52 | +// TestGetBundleIssuer tests the getBundleIssuer helper function |
| 53 | +func TestGetBundleIssuer(t *testing.T) { |
| 54 | + // This test would require setting up a mock bundle |
| 55 | + // For now, we'll just verify it exists and can be called |
| 56 | + // Integration tests cover the actual functionality |
| 57 | + t.Skip("getBundleIssuer requires a valid bundle which needs integration test setup") |
| 58 | +} |
0 commit comments