Skip to content

Commit

Permalink
updated initXscTest verification check to match the new xsc to Xray m…
Browse files Browse the repository at this point in the history
…igration
  • Loading branch information
eranturgeman committed Dec 11, 2024
1 parent 22db4c2 commit a04d806
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 14 deletions.
55 changes: 55 additions & 0 deletions tests/testdata/configprofile/configProfileWithRepoExample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"profile_name": "default-profile-with-repo",
"repository": {
"id": "my-repo-id-123",
"name": "my-repo",
"url": "https://github.com/myUser/my-repo.git",
"provider": "github"
},
"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
}
45 changes: 33 additions & 12 deletions tests/xsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestXscVersion(t *testing.T) {
initXscTest(t, "")
initXscTest(t, "", "")
version, err := GetXscDetails().GetVersion()
if err != nil {
t.Error(err)
Expand All @@ -16,21 +16,42 @@ func TestXscVersion(t *testing.T) {
}
}

func initXscTest(t *testing.T, minVersion string) {
func initXscTest(t *testing.T, minXscVersion string, minXrayVersion string) {
if !*TestXsc {
t.Skip("Skipping xsc test. To run xsc test add the '-test.xsc=true' option.")
}
validateXscVersion(t, minVersion)
validateXscVersion(t, minXscVersion, minXrayVersion)
}
func validateXscVersion(t *testing.T, minVersion string) {
// Validate active XSC server.
version, err := GetXscDetails().GetVersion()
if err != nil {
t.Skip(err)

// This func validates minimal Xsc version.
// Since Xsc was migrated into Xray from version 3.107.13, we need to check minimal Xray version from this version forward instead of Xsc version.
// For features that are available before the migration we pass minXscVersion to check. If the utilized Xray version >= 3.107.13, the returned Xsc version will always suffice the check.
// For features that were introduced only after the migration we pass only minXrayVersion to check and can leave minXscVersion blank.
func validateXscVersion(t *testing.T, minXscVersion string, minXrayVersion string) {
if minXscVersion != "" {
// If minXscVersion is provided we assume we have a Xray version BEFORE Xsc migration to it (i.e. prior to 3.107.13)
// In this case we want to validate active Xsc server + minimal required Xsc version
currentXscVersion, err := GetXscDetails().GetVersion()
if err != nil {
t.Skip(err)
}
// Validate minimum XSC version.
err = clientUtils.ValidateMinimumVersion(clientUtils.Xsc, currentXscVersion, minXscVersion)
if err != nil {
t.Skip(err)
}
}
// Validate minimum XSC version.
err = clientUtils.ValidateMinimumVersion(clientUtils.Xsc, version, minVersion)
if err != nil {
t.Skip(err)

if minXrayVersion != "" {
// If minXrayVersion is provided we assume we have a Xray version AFTER Xsc migration to it (3.107.13+)
// In this case we want to validate minimal required Xray version only
currentXrayVersion, err := GetXrayDetails().GetVersion()
if err != nil {
t.Skip(err)
}
err = clientUtils.ValidateMinimumVersion(clientUtils.Xsc, currentXrayVersion, minXscVersion)
if err != nil {
t.Skip(err)
}
}
}
2 changes: 1 addition & 1 deletion tests/xscanalyticsevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func isValidUUID(str string) bool {

func initXscEventTest(t *testing.T) (xscDetails auth.ServiceDetails, client *jfroghttpclient.JfrogHttpClient) {
var err error
initXscTest(t, services.AnalyticsMetricsMinXscVersion)
initXscTest(t, services.AnalyticsMetricsMinXscVersion, "")
xscDetails = GetXscDetails()
client, err = jfroghttpclient.JfrogClientBuilder().
SetClientCertPath(xscDetails.GetClientCertPath()).
Expand Down
2 changes: 1 addition & 1 deletion tests/xsclogerrorevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const errorMessageContentForTest = "THIS IS NOT A REAL ERROR! This Error is posted as part of TestXscSendLogErrorEvent test"

func TestXscSendLogErrorEvent(t *testing.T) {
initXscTest(t, services.LogErrorMinXscVersion)
initXscTest(t, services.LogErrorMinXscVersion, "")
mockServer, logErrorService := createXscMockServerForLogEvent(t)
defer mockServer.Close()

Expand Down

0 comments on commit a04d806

Please sign in to comment.