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

Function TestNewSigner_Comprehensive

internal/validate/vsa/attest_test.go:369–476  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

367}
368
369func TestNewSigner_Comprehensive(t *testing.T) {
370 t.Setenv("COSIGN_PASSWORD", "")
371
372 // Mock the loadPrivateKey function for success cases to avoid expensive decryption
373 originalLoadPrivateKey := LoadPrivateKey
374 defer func() { LoadPrivateKey = originalLoadPrivateKey }()
375
376 LoadPrivateKey = func(keyBytes, password []byte, _ *[]signature.LoadOption) (signature.SignerVerifier, error) {
377 return &fakeSigner{}, nil
378 }
379
380 tests := []struct {
381 name string
382 keyRef string
383 setup func(fs afero.Fs, ctx context.Context)
384 expectErr bool
385 errMsg string
386 }{
387 {
388 name: "file path success",
389 keyRef: "/path/to/key.pem",
390 setup: func(fs afero.Fs, ctx context.Context) {
391 err := afero.WriteFile(fs, "/path/to/key.pem", []byte("test key content"), 0o600)
392 if err != nil {
393 t.Fatalf("WriteFile: %v", err)
394 }
395 },
396 expectErr: false,
397 },
398 {
399 name: "k8s secret success",
400 keyRef: "k8s://test-namespace/test-secret/private-key",
401 setup: func(fs afero.Fs, ctx context.Context) {
402 // This will be handled in the test loop
403 },
404 expectErr: false,
405 },
406 {
407 name: "file not found",
408 keyRef: "/nonexistent/key.pem",
409 setup: func(fs afero.Fs, ctx context.Context) {},
410 expectErr: true,
411 errMsg: "resolve private key",
412 },
413 {
414 name: "invalid k8s format",
415 keyRef: "k8s://invalid-format",
416 setup: func(fs afero.Fs, ctx context.Context) {},
417 expectErr: true,
418 errMsg: "invalid k8s key reference format",
419 },
420 {
421 name: "invalid k8s format - missing parts",
422 keyRef: "k8s://namespace",
423 setup: func(fs afero.Fs, ctx context.Context) {},
424 expectErr: true,
425 errMsg: "invalid k8s key reference format",
426 },

Callers

nothing calls this directly

Calls 3

NewSignerFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected