-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added centralized config utilization in Audit for CI Next (#146)
- Loading branch information
1 parent
8c43a37
commit e2976fb
Showing
13 changed files
with
403 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package audit | ||
|
||
import ( | ||
biutils "github.com/jfrog/build-info-go/utils" | ||
"github.com/jfrog/jfrog-cli-core/v2/common/format" | ||
coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests" | ||
"github.com/jfrog/jfrog-cli-security/utils" | ||
"github.com/jfrog/jfrog-cli-security/utils/xray/scangraph" | ||
clientTests "github.com/jfrog/jfrog-client-go/utils/tests" | ||
"github.com/jfrog/jfrog-client-go/xsc/services" | ||
"github.com/stretchr/testify/assert" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
// Note: Currently, if a config profile is provided, the scan will use the profile's settings, IGNORING jfrog-apps-config if exists. | ||
func TestAuditWithConfigProfile(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
configProfile services.ConfigProfile | ||
expectedSastIssues int | ||
expectedSecretsIssues int | ||
}{ | ||
{ | ||
name: "Enable only secrets scanner", | ||
configProfile: services.ConfigProfile{ | ||
ProfileName: "only-secrets", | ||
Modules: []services.Module{{ | ||
ModuleId: 1, | ||
ModuleName: "only-secrets-module", | ||
PathFromRoot: ".", | ||
ScanConfig: services.ScanConfig{ | ||
SastScannerConfig: services.SastScannerConfig{ | ||
EnableSastScan: false, | ||
}, | ||
SecretsScannerConfig: services.SecretsScannerConfig{ | ||
EnableSecretsScan: true, | ||
}, | ||
}, | ||
}}, | ||
IsDefault: false, | ||
}, | ||
expectedSastIssues: 0, | ||
expectedSecretsIssues: 7, | ||
}, | ||
{ | ||
name: "Enable only sast scanner", | ||
configProfile: services.ConfigProfile{ | ||
ProfileName: "only-sast", | ||
Modules: []services.Module{{ | ||
ModuleId: 1, | ||
ModuleName: "only-sast-module", | ||
PathFromRoot: ".", | ||
ScanConfig: services.ScanConfig{ | ||
SastScannerConfig: services.SastScannerConfig{ | ||
EnableSastScan: true, | ||
}, | ||
SecretsScannerConfig: services.SecretsScannerConfig{ | ||
EnableSecretsScan: false, | ||
}, | ||
}, | ||
}}, | ||
IsDefault: false, | ||
}, | ||
expectedSastIssues: 1, | ||
expectedSecretsIssues: 0, | ||
}, | ||
{ | ||
name: "Enable secrets and sast", | ||
configProfile: services.ConfigProfile{ | ||
ProfileName: "secrets&sast", | ||
Modules: []services.Module{{ | ||
ModuleId: 1, | ||
ModuleName: "secrets&sast-module", | ||
PathFromRoot: ".", | ||
ScanConfig: services.ScanConfig{ | ||
SastScannerConfig: services.SastScannerConfig{ | ||
EnableSastScan: true, | ||
}, | ||
SecretsScannerConfig: services.SecretsScannerConfig{ | ||
EnableSecretsScan: true, | ||
}, | ||
}, | ||
}}, | ||
IsDefault: false, | ||
}, | ||
expectedSastIssues: 1, | ||
expectedSecretsIssues: 7, | ||
}, | ||
} | ||
|
||
for _, testcase := range testcases { | ||
t.Run(testcase.name, func(t *testing.T) { | ||
mockServer, serverDetails := utils.XrayServer(t, utils.EntitlementsMinVersion) | ||
defer mockServer.Close() | ||
|
||
auditBasicParams := (&utils.AuditBasicParams{}). | ||
SetServerDetails(serverDetails). | ||
SetOutputFormat(format.Table). | ||
SetUseJas(true) | ||
|
||
configProfile := testcase.configProfile | ||
auditParams := NewAuditParams(). | ||
SetGraphBasicParams(auditBasicParams). | ||
SetConfigProfile(&configProfile). | ||
SetCommonGraphScanParams(&scangraph.CommonGraphScanParams{ | ||
RepoPath: "", | ||
ProjectKey: "", | ||
Watches: nil, | ||
ScanType: "dependency", | ||
IncludeVulnerabilities: true, | ||
XscVersion: services.ConfigProfileMinXscVersion, | ||
MultiScanId: "random-msi", | ||
}) | ||
auditParams.SetIsRecursiveScan(true) | ||
|
||
tempDirPath, createTempDirCallback := coreTests.CreateTempDirWithCallbackAndAssert(t) | ||
defer createTempDirCallback() | ||
testDirPath := filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas") | ||
assert.NoError(t, biutils.CopyDir(testDirPath, tempDirPath, true, nil)) | ||
|
||
baseWd, err := os.Getwd() | ||
assert.NoError(t, err) | ||
chdirCallback := clientTests.ChangeDirWithCallback(t, baseWd, tempDirPath) | ||
defer chdirCallback() | ||
|
||
auditResults, err := RunAudit(auditParams) | ||
assert.NoError(t, err) | ||
|
||
// Currently, the only supported scanners are Secrets and Sast, therefore if a config profile is utilized - all other scanners are disabled. | ||
if testcase.expectedSastIssues > 0 { | ||
assert.NotNil(t, auditResults.ExtendedScanResults.SastScanResults) | ||
assert.Equal(t, testcase.expectedSastIssues, len(auditResults.ExtendedScanResults.SastScanResults[0].Results)) | ||
} else { | ||
assert.Nil(t, auditResults.ExtendedScanResults.SastScanResults) | ||
} | ||
|
||
if testcase.expectedSecretsIssues > 0 { | ||
assert.NotNil(t, auditResults.ExtendedScanResults.SecretsScanResults) | ||
assert.Equal(t, testcase.expectedSecretsIssues, len(auditResults.ExtendedScanResults.SecretsScanResults[0].Results)) | ||
} else { | ||
assert.Nil(t, auditResults.ExtendedScanResults.SecretsScanResults) | ||
} | ||
|
||
assert.Nil(t, auditResults.ScaResults) | ||
assert.Nil(t, auditResults.ExtendedScanResults.ApplicabilityScanResults) | ||
assert.Nil(t, auditResults.ExtendedScanResults.IacScanResults) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/testdata/other/configProfile/configProfileExample.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"profile_name": "default-profile", | ||
"frogbot_config": { | ||
"email_author": "[email protected]", | ||
"aggregate_fixes": true, | ||
"avoid_previous_pr_comments_deletion": true, | ||
"branch_name_template": "frogbot-${IMPACTED_PACKAGE}-${BRANCH_NAME_HASH}", | ||
"pr_title_template": "[🐸 Frogbot] Upgrade {IMPACTED_PACKAGE} to {FIX_VERSION}", | ||
"pr_comment_title": "Frogbot notes:", | ||
"commit_message_template": "Upgrade {IMPACTED_PACKAGE} to {FIX_VERSION}", | ||
"show_secrets_as_pr_comment": false | ||
}, | ||
"modules": [ | ||
{ | ||
"module_name": "default-module", | ||
"path_from_root": ".", | ||
"releases_repo": "nuget-remote", | ||
"analyzer_manager_version": "1.8.1", | ||
"additional_paths_for_module": ["lib1", "utils/lib2"], | ||
"exclude_paths": ["**/.git/**", "**/*test*/**", "**/*venv*/**", "**/*node_modules*/**", "**/target/**"], | ||
"scan_config": { | ||
"scan_timeout": 600, | ||
"exclude_pattern": "*.md", | ||
"enable_sca_scan": true, | ||
"enable_contextual_analysis_scan": true, | ||
"sast_scanner_config": { | ||
"enable_sast_scan": true | ||
}, | ||
"secrets_scanner_config": { | ||
"enable_secrets_scan": true | ||
}, | ||
"iac_scanner_config": { | ||
"enable_iac_scan": true | ||
}, | ||
"applications_scanner_config": { | ||
"enable_applications_scan": true | ||
}, | ||
"services_scanner_config": { | ||
"enable_services_scan": true | ||
} | ||
}, | ||
"protected_branches": ["main", "master"], | ||
"include_exclude_mode": 0, | ||
"include_exclude_pattern": "*test*", | ||
"report_analytics": true | ||
} | ||
], | ||
"is_default": true | ||
} |
Oops, something went wrong.