Skip to content

Commit b1f61c6

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into improve_tests
2 parents fbcbf6b + 8689ef6 commit b1f61c6

File tree

5 files changed

+91
-20
lines changed

5 files changed

+91
-20
lines changed

audit_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ func TestXrayAuditJasMissingContextSimpleJson(t *testing.T) {
540540

541541
func TestXrayAuditNotEntitledForJas(t *testing.T) {
542542
integration.InitAuditGeneralTests(t, scangraph.GraphScanMinXrayVersion)
543-
cliToRun, cleanUp := integration.InitTestWithMockCommandOrParams(t, getNoJasAuditMockCommand)
543+
cliToRun, cleanUp := integration.InitTestWithMockCommandOrParams(t, false, getNoJasAuditMockCommand)
544544
defer cleanUp()
545545
output := testXrayAuditJas(t, cliToRun, filepath.Join("jas", "jas"), "3", false, false)
546546
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{Vulnerabilities: 8})
@@ -684,3 +684,31 @@ func TestAuditOnEmptyProject(t *testing.T) {
684684
// No issues should be found in an empty project
685685
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{})
686686
}
687+
688+
// xray-url only - the following tests check the case of adding "xray-url", instead of "url", which is the more common one
689+
690+
func TestXrayAuditNotEntitledForJasWithXrayUrl(t *testing.T) {
691+
cliToRun, cleanUp := integration.InitTestWithMockCommandOrParams(t, true, getNoJasAuditMockCommand)
692+
defer cleanUp()
693+
output := testXrayAuditJas(t, cliToRun, filepath.Join("jas", "jas"), "3", false, false)
694+
// Verify that scan results are printed
695+
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{Vulnerabilities: 8})
696+
// Verify that JAS results are not printed
697+
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{})
698+
}
699+
700+
func TestXrayAuditJasSimpleJsonWithXrayUrl(t *testing.T) {
701+
cliToRun := integration.GetTestCli(cli.GetJfrogCliSecurityApp(), true)
702+
output := testXrayAuditJas(t, cliToRun, filepath.Join("jas", "jas"), "3", false, false)
703+
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{
704+
Sast: 1,
705+
Iac: 9,
706+
Secrets: 6,
707+
708+
Vulnerabilities: 8,
709+
Applicable: 3,
710+
Undetermined: 1,
711+
NotCovered: 1,
712+
NotApplicable: 2,
713+
})
714+
}

jas/analyzermanager.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
ApplicabilityFeatureId = "contextual_analysis"
2626
AnalyzerManagerZipName = "analyzerManager.zip"
27-
defaultAnalyzerManagerVersion = "1.9.11"
27+
defaultAnalyzerManagerVersion = "1.11.1"
2828
analyzerManagerDownloadPath = "xsc-gen-exe-analyzer-manager-local/v1"
2929
analyzerManagerDirName = "analyzerManager"
3030
analyzerManagerExecutableName = "analyzerManager"
@@ -33,6 +33,7 @@ const (
3333
jfPasswordEnvVariable = "JF_PASS"
3434
jfTokenEnvVariable = "JF_TOKEN"
3535
jfPlatformUrlEnvVariable = "JF_PLATFORM_URL"
36+
jfPlatformXrayUrlEnvVariable = "JF_PLATFORM_XRAY_URL"
3637
logDirEnvVariable = "AM_LOG_DIRECTORY"
3738
notEntitledExitCode = 31
3839
unsupportedCommandExitCode = 13
@@ -138,10 +139,11 @@ func GetAnalyzerManagerExecutableName() string {
138139

139140
func GetAnalyzerManagerEnvVariables(serverDetails *config.ServerDetails) (envVars map[string]string, err error) {
140141
envVars = map[string]string{
141-
jfUserEnvVariable: serverDetails.User,
142-
jfPasswordEnvVariable: serverDetails.Password,
143-
jfPlatformUrlEnvVariable: serverDetails.Url,
144-
jfTokenEnvVariable: serverDetails.AccessToken,
142+
jfUserEnvVariable: serverDetails.User,
143+
jfPasswordEnvVariable: serverDetails.Password,
144+
jfPlatformUrlEnvVariable: serverDetails.Url,
145+
jfPlatformXrayUrlEnvVariable: serverDetails.XrayUrl,
146+
jfTokenEnvVariable: serverDetails.AccessToken,
145147
}
146148
if !utils.IsCI() {
147149
analyzerManagerLogFolder, err := coreutils.CreateDirInJfrogHome(filepath.Join(coreutils.JfrogLogsDirName, analyzerManagerLogDirName))

jas/common.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ func CreateJasScanner(serverDetails *config.ServerDetails, validateSecrets bool,
5454
if len(serverDetails.Url) == 0 {
5555
if len(serverDetails.XrayUrl) != 0 {
5656
log.Debug("Xray URL provided without platform URL")
57+
} else {
58+
if len(serverDetails.ArtifactoryUrl) != 0 {
59+
log.Debug("Artifactory URL provided without platform URL")
60+
}
61+
log.Warn(NoServerUrlWarn)
62+
return
5763
}
58-
if len(serverDetails.ArtifactoryUrl) != 0 {
59-
log.Debug("Artifactory URL provided without platform URL")
60-
}
61-
log.Warn(NoServerUrlWarn)
62-
return
6364
}
6465
scanner = &JasScanner{}
6566
if scanner.EnvVars, err = getJasEnvVars(serverDetails, validateSecrets, envVars); err != nil {

jas/common_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,40 @@ func TestGetJasEnvVars(t *testing.T) {
157157
"test": "testValue",
158158
},
159159
},
160+
{
161+
name: "Valid server details xray only",
162+
serverDetails: &config.ServerDetails{
163+
Url: "",
164+
XrayUrl: "url/xray",
165+
User: "user",
166+
Password: "password",
167+
AccessToken: "token",
168+
},
169+
expectedOutput: map[string]string{
170+
jfPlatformUrlEnvVariable: "",
171+
jfPlatformXrayUrlEnvVariable: "url/xray",
172+
jfUserEnvVariable: "user",
173+
jfPasswordEnvVariable: "password",
174+
jfTokenEnvVariable: "token",
175+
},
176+
},
177+
{
178+
name: "Valid server details both url and xray",
179+
serverDetails: &config.ServerDetails{
180+
Url: "url",
181+
XrayUrl: "url/xray",
182+
User: "user",
183+
Password: "password",
184+
AccessToken: "token",
185+
},
186+
expectedOutput: map[string]string{
187+
jfPlatformUrlEnvVariable: "url",
188+
jfPlatformXrayUrlEnvVariable: "url/xray",
189+
jfUserEnvVariable: "user",
190+
jfPasswordEnvVariable: "password",
191+
jfTokenEnvVariable: "token",
192+
},
193+
},
160194
}
161195
for _, test := range tests {
162196
t.Run(test.name, func(t *testing.T) {

tests/utils/integration/test_integrationutils.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func InitNativeDockerTest(t *testing.T) (mockCli *coreTests.JfrogCli, cleanUp fu
142142
if !*configTests.TestDockerScan {
143143
t.Skip(getSkipTestMsg("Docker scan command integration (Ubuntu)", "--test.dockerScan"))
144144
}
145-
return InitTestWithMockCommandOrParams(t, cli.DockerScanMockCommand)
145+
return InitTestWithMockCommandOrParams(t, false, cli.DockerScanMockCommand)
146146
}
147147

148148
func InitCurationTest(t *testing.T) {
@@ -183,19 +183,25 @@ func CreateJfrogHomeConfig(t *testing.T, encryptPassword bool) {
183183
func InitTestCliDetails(testApplication components.App) {
184184
configTests.TestApplication = &testApplication
185185
if configTests.PlatformCli == nil {
186-
configTests.PlatformCli = GetTestCli(testApplication)
186+
configTests.PlatformCli = GetTestCli(testApplication, false)
187187
}
188188
}
189189

190-
func GetTestCli(testApplication components.App) (testCli *coreTests.JfrogCli) {
191-
creds := authenticateXray()
190+
func GetTestCli(testApplication components.App, xrayUrlOnly bool) (testCli *coreTests.JfrogCli) {
191+
creds := authenticateXray(xrayUrlOnly)
192192
return coreTests.NewJfrogCli(func() error { return plugins.RunCliWithPlugin(testApplication)() }, "", creds)
193193
}
194194

195-
func authenticateXray() string {
195+
func authenticateXray(xrayUrlOnly bool) string {
196196
*configTests.JfrogUrl = clientUtils.AddTrailingSlashIfNeeded(*configTests.JfrogUrl)
197-
configTests.XrDetails = &config.ServerDetails{Url: *configTests.JfrogUrl, ArtifactoryUrl: *configTests.JfrogUrl + configTests.ArtifactoryEndpoint, XrayUrl: *configTests.JfrogUrl + configTests.XrayEndpoint}
198-
cred := fmt.Sprintf("--url=%s", configTests.XrDetails.XrayUrl)
197+
var cred string
198+
if xrayUrlOnly {
199+
configTests.XrDetails = &config.ServerDetails{XrayUrl: *configTests.JfrogUrl + configTests.XrayEndpoint}
200+
cred = fmt.Sprintf("--xray-url=%s", configTests.XrDetails.XrayUrl)
201+
} else {
202+
configTests.XrDetails = &config.ServerDetails{Url: *configTests.JfrogUrl, ArtifactoryUrl: *configTests.JfrogUrl + configTests.ArtifactoryEndpoint, XrayUrl: *configTests.JfrogUrl + configTests.XrayEndpoint}
203+
cred = fmt.Sprintf("--url=%s", configTests.XrDetails.XrayUrl)
204+
}
199205
if *configTests.JfrogAccessToken != "" {
200206
configTests.XrDetails.AccessToken = *configTests.JfrogAccessToken
201207
cred += fmt.Sprintf(" --access-token=%s", configTests.XrDetails.AccessToken)
@@ -391,7 +397,7 @@ func CreateRepos(repos map[*string]string) {
391397
}
392398
}
393399

394-
func InitTestWithMockCommandOrParams(t *testing.T, mockCommands ...func() components.Command) (mockCli *coreTests.JfrogCli, cleanUp func()) {
400+
func InitTestWithMockCommandOrParams(t *testing.T, xrayUrlCli bool, mockCommands ...func() components.Command) (mockCli *coreTests.JfrogCli, cleanUp func()) {
395401
oldHomeDir := os.Getenv(coreutils.HomeDir)
396402
// Create server config to use with the command.
397403
CreateJfrogHomeConfig(t, true)
@@ -400,7 +406,7 @@ func InitTestWithMockCommandOrParams(t *testing.T, mockCommands ...func() compon
400406
for _, mockCommand := range mockCommands {
401407
commands = append(commands, mockCommand())
402408
}
403-
return GetTestCli(components.CreateEmbeddedApp("security", commands)), func() {
409+
return GetTestCli(components.CreateEmbeddedApp("security", commands), xrayUrlCli), func() {
404410
clientTests.SetEnvAndAssert(t, coreutils.HomeDir, oldHomeDir)
405411
}
406412
}

0 commit comments

Comments
 (0)