Skip to content

Commit 1b300d6

Browse files
authored
Use new xsc git info struct
1 parent 6075488 commit 1b300d6

File tree

10 files changed

+92
-70
lines changed

10 files changed

+92
-70
lines changed

commands/audit/audit_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ func TestCreateResultsContext(t *testing.T) {
652652
expectedIncludeVulnerabilitiesIfOnlyGitRepoUrlProvided := false
653653
if len(test.expectedPlatformWatches.GitRepositoryWatches) > 0 {
654654
// We should include the value of gitRepoUrl only if a watch is assigned to this git_repository
655-
testCaseExpectedGitRepoHttpsCloneUrl = validations.TestMockGitInfo.GitRepoHttpsCloneUrl
655+
testCaseExpectedGitRepoHttpsCloneUrl = validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl
656656
} else {
657657
// If only the git repo url is provided but not supported or there are no defined watches, the expected includeVulnerabilities flag should be set to true even if not provided
658658
expectedIncludeVulnerabilitiesIfOnlyGitRepoUrlProvided = true
@@ -704,13 +704,13 @@ func TestCreateResultsContext(t *testing.T) {
704704
},
705705
{
706706
name: "Git Clone Url",
707-
httpCloneUrl: validations.TestMockGitInfo.GitRepoHttpsCloneUrl,
707+
httpCloneUrl: validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl,
708708
expectedHttpCloneUrl: testCaseExpectedGitRepoHttpsCloneUrl,
709709
expectedIncludeVulnerabilities: expectedIncludeVulnerabilitiesIfOnlyGitRepoUrlProvided,
710710
},
711711
{
712712
name: "All",
713-
httpCloneUrl: validations.TestMockGitInfo.GitRepoHttpsCloneUrl,
713+
httpCloneUrl: validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl,
714714
watches: mockWatches,
715715
jfrogProjectKey: mockProjectKey,
716716
includeVulnerabilities: true,

commands/git/audit/gitaudit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func toAuditParams(params GitAuditParams) *sourceAudit.AuditParams {
8383
params.resultsContext.Watches,
8484
params.resultsContext.RepoPath,
8585
params.resultsContext.ProjectKey,
86-
params.source.GitRepoHttpsCloneUrl,
86+
params.source.Source.GitRepoHttpsCloneUrl,
8787
params.resultsContext.IncludeVulnerabilities,
8888
params.resultsContext.IncludeLicenses,
8989
false,

git_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestGitAuditViolationsWithIgnoreRule(t *testing.T) {
9595
// Create policy and watch for the git repo so we will also get violations (unknown = all vulnerabilities will be reported as violations)
9696
policyName, cleanUpPolicy := securityTestUtils.CreateTestSecurityPolicy(t, "git-repo-ignore-rule-policy", utils.Unknown, true, false)
9797
defer cleanUpPolicy()
98-
watchName, cleanUpWatch := securityTestUtils.CreateWatchForTests(t, policyName, "git-repo-ignore-rule-watch", xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.GitRepoHttpsCloneUrl))
98+
watchName, cleanUpWatch := securityTestUtils.CreateWatchForTests(t, policyName, "git-repo-ignore-rule-watch", xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl))
9999
defer cleanUpWatch()
100100

101101
// Run the audit command with git repo and verify violations are reported to the platform.
@@ -111,19 +111,19 @@ func TestGitAuditViolationsWithIgnoreRule(t *testing.T) {
111111

112112
// Create an ignore rules for the git repo
113113
cleanUpCveIgnoreRule := securityTestUtils.CreateTestIgnoreRules(t, "security cli tests - Sca ignore rule", utils.IgnoreFilters{
114-
GitRepositories: []string{xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.GitRepoHttpsCloneUrl)},
114+
GitRepositories: []string{xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl)},
115115
CVEs: []string{"any"}, Licenses: []string{"any"},
116116
Watches: []string{watchName},
117117
})
118118
defer cleanUpCveIgnoreRule()
119119
cleanUpExposureIgnoreRule := securityTestUtils.CreateTestIgnoreRules(t, "security cli tests - Exposure ignore rule", utils.IgnoreFilters{
120-
GitRepositories: []string{xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.GitRepoHttpsCloneUrl)},
120+
GitRepositories: []string{xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl)},
121121
Exposures: &utils.ExposuresFilterName{Categories: []utils.ExposureType{utils.SecretExposureType, utils.IacExposureType}},
122122
Watches: []string{watchName},
123123
})
124124
defer cleanUpExposureIgnoreRule()
125125
cleanSastUpIgnoreRule := securityTestUtils.CreateTestIgnoreRules(t, "security cli tests - Sast ignore rule", utils.IgnoreFilters{
126-
GitRepositories: []string{xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.GitRepoHttpsCloneUrl)},
126+
GitRepositories: []string{xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl)},
127127
Sast: &utils.SastFilterName{Rule: []string{"any"}},
128128
Watches: []string{watchName},
129129
})
@@ -178,7 +178,7 @@ func TestXrayAuditJasSkipNotApplicableCvesViolations(t *testing.T) {
178178
cleanUpPolicy()
179179
}
180180
}()
181-
watchName, cleanUpWatch := securityTestUtils.CreateWatchForTests(t, policyName, "without-skip-not-applicable-watch", xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.GitRepoHttpsCloneUrl))
181+
watchName, cleanUpWatch := securityTestUtils.CreateWatchForTests(t, policyName, "without-skip-not-applicable-watch", xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl))
182182
defer func() {
183183
if !firstWatchCleaned {
184184
cleanUpWatch()
@@ -207,7 +207,7 @@ func TestXrayAuditJasSkipNotApplicableCvesViolations(t *testing.T) {
207207
// Create policy and watch for the git repo so we will also get violations - This watch SKIP not-applicable results
208208
skipPolicyName, skipCleanUpPolicy := securityTestUtils.CreateTestSecurityPolicy(t, "skip-non-applicable-policy", utils.Low, false, true)
209209
defer skipCleanUpPolicy()
210-
skipWatchName, skipCleanUpWatch := securityTestUtils.CreateWatchForTests(t, skipPolicyName, "skip-not-applicable-watch", xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.GitRepoHttpsCloneUrl))
210+
skipWatchName, skipCleanUpWatch := securityTestUtils.CreateWatchForTests(t, skipPolicyName, "skip-not-applicable-watch", xscutils.GetGitRepoUrlKey(validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl))
211211
defer skipCleanUpWatch()
212212

213213
// Run the audit command with git repo and verify violations are reported to the platform and not applicable issues are skipped.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ require (
111111
gopkg.in/warnings.v0 v0.1.2 // indirect
112112
)
113113

114-
// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go dev
114+
replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250309113753-9cb691a755b5
115115

116116
// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 dev
117117

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ github.com/jfrog/jfrog-cli-artifactory v0.2.0 h1:4jEbIpJIeu8HsduZHr8L6e0bKQrhn6B
132132
github.com/jfrog/jfrog-cli-artifactory v0.2.0/go.mod h1:U9gkQhxSPv6tXYEdj0kdsCrmFUjcvYmizrh+DztDxXc=
133133
github.com/jfrog/jfrog-cli-core/v2 v2.58.1 h1:ZktHuEVDBkM21JNp/0V3HGcMAMt7DLl1iQlbyBNKucE=
134134
github.com/jfrog/jfrog-cli-core/v2 v2.58.1/go.mod h1:75J6/Z5sMuRAloMAqJtMJIXqNTC1eFh/SulgLGm2fIY=
135-
github.com/jfrog/jfrog-client-go v1.51.0 h1:O9sgpgEDBW9t05brGYwNR/NMqJ/e3WZY9G8Wge2xR+Q=
136-
github.com/jfrog/jfrog-client-go v1.51.0/go.mod h1:2tQPwRhGS/F357BOKFfZrQbjd4XbzHPYUQm/OFNwLHg=
135+
github.com/jfrog/jfrog-client-go v1.28.1-0.20250309113753-9cb691a755b5 h1:Q9dVmb8sz2SXlqbtIuvIajIWFZwkp4269VXFaSqP1yM=
136+
github.com/jfrog/jfrog-client-go v1.28.1-0.20250309113753-9cb691a755b5/go.mod h1:2tQPwRhGS/F357BOKFfZrQbjd4XbzHPYUQm/OFNwLHg=
137137
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
138138
github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg=
139139
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=

utils/scm/gitmanager.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ func (gm *GitManager) GetSourceControlContext() (gitInfo *services.XscGitInfoCon
116116
// Create the gitInfo object with known git information
117117
gitInfo = &services.XscGitInfoContext{
118118
GitProvider: getGitProvider(remoteUrl).String(),
119-
// Use Clone URLs as Repo Url, on browsers it will redirect to repository URLS.
120-
GitRepoHttpsCloneUrl: remoteUrl,
121-
GitRepoName: getGitRepoName(remoteUrl),
122-
GitProject: getGitProject(remoteUrl),
123-
124-
BranchName: currentBranch.Name().Short(),
125-
126-
LastCommitHash: lastCommit.Hash.String(),
127-
LastCommitMessage: strings.TrimSpace(lastCommit.Message),
128-
LastCommitAuthor: lastCommit.Author.Name,
119+
Source: services.CommitContext{
120+
// Use Clone URLs as Repo Url, on browsers it will redirect to repository URLS.
121+
GitRepoHttpsCloneUrl: remoteUrl,
122+
GitRepoName: getGitRepoName(remoteUrl),
123+
GitProject: getGitProject(remoteUrl),
124+
BranchName: currentBranch.Name().Short(),
125+
CommitHash: lastCommit.Hash.String(),
126+
CommitMessage: strings.TrimSpace(lastCommit.Message),
127+
CommitAuthor: lastCommit.Author.Name,
128+
},
129129
}
130130
isClean, err := gm.isClean()
131131
if err != nil {

utils/scm/gitmanager_test.go

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,70 +32,80 @@ func TestGetGitContext(t *testing.T) {
3232
name: "Clean Project (after clone)",
3333
testProjectZipDirPath: filepath.Join(basePath, "clean"),
3434
gitInfo: &services.XscGitInfoContext{
35-
GitRepoHttpsCloneUrl: "https://github.com/attiasas/test-security-git.git",
36-
GitRepoName: "test-security-git",
37-
GitProject: "attiasas",
38-
GitProvider: "github",
39-
BranchName: "main",
40-
LastCommitHash: "5fc36ff0666e5ce9dba6c0a1c539ee640cabe0b0",
41-
LastCommitMessage: "remove json",
42-
LastCommitAuthor: "attiasas",
35+
Source: services.CommitContext{
36+
GitRepoHttpsCloneUrl: "https://github.com/attiasas/test-security-git.git",
37+
GitRepoName: "test-security-git",
38+
GitProject: "attiasas",
39+
BranchName: "main",
40+
CommitHash: "5fc36ff0666e5ce9dba6c0a1c539ee640cabe0b0",
41+
CommitMessage: "remove json",
42+
CommitAuthor: "attiasas",
43+
},
44+
GitProvider: "github",
4345
},
4446
},
4547
{
4648
name: "Self-Hosted Git Project (and SSO credentials)",
4749
testProjectZipDirPath: filepath.Join(basePath, "selfhosted"),
4850
gitInfo: &services.XscGitInfoContext{
49-
GitRepoHttpsCloneUrl: "ssh://[email protected]/~assafa/test-security-git.git",
50-
GitRepoName: "test-security-git",
51-
GitProject: "~assafa",
52-
GitProvider: "bitbucket",
53-
BranchName: "main",
54-
LastCommitHash: "6abd0162f4e02e358124f74e89b30d1b1ff906bc",
55-
LastCommitMessage: "initial commit",
56-
LastCommitAuthor: "attiasas",
51+
Source: services.CommitContext{
52+
GitRepoHttpsCloneUrl: "ssh://[email protected]/~assafa/test-security-git.git",
53+
GitRepoName: "test-security-git",
54+
GitProject: "~assafa",
55+
BranchName: "main",
56+
CommitHash: "6abd0162f4e02e358124f74e89b30d1b1ff906bc",
57+
CommitMessage: "initial commit",
58+
CommitAuthor: "attiasas",
59+
},
60+
GitProvider: "bitbucket",
5761
},
5862
},
5963
{
6064
name: "Gitlab Project (group tree structure)",
6165
testProjectZipDirPath: filepath.Join(basePath, "gitlab"),
6266
gitInfo: &services.XscGitInfoContext{
63-
GitRepoHttpsCloneUrl: "https://gitlab.com/attiasas/test-group/test-security-git.git",
64-
GitRepoName: "test-security-git",
65-
GitProject: "attiasas/test-group",
66-
GitProvider: "gitlab",
67-
BranchName: "main",
68-
LastCommitHash: "ada14e9f525d8cbfb3c8c31ebe345d85ec342480",
69-
LastCommitMessage: "add npm",
70-
LastCommitAuthor: "attiasas",
67+
Source: services.CommitContext{
68+
GitRepoHttpsCloneUrl: "https://gitlab.com/attiasas/test-group/test-security-git.git",
69+
GitRepoName: "test-security-git",
70+
GitProject: "attiasas/test-group",
71+
BranchName: "main",
72+
CommitHash: "ada14e9f525d8cbfb3c8c31ebe345d85ec342480",
73+
CommitMessage: "add npm",
74+
CommitAuthor: "attiasas",
75+
},
76+
GitProvider: "gitlab",
7177
},
7278
},
7379
{
7480
name: "Gerrit Project (no owner)",
7581
testProjectZipDirPath: filepath.Join(basePath, "gerrit"),
7682
gitInfo: &services.XscGitInfoContext{
77-
GitRepoHttpsCloneUrl: "https://gerrit.googlesource.com/git-repo",
78-
GitRepoName: "git-repo",
79-
GitProject: "git-repo",
80-
GitProvider: "gerrit",
81-
BranchName: "main",
82-
LastCommitHash: "a532f57a1f20623f5b9dd022493141a5b2a71009",
83-
LastCommitMessage: `clean project`,
84-
LastCommitAuthor: "attiasas",
83+
Source: services.CommitContext{
84+
GitRepoHttpsCloneUrl: "https://gerrit.googlesource.com/git-repo",
85+
GitRepoName: "git-repo",
86+
GitProject: "git-repo",
87+
BranchName: "main",
88+
CommitHash: "a532f57a1f20623f5b9dd022493141a5b2a71009",
89+
CommitMessage: `clean project`,
90+
CommitAuthor: "attiasas",
91+
},
92+
GitProvider: "gerrit",
8593
},
8694
},
8795
{
8896
name: "Forked Project (multiple remotes)",
8997
testProjectZipDirPath: filepath.Join(basePath, "forked"),
9098
gitInfo: &services.XscGitInfoContext{
91-
GitRepoHttpsCloneUrl: "https://github.com/attiasas/test-security-git.git",
92-
GitRepoName: "test-security-git",
93-
GitProject: "attiasas",
94-
GitProvider: "github",
95-
BranchName: "main",
96-
LastCommitHash: "5fc36ff0666e5ce9dba6c0a1c539ee640cabe0b0",
97-
LastCommitMessage: "remove json",
98-
LastCommitAuthor: "attiasas",
99+
Source: services.CommitContext{
100+
GitRepoHttpsCloneUrl: "https://github.com/attiasas/test-security-git.git",
101+
GitRepoName: "test-security-git",
102+
GitProject: "attiasas",
103+
BranchName: "main",
104+
CommitHash: "5fc36ff0666e5ce9dba6c0a1c539ee640cabe0b0",
105+
CommitMessage: "remove json",
106+
CommitAuthor: "attiasas",
107+
},
108+
GitProvider: "github",
99109
},
100110
},
101111
// Not supported yet

utils/validations/test_mocks.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ var (
3939
versionApiUrl = "/%s/%ssystem/version"
4040

4141
TestMockGitInfo = xscservices.XscGitInfoContext{
42-
GitRepoHttpsCloneUrl: "https://github.com/jfrog/dummy-repo.git",
43-
GitProvider: "github",
44-
GitRepoName: "dummy-repo",
45-
GitProject: "jfrog",
46-
BranchName: "dev",
47-
LastCommitHash: "4be861f9a585d8ae5dde0b9550669972ee05c9d7",
42+
Source: xscservices.CommitContext{
43+
GitRepoHttpsCloneUrl: "https://github.com/jfrog/dummy-repo.git",
44+
GitRepoName: "dummy-repo",
45+
GitProject: "jfrog",
46+
BranchName: "dev",
47+
CommitHash: "4be861f9a585d8ae5dde0b9550669972ee05c9d7",
48+
},
49+
GitProvider: "github",
4850
}
4951
)
5052

utils/xsc/analyticsmetrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func SendNewScanEvent(xrayVersion, xscVersion string, serviceDetails *config.Ser
4545
log.Debug(fmt.Sprintf("failed to create xsc manager for analytics metrics service, error: %s ", err.Error()))
4646
return
4747
}
48-
if multiScanId, err = xscService.AddAnalyticsGeneralEvent(*event); err != nil {
48+
if multiScanId, err = xscService.AddAnalyticsGeneralEvent(*event, xrayVersion); err != nil {
4949
log.Debug(fmt.Sprintf("failed sending general event request to XSC service, error: %s ", err.Error()))
5050
return
5151
}

utils/xsc/analyticsmetrics_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ func TestSendStartScanEvent(t *testing.T) {
117117
reportUsage: true,
118118
expectedMsi: "diff-msi",
119119
},
120+
{
121+
name: "Xray version with new AddGeneralEvent",
122+
mockParams: validations.MockServerParams{
123+
XrayVersion: "3.116.0",
124+
XscVersion: xscservices.AnalyticsMetricsMinXscVersion,
125+
ReturnMsi: "diff-msi",
126+
},
127+
reportUsage: true,
128+
expectedMsi: "diff-msi",
129+
},
120130
}
121131

122132
for _, testCase := range testCases {

0 commit comments

Comments
 (0)