diff --git a/testdata/configprofile/configProfileWithRepoExample.json b/testdata/configprofile/configProfileWithRepoExample.json new file mode 100644 index 000000000..250b7add0 --- /dev/null +++ b/testdata/configprofile/configProfileWithRepoExample.json @@ -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": "my-user@jfrog.com", + "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 +} \ No newline at end of file diff --git a/utils/params_test.go b/utils/params_test.go index fdb58b1d3..c3b1ffaa9 100644 --- a/utils/params_test.go +++ b/utils/params_test.go @@ -23,6 +23,7 @@ var ( configParamsTestFile = filepath.Join("..", "testdata", "config", "frogbot-config-test-params.yml") configEmptyScanParamsTestFile = filepath.Join("..", "testdata", "config", "frogbot-config-empty-scan.yml") configProfileFile = filepath.Join("..", "testdata", "configprofile", "configProfileExample.json") + configProfileWithRepoFile = filepath.Join("..", "testdata", "configprofile", "configProfileWithRepoExample.json") ) func TestExtractParamsFromEnvError(t *testing.T) { @@ -700,6 +701,7 @@ func TestGetConfigProfileIfExistsAndValid(t *testing.T) { profileName string xrayVersion string failureExpected bool + profileWithRepo bool }{ { name: "Deprecated Server - Valid ConfigProfile", @@ -740,6 +742,7 @@ func TestGetConfigProfileIfExistsAndValid(t *testing.T) { profileName: "", xrayVersion: services.ConfigProfileByUrlMinXrayVersion, failureExpected: false, + profileWithRepo: true, }, { name: "Profile by Name - Non existing profile name", @@ -766,24 +769,30 @@ func TestGetConfigProfileIfExistsAndValid(t *testing.T) { defer mockServer.Close() configProfile, err := getConfigProfileIfExistsAndValid(testcase.xrayVersion, services.ConfigProfileMinXscVersion, serverDetails) - if testcase.useProfile { - if testcase.failureExpected { - assert.Error(t, err) - } else { - require.NotNil(t, configProfile) - assert.NoError(t, err) - var configProfileContentForComparison []byte - configProfileContentForComparison, err = os.ReadFile(configProfileFile) - assert.NoError(t, err) - var configProfileFromFile services.ConfigProfile - err = json.Unmarshal(configProfileContentForComparison, &configProfileFromFile) - assert.NoError(t, err) - assert.Equal(t, configProfileFromFile, *configProfile) - } - } else { + + if !testcase.useProfile { assert.Nil(t, configProfile) assert.Nil(t, err) + return + } + if testcase.failureExpected { + assert.Error(t, err) + return + } + + require.NotNil(t, configProfile) + assert.NoError(t, err) + var configProfileContentForComparison []byte + if testcase.profileWithRepo { + configProfileContentForComparison, err = os.ReadFile(configProfileWithRepoFile) + } else { + configProfileContentForComparison, err = os.ReadFile(configProfileFile) } + assert.NoError(t, err) + var configProfileFromFile services.ConfigProfile + err = json.Unmarshal(configProfileContentForComparison, &configProfileFromFile) + assert.NoError(t, err) + assert.Equal(t, configProfileFromFile, *configProfile) }) } } diff --git a/utils/testsutils.go b/utils/testsutils.go index ebb209dfb..7a2033d94 100644 --- a/utils/testsutils.go +++ b/utils/testsutils.go @@ -211,7 +211,7 @@ func CreateXscMockServerForConfigProfile(t *testing.T, xrayVersion string) (mock // Endpoint to profile by URL case strings.Contains(r.RequestURI, "/xsc/profile_repos") && isXrayAfterXscMigration: assert.Equal(t, http.MethodPost, r.Method) - content, err := os.ReadFile("../testdata/configprofile/configProfileExample.json") + content, err := os.ReadFile("../testdata/configprofile/configProfileWithRepoExample.json") assert.NoError(t, err) w.WriteHeader(http.StatusOK) _, err = w.Write(content)