-
Notifications
You must be signed in to change notification settings - Fork 112
Adding -r flag to automatically clone and test remote go modules, along with functionality to test the Scan cmd #20
Conversation
Made some minor changes (variable casing) when merging for consistency across the codebase, but I know we're all over the place with conventions in the repo. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Functionality works great assuming repo does not yet exist
- Changes requested to error handling
- Running 'go test -v' in /cmd directory throws errors:
ianspiro@Ians-MacBook-Pro cmd % go test -v
=== RUN TestScanCommand
Current dir is: /Users/ianspiro/Documents/sandbox/chariot-2021/gokart/cmd=== RUN TestScanCommand/scan
=== RUN TestScanCommand/scan_-r_github.com/Contrast-Security-OSS/go-test-bench
scan_test.go:49: Failed! Expected: GoKart found 8 potentially vulnerable functions
Got: CRASH! GoKart didn't find any files to scan! Make sure the usage is correct to get GoKart back on track.
=== RUN TestScanCommand/scan_-r_github.com/praetorian-inc/gokart
scan_test.go:49: Failed! Expected: GoKart found 0 potentially vulnerable functions
Got: CRASH! GoKart didn't find any files to scan! Make sure the usage is correct to get GoKart back on track.
=== RUN TestScanCommand/scan_--help
--- FAIL: TestScanCommand (1.81s)
--- PASS: TestScanCommand/scan (0.44s)
--- FAIL: TestScanCommand/scan_-r_github.com/Contrast-Security-OSS/go-test-bench (0.74s)
--- FAIL: TestScanCommand/scan_-r_github.com/praetorian-inc/gokart (0.62s)
--- PASS: TestScanCommand/scan_--help (0.00s)
FAIL
exit status 1
FAIL github.com/praetorian-inc/gokart/cmd 2.592s```
- Deletion of repo does not currently happen for remote repos Suggest use of deferred call to CleanupModule
…ote repo, adding verbosity to git failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outstanding @bpsizemore! This, combined with the -o,--output flag that @michaelweber added makes the usage completely frictionless 🏆
// If we're given a target path, we do some slight changes to make sure that | ||
// gokart will behave as expected. Specifically we turn the path into an absolute | ||
// path, and then we append /... to the end to make sure the package loading is recursive. | ||
// Finally we update the current working directory to the target | ||
// In order to not cause issues we set the working directory back after we are done scanning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
} | ||
err = util.CloneModule(modDirName, "https://"+goModName) | ||
if err != nil { | ||
log.Fatal("GoKart was unable to get the new racetrack. Ensure track repository is open to the public or that your access tokens are configured correctly for Private ones.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It said your access tokens are configured correctly for Private ones, but how do I define those things?
Added a new flag
-r
or--remoteModule
which allows you to specify a remote module for analysis.Also added a new file gokart/cmd/scan_test.go which implements some very basic tests for the scan functionality. This should serve as a solid foundation as we add more features and modify the ability/way we specify modules to scan.