Skip to content

Commit

Permalink
fix(codeqlExecuteScan): Fix for GlobalSettingsFile url checks (#4708)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeetpatil authored Dec 5, 2023
1 parent e6a7432 commit a6dccf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/codeqlExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ func getMavenSettings(config *codeqlExecuteScanOptions) string {
params = " --settings=" + config.ProjectSettingsFile
}
}

if len(config.GlobalSettingsFile) > 0 {
if strings.Contains(config.ProjectSettingsFile, "http") {
if strings.Contains(config.GlobalSettingsFile, "http") {
log.Entry().Warn("codeqlExecuteScan's globalSettingsFile param still does not support http(s) urls. Please use a local file path")
} else {
params = params + " --global-settings=" + config.GlobalSettingsFile
Expand Down
16 changes: 14 additions & 2 deletions cmd/codeqlExecuteScan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,29 @@ func TestGetMavenSettings(t *testing.T) {
assert.Equal(t, " --settings=test.xml --global-settings=global.xml", params)
})

t.Run("Skip incase of https url", func(t *testing.T) {
t.Run("Skip incase of ProjectSettingsFile https url", func(t *testing.T) {
config := codeqlExecuteScanOptions{BuildTool: "maven", BuildCommand: "mvn clean install", ProjectSettingsFile: "https://jenkins-sap-test.com/test.xml"}
params := getMavenSettings(&config)
assert.Equal(t, "", params)
})

t.Run("Skip incase of http url", func(t *testing.T) {
t.Run("Skip incase of ProjectSettingsFile http url", func(t *testing.T) {
config := codeqlExecuteScanOptions{BuildTool: "maven", BuildCommand: "mvn clean install", ProjectSettingsFile: "http://jenkins-sap-test.com/test.xml"}
params := getMavenSettings(&config)
assert.Equal(t, "", params)
})

t.Run("Skip incase of GlobalSettingsFile https url", func(t *testing.T) {
config := codeqlExecuteScanOptions{BuildTool: "maven", BuildCommand: "mvn clean install", GlobalSettingsFile: "https://jenkins-sap-test.com/test.xml"}
params := getMavenSettings(&config)
assert.Equal(t, "", params)
})

t.Run("Skip incase of GlobalSettingsFile http url", func(t *testing.T) {
config := codeqlExecuteScanOptions{BuildTool: "maven", BuildCommand: "mvn clean install", GlobalSettingsFile: "http://jenkins-sap-test.com/test.xml"}
params := getMavenSettings(&config)
assert.Equal(t, "", params)
})
}

type CodeqlSarifUploaderMock struct {
Expand Down

0 comments on commit a6dccf9

Please sign in to comment.