Skip to content

Commit 73fa3e6

Browse files
committed
chore: add tests for GHA and common CI checkout path routes
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent 413174b commit 73fa3e6

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/test_sast_ignore_overrides.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from socket_basics.core.config import (
22
Config,
3+
normalize_repo_relative_path,
34
parse_sast_ignore_overrides,
45
)
56
from socket_basics.core.connector.normalizer import _normalize_alert
@@ -76,6 +77,47 @@ def test_normalize_alert_accepts_windows_style_override_paths():
7677
assert alert['action'] == 'ignore'
7778

7879

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+
79121
def test_normalize_alert_does_not_ignore_non_matching_path_override():
80122
connector = _DummyConnector(
81123
Config({'workspace': '.', 'sast_ignore_overrides': 'js-sql-injection:src/index.js'})

0 commit comments

Comments
 (0)