Skip to content

Commit

Permalink
added more e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Jan 10, 2025
1 parent 07c66b4 commit 4c07098
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/notation/blob/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Example - Verify the signature on a blob artifact using a policy statement name:
`
command := &cobra.Command{
Use: "verify [flags] --signature <signature_path> <blob_path>",
Short: "verify a signature associated with a blob",
Short: "Verify a signature associated with a blob",
Long: longMessage,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
Expand Down
14 changes: 7 additions & 7 deletions specs/commandline/blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ Usage:
notation blob verify [flags] --signature <signature_path> <blob_path>
Flags:
--signature string filepath of the signature to be verified
--media-type string optional media type of the blob to verify
--policy-name string optional policy name to verify against. If not provided, the global policy is used if exists
-m, --user-metadata stringArray user defined {key}={value} pairs that must be present in the signature for successful verification if provided
-d, --debug debug mode
-h, --help help for verify
--media-type string media type of the blob to verify
--plugin-config stringArray {key}={value} pairs that are passed as it is to a plugin, if the verification is associated with a verification plugin, refer plugin documentation to set appropriate values
-d, --debug debug mode
-v, --verbose verbose mode
-h, --help help for inspect
--policy-name string policy name to verify against. If not provided, the global policy is used if exists
--signature string filepath of the signature to be verified
-m, --user-metadata stringArray user defined {key}={value} pairs that must be present in the signature for successful verification if provided
-v, --verbose verbose mode
```

## Usage
Expand Down
27 changes: 26 additions & 1 deletion test/e2e/suite/command/blob/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = Describe("notation blob verify", func() {
MatchKeyWords("Signature file written to")

signaturePath := signatureFilepath(workDir, blobPath, "jws")
notation.Exec("blob", "verify", "-d", "--media-type", "image/jpeg", "--signature", signaturePath, blobPath).
notation.Exec("blob", "verify", "--media-type", "image/jpeg", "--signature", signaturePath, blobPath).
MatchKeyWords(VerifySuccessfully)
})
})
Expand All @@ -108,7 +108,32 @@ var _ = Describe("notation blob verify", func() {
})
})

It("with user metadata", func() {
HostWithBlob(BaseBlobOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
workDir := vhost.AbsolutePath()
notation.WithWorkDir(workDir).Exec("blob", "sign", "--user-metadata", "k1=v1", blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords("Signature file written to")

signaturePath := signatureFilepath(workDir, blobPath, "jws")
notation.Exec("blob", "verify", "--user-metadata", "k1=v1", "--signature", signaturePath, blobPath).
MatchKeyWords(VerifySuccessfully)
})
})

// Failure cases
It("with missing --signature flag", func() {
HostWithBlob(BaseBlobOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
workDir := vhost.AbsolutePath()
notation.WithWorkDir(workDir).Exec("blob", "sign", blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords("Signature file written to")

notation.ExpectFailure().Exec("blob", "verify", blobPath).
MatchErrKeyWords("filepath of the signature cannot be empty")
})
})

It("with no permission to read blob", func() {
HostWithBlob(BaseBlobOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
workDir := vhost.AbsolutePath()
Expand Down

0 comments on commit 4c07098

Please sign in to comment.