Skip to content

Commit 2aa40b7

Browse files
committed
Merge branch 'fix/set-workspace-path-validation-15' of https://github.com/cppalliance/cppa-cursor-browser into fix/set-workspace-path-validation-15
2 parents 8284b58 + b7ba220 commit 2aa40b7

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

tests/test_workspace_path_validation.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import tempfile
1717
import unittest
18+
from pathlib import Path
1819

1920
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2021
sys.path.insert(0, REPO_ROOT)
@@ -56,7 +57,10 @@ def test_returns_canonical_path_collapsing_dotdot(self):
5657
traversal_input = os.path.join(storage, "..", os.path.basename(storage))
5758
result = validate_workspace_path(traversal_input)
5859
self.assertEqual(result, os.path.realpath(storage))
59-
self.assertNotIn("..", result)
60+
# Assert no `..` *segment* in the canonical path (vs. a substring check
61+
# on the raw string, which would spuriously fail if the OS-supplied
62+
# tempdir name ever embedded `..` in a folder name).
63+
self.assertNotIn(os.pardir, Path(result).parts)
6064

6165
# ─── Hard rejects ──────────────────────────────────────────────
6266

@@ -150,9 +154,15 @@ class TestSetWorkspaceApi(unittest.TestCase):
150154
def setUp(self):
151155
from flask import Flask
152156
from api.config_api import bp as config_bp
157+
from utils.workspace_path import set_workspace_path_override
153158

154159
self.tmp = tempfile.mkdtemp(prefix="cursor-validate-api-test-")
155160
self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True)
161+
# Reset the module-global workspace override after each test. The
162+
# 200-path test below mutates it via the API and the tempdir is then
163+
# rmtree'd by the cleanup above — without this, a future sibling test
164+
# inspecting the override would see a stale, now-deleted path.
165+
self.addCleanup(set_workspace_path_override, None)
156166

157167
app = Flask(__name__)
158168
app.config["TESTING"] = True

0 commit comments

Comments
 (0)