|
1 | 1 | from socket_basics.core.config import ( |
2 | 2 | Config, |
| 3 | + normalize_repo_relative_path, |
3 | 4 | parse_sast_ignore_overrides, |
4 | 5 | ) |
5 | 6 | from socket_basics.core.connector.normalizer import _normalize_alert |
@@ -76,6 +77,47 @@ def test_normalize_alert_accepts_windows_style_override_paths(): |
76 | 77 | assert alert['action'] == 'ignore' |
77 | 78 |
|
78 | 79 |
|
| 80 | +def test_normalize_repo_relative_path_strips_github_actions_workspace_prefix(monkeypatch): |
| 81 | + monkeypatch.setenv('GITHUB_WORKSPACE', '/github/workspace') |
| 82 | + |
| 83 | + assert normalize_repo_relative_path('github/workspace/index.js') == 'index.js' |
| 84 | + |
| 85 | + |
| 86 | +def test_normalize_repo_relative_path_strips_gitlab_workspace_prefix(monkeypatch): |
| 87 | + monkeypatch.setenv('CI_PROJECT_DIR', '/builds/acme/sample-repo') |
| 88 | + |
| 89 | + assert normalize_repo_relative_path('/builds/acme/sample-repo/src/index.js') == 'src/index.js' |
| 90 | + |
| 91 | + |
| 92 | +def test_normalize_repo_relative_path_strips_bitbucket_workspace_prefix(monkeypatch): |
| 93 | + monkeypatch.setenv('BITBUCKET_CLONE_DIR', '/opt/atlassian/pipelines/agent/build') |
| 94 | + |
| 95 | + assert normalize_repo_relative_path('/opt/atlassian/pipelines/agent/build/index.js') == 'index.js' |
| 96 | + |
| 97 | + |
| 98 | +def test_normalize_repo_relative_path_strips_buildkite_workspace_prefix(monkeypatch): |
| 99 | + monkeypatch.setenv('BUILDKITE_BUILD_CHECKOUT_PATH', '/var/lib/buildkite-agent/builds/agent-1/org/repo') |
| 100 | + |
| 101 | + assert normalize_repo_relative_path( |
| 102 | + '/var/lib/buildkite-agent/builds/agent-1/org/repo/app/index.js' |
| 103 | + ) == 'app/index.js' |
| 104 | + |
| 105 | + |
| 106 | +def test_normalize_alert_strips_github_actions_workspace_prefix(monkeypatch): |
| 107 | + monkeypatch.setenv('GITHUB_WORKSPACE', '/github/workspace') |
| 108 | + |
| 109 | + connector = _DummyConnector( |
| 110 | + Config({'workspace': '.', 'sast_ignore_overrides': 'js-sql-injection:index.js'}) |
| 111 | + ) |
| 112 | + |
| 113 | + alert = _normalize_alert( |
| 114 | + _build_alert('github/workspace/index.js'), |
| 115 | + connector=connector, |
| 116 | + ) |
| 117 | + |
| 118 | + assert alert['action'] == 'ignore' |
| 119 | + |
| 120 | + |
79 | 121 | def test_normalize_alert_does_not_ignore_non_matching_path_override(): |
80 | 122 | connector = _DummyConnector( |
81 | 123 | Config({'workspace': '.', 'sast_ignore_overrides': 'js-sql-injection:src/index.js'}) |
|
0 commit comments