Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 7d75237

Browse files
committed
Do not require accept-license to display version
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
1 parent 0b3c564 commit 7d75237

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

cmd/docker-scan/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ func checkConsent(flags options, dockerCli command.Streams) (config.Config, erro
157157
if err != nil {
158158
return config.Config{}, err
159159
}
160+
if flags.showVersion {
161+
return conf, nil
162+
}
160163

161164
if !conf.Optin || flags.forceOptIn || flags.forceOptOut {
162165
switch {

e2e/optin_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestFirstScanOptinMessage(t *testing.T) {
4242
// docker scan should ask for consent the first time the user runs it
4343
in, out, err := os.Pipe()
4444
assert.NilError(t, err)
45-
cmd.Command = dockerCli.Command("scan", "--version")
45+
cmd.Command = dockerCli.Command("scan", "myimage")
4646
cmd.Stdin = in
4747

4848
go func() {
@@ -51,8 +51,7 @@ func TestFirstScanOptinMessage(t *testing.T) {
5151
}()
5252

5353
result := icmd.RunCmd(cmd)
54-
assert.Assert(t, strings.Contains(result.Combined(), `Docker Scan relies upon access to Snyk, a third party provider, do you consent to proceed using Snyk? (y/N)
55-
Version:`))
54+
assert.Assert(t, strings.Contains(result.Combined(), `Docker Scan relies upon access to Snyk, a third party provider, do you consent to proceed using Snyk? (y/N)`))
5655

5756
// check the consent has been stored in config file
5857
data, err := ioutil.ReadFile(filepath.Join(configDir, "scan", "config.json"))
@@ -67,8 +66,8 @@ func TestRefuseOptinWithDisableFlag(t *testing.T) {
6766
defer cleanup()
6867
createScanConfigFile(t, configDir)
6968

70-
// docker scan --version should exit immediately
71-
cmd.Command = dockerCli.Command("scan", "--reject-license", "--version")
69+
// docker scan myimage should exit immediately
70+
cmd.Command = dockerCli.Command("scan", "--reject-license", "myimage")
7271
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
7372
ExitCode: 0,
7473
Out: "",

e2e/version_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestVersionSnykDesktopBinary(t *testing.T) {
8383
createScanConfigFile(t, configDir)
8484

8585
// docker scan --version should print docker scan plugin version and snyk version
86-
cmd.Command = dockerCli.Command("scan", "--accept-license", "--version")
86+
cmd.Command = dockerCli.Command("scan", "--version")
8787
output := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined()
8888
expected := fmt.Sprintf(
8989
`Version: %s
@@ -99,7 +99,7 @@ func TestVersionWithoutSnykOrConfig(t *testing.T) {
9999
defer cleanup()
100100

101101
// docker scan --version should fail with a clean error
102-
cmd.Command = dockerCli.Command("scan", "--accept-license", "--version")
102+
cmd.Command = dockerCli.Command("scan", "--version")
103103
res := icmd.RunCmd(cmd)
104104
if runtime.GOOS != "darwin" && runtime.GOOS != "windows" { // config file created by default without Docker Desktop
105105
expected := fmt.Sprintf(`Version: %s

0 commit comments

Comments
 (0)