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

feat: blob sign command #1128

Merged
merged 30 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 2 additions & 3 deletions test/e2e/internal/utils/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
// VirtualHost is a virtualized host machine isolated by environment variable.
type VirtualHost struct {
Executor *ExecOpts

userDir string
env map[string]string
userDir string
env map[string]string
}

// NewVirtualHost creates a temporary user-level directory and updates
Expand Down
29 changes: 13 additions & 16 deletions test/e2e/suite/command/blob/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ import (

const tsaURL = "http://timestamp.digicert.com"

var _ = Describe("notation blob sign", func() {
var _ = Describe("notation blob sign", Serial, func() {
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
// Success cases
It("with blob sign", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
notation.Exec("blob", "sign", "--force", blobPath).
notation.WithWorkDir(vhost.AbsolutePath()).Exec("blob", "sign", blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords("Signature file written to")
})
})

It("with COSE format", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
notation.Exec("blob", "sign", "--signature-format", "cose", "--force", blobPath).
notation.WithWorkDir(vhost.AbsolutePath()).Exec("blob", "sign", "--signature-format", "cose", blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords("Signature file written to")
})
})

It("with specified media-type", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
notation.Exec("blob", "sign", "--force", "--media-type", "other-media-type", blobPath).
notation.WithWorkDir(vhost.AbsolutePath()).Exec("blob", "sign", "--media-type", "other-media-type", blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords("Signature file written to")
})
Expand All @@ -55,43 +55,42 @@ var _ = Describe("notation blob sign", func() {
It("with specific key", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
const keyName = "sKey"
notation.Exec("cert", "generate-test", keyName).
notation.WithWorkDir(vhost.AbsolutePath()).Exec("cert", "generate-test", keyName).
MatchKeyWords(fmt.Sprintf("notation/localkeys/%s.crt", keyName))

notation.Exec("blob", "sign", "--force", "--key", keyName, blobPath).
notation.WithWorkDir(vhost.AbsolutePath()).Exec("blob", "sign", "--key", keyName, blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords("Signature file written to")
})
})

It("with expiry in 24h", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
notation.Exec("blob", "sign", "--expiry", "24h", "--force", blobPath).
notation.WithWorkDir(vhost.AbsolutePath()).Exec("blob", "sign", "--expiry", "24h", blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords("Signature file written to")
})
})

It("with signature directory", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
blobDir := filepath.Dir(blobPath)
notation.Exec("blob", "sign", "--force", "--signature-directory", blobDir, blobPath).
notation.Exec("blob", "sign", "--force", "--signature-directory", vhost.AbsolutePath(), blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords(fmt.Sprintf("Signature file written to %s", filepath.Join(blobDir, "blobFile.jws.sig")))
MatchKeyWords(fmt.Sprintf("Signature file written to %s", filepath.Join(vhost.AbsolutePath(), "blobFile.jws.sig")))
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
})
})

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

It("with timestamping", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
notation.Exec("blob", "sign", "--force", "--timestamp-url", tsaURL, "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "DigiCertTSARootSHA384.cer"), blobPath).
notation.WithWorkDir(vhost.AbsolutePath()).Exec("blob", "sign", "--timestamp-url", tsaURL, "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "DigiCertTSARootSHA384.cer"), blobPath).
MatchKeyWords(SignSuccessfully).
MatchKeyWords("Signature file written to")
})
Expand Down Expand Up @@ -128,8 +127,7 @@ var _ = Describe("notation blob sign", func() {

It("with no permission to read the blob file", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
blobDir := filepath.Dir(blobPath)
noPermissionBlobPath := filepath.Join(blobDir, "noPermissionBlob")
noPermissionBlobPath := filepath.Join(vhost.AbsolutePath(), "noPermissionBlob")
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
newBlobFile, err := os.Create(noPermissionBlobPath)
if err != nil {
Fail(err.Error())
Expand All @@ -148,8 +146,7 @@ var _ = Describe("notation blob sign", func() {

It("with no permission to write the signature file", func() {
HostWithBlob(BaseOptions(), func(notation *utils.ExecOpts, blobPath string, vhost *utils.VirtualHost) {
blobDir := filepath.Dir(blobPath)
sigDir := filepath.Join(blobDir, "signature")
sigDir := filepath.Join(vhost.AbsolutePath(), "signature")
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
if err := os.MkdirAll(sigDir, 0000); err != nil {
Fail(err.Error())
}
Expand Down
Loading