-
Notifications
You must be signed in to change notification settings - Fork 40
Fail 'jf scan' when a wrong flag is provided after command's arguments #165
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
Changes from all commits
b73beff
4a880c0
0fea4d8
b6ef48a
a9bf652
601bd0a
01baf4c
1451968
84455f6
6ecc4ef
7c2782b
ea59b23
763a5bd
09e6dfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,6 +76,44 @@ func TestXrayBinaryScanSimpleJsonWithProgress(t *testing.T) { | |||||||||||||
| }) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // This test verifies the correctness of a use case in 'scan' command, where a user provides the command's arguments before the command's flags, and there is an incorrect flag. | ||||||||||||||
| // Since the library that parses the command expects the flags to be provided before the arguments, it cannot recognize a wrongly provided flag when the order is reversed. | ||||||||||||||
| // This test checks the fix for this issue. | ||||||||||||||
| func TestXrayBinaryScanWithIncorrectFlagsAfterArgs(t *testing.T) { | ||||||||||||||
| testCases := []struct { | ||||||||||||||
| name string | ||||||||||||||
| flagsBeforeArgs bool | ||||||||||||||
| }{ | ||||||||||||||
| { | ||||||||||||||
| name: "flags before args", | ||||||||||||||
| flagsBeforeArgs: true, | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| name: "args before flags", | ||||||||||||||
| flagsBeforeArgs: false, | ||||||||||||||
| }, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| callback := commonTests.MockProgressInitialization() | ||||||||||||||
| defer callback() | ||||||||||||||
| integration.InitScanTest(t, scangraph.GraphScanMinXrayVersion) | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| binariesPath := filepath.Join(filepath.FromSlash(securityTests.GetTestResourcesPath()), "projects", "binaries", "*") | ||||||||||||||
|
|
||||||||||||||
| for _, test := range testCases { | ||||||||||||||
| t.Run(test.name, func(t *testing.T) { | ||||||||||||||
| var args []string | ||||||||||||||
| if test.flagsBeforeArgs { | ||||||||||||||
| args = []string{"scan", "--watch=my-watch", binariesPath} | ||||||||||||||
| } else { | ||||||||||||||
| args = []string{"scan", binariesPath, "--watch=my-watch"} | ||||||||||||||
|
Comment on lines
+106
to
+108
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
change the flag name to make it more readable |
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| err := securityTests.PlatformCli.Exec(args...) | ||||||||||||||
| assert.Error(t, err) | ||||||||||||||
|
Comment on lines
+111
to
+112
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
maybe you can also check if its the error you added (or error expected) and not random one |
||||||||||||||
| }) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func testXrayBinaryScan(t *testing.T, format, policyName, watchName string, errorExpected bool) string { | ||||||||||||||
| binariesPath := filepath.Join(filepath.FromSlash(securityTests.GetTestResourcesPath()), "projects", "binaries", "*") | ||||||||||||||
| args := []string{"scan", binariesPath, "--licenses", "--format=" + format} | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.