Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Adding -r flag to automatically clone and test remote go modules, along with functionality to test the Scan cmd #20

Merged
merged 5 commits into from
Aug 27, 2021

Conversation

bpsizemore
Copy link
Contributor

Added a new flag -r or --remoteModule which allows you to specify a remote module for analysis.

gokart scan -r github.com/praetorian-inc/gokart

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.

@isp1r0 isp1r0 self-assigned this Aug 24, 2021
@michaelweber
Copy link
Collaborator

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.

Copy link
Contributor

@isp1r0 isp1r0 left a 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

cmd/scan.go Outdated Show resolved Hide resolved
cmd/scan.go Outdated Show resolved Hide resolved
util/module.go Show resolved Hide resolved
cmd/scan.go Show resolved Hide resolved
Copy link
Contributor

@isp1r0 isp1r0 left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@isp1r0 isp1r0 merged commit 7e47711 into praetorian-inc:main Aug 27, 2021
}
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.")

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants