-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add testing VerifyBlobCmd with CA roots
Signed-off-by: Dmitry S. <[email protected]>
- Loading branch information
Showing
2 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -873,16 +873,26 @@ func TestVerifyWithCARoots(t *testing.T) { | |
td := t.TempDir() | ||
|
||
imgName := path.Join(repo, "cosign-verify-caroots-e2e") | ||
|
||
privKeyRef := path.Join(repo, "cosign-verify-caroots-e2e-blob") | ||
_, _, cleanup := mkimage(t, imgName) | ||
defer cleanup() | ||
|
||
blob := "someblob2sign" | ||
|
||
b := bytes.Buffer{} | ||
blobRef := filepath.Join(td, blob) | ||
if err := os.WriteFile(blobRef, []byte(blob), 0644); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
must(generate.GenerateCmd(context.Background(), options.RegistryOptions{}, imgName, nil, &b), t) | ||
|
||
rootCert, rootKey, _ := GenerateRootCa() | ||
subCert, subKey, _ := GenerateSubordinateCa(rootCert, rootKey) | ||
leafCert, privKey, _ := GenerateLeafCert("[email protected]", "oidc-issuer", subCert, subKey) | ||
if err := ecdsaPublicKeyToPEMFile(privKey, privKeyRef); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
pemRoot := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: rootCert.Raw}) | ||
pemSub := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: subCert.Raw}) | ||
|
@@ -947,6 +957,14 @@ func TestVerifyWithCARoots(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
// Now sign the blob with one key | ||
ko := options.KeyOpts{ | ||
KeyRef: privKeyRef, | ||
} | ||
blobSig, err := sign.SignBlobCmd(ro, ko, blobRef, true, "", "", false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// the following fields with non-changing values are logically "factored out" for brevity | ||
// and passed to verifyKeylessTSAWithCARoots in the testing loop: | ||
// imageName string | ||
|
@@ -1053,6 +1071,21 @@ func TestVerifyWithCARoots(t *testing.T) { | |
t.Errorf("%s - unexpected error: %v", tt.name, err) | ||
} | ||
} | ||
err = verifyBlobKeylessTSAWithCARoots(blobRef, | ||
string(blobSig), | ||
tt.rootRef, | ||
tt.subRef, | ||
tt.leafRef, | ||
false, | ||
false) | ||
hasErr = (err != nil) | ||
if hasErr != tt.wantError { | ||
if tt.wantError { | ||
t.Errorf("%s - no expected error", tt.name) | ||
} else { | ||
t.Errorf("%s - unexpected error: %v", tt.name, err) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters