Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions commands/curation/curationaudit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,14 @@ func getTestCasesForDoCurationAudit() []testCase {
pathToProject: filepath.Join("projects", "package-managers", "go", "curation-project"),
createServerWithoutCreds: true,
serveResources: map[string]string{
"v1.5.2.mod": filepath.Join("resources", "quote-v1.5.2.mod"),
"v1.5.2.zip": filepath.Join("resources", "quote-v1.5.2.zip"),
"v1.5.2.info": filepath.Join("resources", "quote-v1.5.2.info"),
"v1.3.0.mod": filepath.Join("resources", "sampler-v1.3.0.mod"),
"v1.3.0.zip": filepath.Join("resources", "sampler-v1.3.0.zip"),
"v1.3.0.info": filepath.Join("resources", "sampler-v1.3.0.info"),
"v0.0.0-20170915032832-14c0d48ead0c.mod": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.mod"),
"v0.0.0-20170915032832-14c0d48ead0c.zip": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.zip"),
"v1.5.2.mod": filepath.Join("resources", "quote-v1.5.2.mod"),
"v1.5.2.zip": filepath.Join("resources", "quote-v1.5.2.zip"),
"v1.5.2.info": filepath.Join("resources", "quote-v1.5.2.info"),
"v1.3.0.mod": filepath.Join("resources", "sampler-v1.3.0.mod"),
"v1.3.0.zip": filepath.Join("resources", "sampler-v1.3.0.zip"),
"v1.3.0.info": filepath.Join("resources", "sampler-v1.3.0.info"),
"v0.0.0-20170915032832-14c0d48ead0c.mod": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.mod"),
"v0.0.0-20170915032832-14c0d48ead0c.zip": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.zip"),
"v0.0.0-20170915032832-14c0d48ead0c.info": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.info"),
},
// example.com/localmod is a tripwire, not an expected call: it's local-replaced and must never
Expand Down
1 change: 1 addition & 0 deletions commands/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func (scanCmd *ScanCommand) prepareForScan(cmdResults *results.SecurityCommandRe
indexer.WithXray(xrayManager, scanCmd.xrayVersion),
indexer.WithBypassArchiveLimits(scanCmd.bypassArchiveLimits),
indexer.WithServerDetails(scanCmd.serverDetails),
indexer.WithProjectKey(scanCmd.resultsContext.ProjectKey),
).PrepareGenerator()
})
} else {
Expand Down
15 changes: 14 additions & 1 deletion sca/bom/indexer/indexerbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ const (
// #nosec G101 -- Not credentials.
XrayPasswordEnvVariable = "JFROG_XRAY_PASSWORD"
// #nosec G101 -- Not credentials.
XrayTokenEnvVariable = "JFROG_XRAY_TOKEN"
XrayTokenEnvVariable = "JFROG_XRAY_TOKEN"
XrayProjectKeyEnvVariable = "JFROG_XRAY_PROJECT_KEY"
)

// IndexerBomGenerator is a BomGenerator that uses the Xray Indexer to generate a CycloneDX SBOM.
// It indexes a file and converts the resulting component graph to a CycloneDX SBOM.
type IndexerBomGenerator struct {
bypassArchiveLimits bool
serverDetails *config.ServerDetails
projectKey string

xrayManager *xray.XrayServicesManager
xrayVersion string
Expand Down Expand Up @@ -77,6 +79,14 @@ func WithServerDetails(serverDetails *config.ServerDetails) bom.SbomGeneratorOpt
}
}

func WithProjectKey(projectKey string) bom.SbomGeneratorOption {
return func(sg bom.SbomGenerator) {
if ibg, ok := sg.(*IndexerBomGenerator); ok {
ibg.projectKey = projectKey
}
}
}

func (ibg *IndexerBomGenerator) WithOptions(options ...bom.SbomGeneratorOption) bom.SbomGenerator {
for _, option := range options {
option(ibg)
Expand Down Expand Up @@ -145,6 +155,9 @@ func (ibg *IndexerBomGenerator) getIndexerEnvVars() utils.EnvironmentVariables {
platformEnv[XrayPasswordEnvVariable] = ibg.serverDetails.Password
}
}
if ibg.projectKey != "" {
platformEnv[XrayProjectKeyEnvVariable] = ibg.projectKey
}
if len(platformEnv) == 0 {
return nil
}
Expand Down
35 changes: 29 additions & 6 deletions sca/bom/indexer/indexerbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ func TestGetIndexerEnvVars(t *testing.T) {
tests := []struct {
name string
serverDetails *config.ServerDetails
projectKey string
wantKeys map[string]string
wantAbsent []string
}{
{
name: "nil server details",
serverDetails: nil,
wantAbsent: []string{XrayUrlEnvVariable, XrayUserEnvVariable, XrayPasswordEnvVariable, XrayTokenEnvVariable},
wantAbsent: []string{XrayUrlEnvVariable, XrayUserEnvVariable, XrayPasswordEnvVariable, XrayTokenEnvVariable, XrayProjectKeyEnvVariable},
},
{
name: "access token preferred",
Expand All @@ -32,7 +33,7 @@ func TestGetIndexerEnvVars(t *testing.T) {
XrayUrlEnvVariable: "https://xray.example/",
XrayTokenEnvVariable: "tok",
},
wantAbsent: []string{XrayUserEnvVariable, XrayPasswordEnvVariable},
wantAbsent: []string{XrayUserEnvVariable, XrayPasswordEnvVariable, XrayProjectKeyEnvVariable},
},
{
name: "user and password",
Expand All @@ -46,13 +47,35 @@ func TestGetIndexerEnvVars(t *testing.T) {
XrayUserEnvVariable: "u",
XrayPasswordEnvVariable: "p",
},
wantAbsent: []string{XrayTokenEnvVariable},
wantAbsent: []string{XrayTokenEnvVariable, XrayProjectKeyEnvVariable},
},
{
name: "project key with access token",
serverDetails: &config.ServerDetails{
XrayUrl: "https://xray.example/",
AccessToken: "tok",
},
projectKey: "my-project",
wantKeys: map[string]string{
XrayUrlEnvVariable: "https://xray.example/",
XrayTokenEnvVariable: "tok",
XrayProjectKeyEnvVariable: "my-project",
},
wantAbsent: []string{XrayUserEnvVariable, XrayPasswordEnvVariable},
},
{
name: "project key without server details",
projectKey: "my-project",
wantKeys: map[string]string{
XrayProjectKeyEnvVariable: "my-project",
},
wantAbsent: []string{XrayUrlEnvVariable, XrayUserEnvVariable, XrayPasswordEnvVariable, XrayTokenEnvVariable},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ibg := &IndexerBomGenerator{serverDetails: tt.serverDetails}
ibg := &IndexerBomGenerator{serverDetails: tt.serverDetails, projectKey: tt.projectKey}
env := ibg.getIndexerEnvVars()
for k, v := range tt.wantKeys {
assert.Equal(t, v, env[k], "key %s", k)
Expand All @@ -61,8 +84,8 @@ func TestGetIndexerEnvVars(t *testing.T) {
_, ok := env[k]
assert.False(t, ok, "key %s should be absent", k)
}
// When server details are set, env must include process env (PATH at minimum).
if tt.serverDetails != nil {
// When platform env is set, env must include process env (PATH at minimum).
if tt.serverDetails != nil || tt.projectKey != "" {
require.NotEmpty(t, env["PATH"])
}
})
Expand Down
2 changes: 1 addition & 1 deletion scans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestXrayBinaryScanSelectiveScan(t *testing.T) {
validate: func(t *testing.T, issueCount validations.ValidationCountActualValues) {
// Expect SCA vulnerabilities and contextual analysis statuses
assert.GreaterOrEqual(t, issueCount.ScaVulnerabilities, 17, "SCA vulnerabilities count mismatch - should be 17 or more")
assert.Equal(t, 3, issueCount.ApplicableVulnerabilities, "Applicable vulnerabilities count mismatch - should be 3")
assert.Equal(t, 4, issueCount.ApplicableVulnerabilities, "Applicable vulnerabilities count mismatch - should be 4")
assert.Equal(t, 4, issueCount.UndeterminedVulnerabilities, "Undetermined vulnerabilities count mismatch - should be 4")
// All other vulnerability types should be 0
assert.Equal(t, 0, issueCount.SecretsVulnerabilities, "Secrets vulnerabilities count mismatch - should be 0")
Expand Down
Loading