Commit a63297f
committed
fix: harden /api/set-workspace handler + traversal test (CodeRabbit on PR #16)
Two CodeRabbit follow-ups:
1. api/config_api.py:set_workspace — when get_json(silent=True) returned
a non-dict (JSON array, string, number, null), the truthy fallback
`or {}` was bypassed and `body.get("path", "")` raised AttributeError,
which the outer Exception handler mis-reported as a 500 server error.
Added isinstance(body, dict) guard that returns
400 { error: "request body must be a JSON object" } directly. Diverged
from CodeRabbit's literal patch in one way: they had it raise
WorkspacePathError("path is required"), but the actual problem here is
a malformed body shape — the error message should match the cause so
the client can fix it.
2. tests/test_workspace_path_validation.py — the traversal test escaped
to /tmp itself, which is shared and could be flipped by any other
test / process creating <something>/state.vscdb there. Pinned the
escape target to an isolated root inside self.tmp.
Also added 4 API-layer regression tests (TestSetWorkspaceApi) using
Flask test_client: JSON array / string / number return 400 (not 500),
plus a sanity end-to-end with a valid {path} body returning 200 and the
canonical realpath.
Full suite: 152/152 OK (was 148; +4 new API tests).1 parent 75468a2 commit a63297f
2 files changed
Lines changed: 78 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
80 | 87 | | |
81 | 88 | | |
82 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
104 | 112 | | |
105 | 113 | | |
106 | 114 | | |
| |||
129 | 137 | | |
130 | 138 | | |
131 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
132 | 200 | | |
133 | 201 | | |
0 commit comments