Skip to content

Commit 35da413

Browse files
Chris WesselingChris Wesseling
authored andcommitted
Fixes passing absolute paths to http methods
When session.root wasn't a site_root ie https://example.com/Plone instead of https://example.com/. then calls like sessiopn.get('/@System') would throw an Exception
1 parent 4796313 commit 35da413

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ repos:
1818
rev: v0.13.0
1919
hooks:
2020
- id: reuse
21+
- repo: https://github.com/pycqa/isort
22+
rev: 5.9.3
23+
hooks:
24+
- id: isort
25+
name: isort (python)
26+
types: [python]
27+
- id: isort
28+
name: isort (cython)
29+
types: [cython]
30+
- id: isort
31+
name: isort (pyi)
32+
types: [pyi]
2133
- repo: local
2234
hooks:
2335
- id: pytest-cov

affen/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def request(
8080
*args,
8181
**kwargs,
8282
) -> requests.Response:
83-
url = urljoin(self.root, url)
83+
url = urljoin(self.root, url.lstrip("/"))
8484
if not url.startswith(self.root):
8585
raise ValueError(
8686
f"Making requests to other hosts than {self.root} may leak credentials. "

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ exclude_lines = [
3939
"if TYPE_CHECKING:",
4040
]
4141

42+
[tool.isort]
43+
profile = "black"
44+
4245
[tool.pdm]
4346
[tool.pdm.dev-dependencies]
4447
dev = [
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# SPDX-FileCopyrightText: 2021 Centrum Wiskune en Informatica
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
interactions:
6+
- request:
7+
body: null
8+
headers:
9+
Accept-Encoding:
10+
- gzip, deflate
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- python-requests/2.26.0
15+
accept:
16+
- application/json
17+
method: GET
18+
uri: http://127.0.0.1:8080/Plone/@search
19+
response:
20+
body:
21+
string: "{\n \"@id\": \"http://127.0.0.1:8080/Plone/@search\", \n \"items\":
22+
[\n {\n \"@id\": \"http://127.0.0.1:8080/Plone/front-page\", \n \"@type\":
23+
\"Document\", \n \"description\": \"Congratulations! You have successfully
24+
installed Plone.\", \n \"review_state\": \"published\", \n \"title\":
25+
\"Welcome to Plone\"\n }, \n {\n \"@id\": \"http://127.0.0.1:8080/Plone/news\",
26+
\n \"@type\": \"Folder\", \n \"description\": \"Site News\", \n
27+
\ \"review_state\": \"published\", \n \"title\": \"News\"\n },
28+
\n {\n \"@id\": \"http://127.0.0.1:8080/Plone/news/aggregator\", \n
29+
\ \"@type\": \"Collection\", \n \"description\": \"Site News\", \n
30+
\ \"review_state\": \"published\", \n \"title\": \"News\"\n },
31+
\n {\n \"@id\": \"http://127.0.0.1:8080/Plone/events\", \n \"@type\":
32+
\"Folder\", \n \"description\": \"Site Events\", \n \"review_state\":
33+
\"published\", \n \"title\": \"Events\"\n }, \n {\n \"@id\":
34+
\"http://127.0.0.1:8080/Plone/events/aggregator\", \n \"@type\": \"Collection\",
35+
\n \"description\": \"Site Events\", \n \"review_state\": \"published\",
36+
\n \"title\": \"Events\"\n }, \n {\n \"@id\": \"http://127.0.0.1:8080/Plone/Members\",
37+
\n \"@type\": \"Folder\", \n \"description\": \"Site Users\", \n
38+
\ \"review_state\": \"private\", \n \"title\": \"Users\"\n }\n
39+
\ ], \n \"items_total\": 6\n}"
40+
headers:
41+
Content-Length:
42+
- '1297'
43+
Content-Type:
44+
- application/json
45+
Date:
46+
- Sat, 31 Jul 2021 02:27:04 GMT
47+
Server:
48+
- waitress
49+
Via:
50+
- waitress
51+
X-Frame-Options:
52+
- SAMEORIGIN
53+
X-Powered-By:
54+
- Zope (www.zope.org), Python (www.python.org)
55+
status:
56+
code: 200
57+
message: OK
58+
version: 1

tests/test_session.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ def test_does_not_leak_authentication(plone):
121121
assert "http://127.0.0.1:8080/Plone" in str(info.value)
122122

123123

124+
@pytest.mark.vcr
125+
def test_accepts_absolute_paths_even_if_api_root_is_not_at_host_root(plone):
126+
assert plone.get("/@search").ok
127+
128+
124129
@pytest.fixture(scope="module")
125130
def vcr_config():
126131
return {

0 commit comments

Comments
 (0)