|
15 | 15 | import sys |
16 | 16 | import tempfile |
17 | 17 | import unittest |
| 18 | +from pathlib import Path |
18 | 19 |
|
19 | 20 | REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
20 | 21 | sys.path.insert(0, REPO_ROOT) |
@@ -56,7 +57,10 @@ def test_returns_canonical_path_collapsing_dotdot(self): |
56 | 57 | traversal_input = os.path.join(storage, "..", os.path.basename(storage)) |
57 | 58 | result = validate_workspace_path(traversal_input) |
58 | 59 | 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) |
60 | 64 |
|
61 | 65 | # ─── Hard rejects ────────────────────────────────────────────── |
62 | 66 |
|
@@ -150,9 +154,15 @@ class TestSetWorkspaceApi(unittest.TestCase): |
150 | 154 | def setUp(self): |
151 | 155 | from flask import Flask |
152 | 156 | from api.config_api import bp as config_bp |
| 157 | + from utils.workspace_path import set_workspace_path_override |
153 | 158 |
|
154 | 159 | self.tmp = tempfile.mkdtemp(prefix="cursor-validate-api-test-") |
155 | 160 | 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) |
156 | 166 |
|
157 | 167 | app = Flask(__name__) |
158 | 168 | app.config["TESTING"] = True |
|
0 commit comments