Skip to content

Commit 0f38067

Browse files
Tests: more $request_uri variable tests
1 parent e75f8d5 commit 0f38067

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

test/test_python_application.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from packaging import version
1111

1212
from unit.applications.lang.python import ApplicationPython
13+
from unit.option import option
1314

1415
prerequisites = {'modules': {'python': 'all'}}
1516

@@ -64,6 +65,45 @@ def test_python_application_variables(date_to_sec_epoch, sec_epoch):
6465
}, 'headers'
6566
assert resp['body'] == body, 'body'
6667

68+
# REQUEST_URI unchanged
69+
70+
path = f'{option.test_dir}/python/variables'
71+
assert 'success' in client.conf(
72+
{
73+
"listeners": {"*:8080": {"pass": "routes"}},
74+
"routes": [
75+
{
76+
"action": {
77+
"rewrite": "/foo",
78+
"pass": "applications/variables",
79+
}
80+
}
81+
],
82+
"applications": {
83+
"variables": {
84+
"type": client.get_application_type(),
85+
"processes": {'spare': 0},
86+
"path": path,
87+
"working_directory": path,
88+
"module": "wsgi",
89+
}
90+
},
91+
}
92+
)
93+
94+
resp = client.http(
95+
f"""POST /bar HTTP/1.1
96+
Host: localhost
97+
Content-Length: 1
98+
Custom-Header: blah
99+
Content-Type: text/html
100+
Connection: close
101+
102+
a""".encode(),
103+
raw=True,
104+
)
105+
assert resp['headers']['Request-Uri'] == '/bar', 'REQUEST_URI unchanged'
106+
67107

68108
def test_python_application_query_string():
69109
client.load('query_string')

test/test_variables.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_variables_method(search_in_file, wait_for_record):
9393
assert wait_for_record(reg, 'access.log') is not None, 'method POST'
9494

9595

96-
def test_variables_request_uri(search_in_file, wait_for_record):
96+
def test_variables_request_uri(search_in_file, temp_dir, wait_for_record):
9797
set_format('$request_uri')
9898

9999
def check_request_uri(req_uri):
@@ -108,6 +108,48 @@ def check_request_uri(req_uri):
108108
check_request_uri('/4%2A')
109109
check_request_uri('/9?q#a')
110110

111+
# $request_uri should not be changed by rewrite
112+
113+
assert 'success' in client.conf(
114+
{
115+
"listeners": {
116+
"*:8080": {"pass": "routes/a"},
117+
"*:8081": {"pass": "routes/b"},
118+
},
119+
"routes": {
120+
"a": [
121+
{
122+
"action": {
123+
"rewrite": "/foo",
124+
"proxy": "http://127.0.0.1:8081",
125+
}
126+
}
127+
],
128+
"b": [
129+
{
130+
"action": {
131+
"rewrite": "/bar",
132+
"return": 200,
133+
}
134+
}
135+
],
136+
},
137+
"access_log": {
138+
"path": f'{temp_dir}/access.log',
139+
"format": "$uri $request_uri",
140+
},
141+
}
142+
)
143+
144+
assert search_in_file(r'/foo', 'access.log') is None
145+
146+
assert client.get()['status'] == 200
147+
148+
assert wait_for_record(fr'^/foo /$', 'access.log') is not None, 'req 8080'
149+
assert (
150+
search_in_file(fr'^/bar /foo$', 'access.log') is not None
151+
), 'req 8081 (proxy)'
152+
111153

112154
def test_variables_uri(search_in_file, wait_for_record):
113155
set_format('$uri')

0 commit comments

Comments
 (0)