Skip to content

Commit 4b6168f

Browse files
committed
Verify new behavior of JS challenge tests
Now Tempesta FW sends JS challenge to a client only if request beign matched by http chain "jsch" rule and this is GET request.
1 parent 0bb2759 commit 4b6168f

2 files changed

Lines changed: 63 additions & 12 deletions

File tree

sessions/test_js_challenge.py

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ class JSChallenge(BaseJSChallenge):
158158
tempesta = {
159159
"config": f"""
160160
server ${{server_ip}}:8000;
161-
161+
162162
listen 80;
163163
listen 443 proto=h2;
164-
164+
165165
tls_certificate ${{tempesta_workdir}}/tempesta.crt;
166166
tls_certificate_key ${{tempesta_workdir}}/tempesta.key;
167167
tls_match_any_server_name;
@@ -170,18 +170,32 @@ class JSChallenge(BaseJSChallenge):
170170
http_method_override_allowed true;
171171
http_strict_host_checking false;
172172
}}
173-
173+
174+
vhost tempesta-tech.com {{
175+
sticky {{
176+
cookie enforce name=cname max_misses={MAX_MISSES};
177+
js_challenge resp_code=503 delay_min={DELAY_MIN} delay_range={DELAY_RANGE}
178+
${{tempesta_workdir}}/js1.html;
179+
}}
180+
proxy_pass default;
181+
}}
182+
183+
vhost dev.tempesta-tech.com {{
184+
proxy_pass default;
185+
}}
186+
174187
block_action attack reply;
175188
block_action error reply;
176189
177190
cache 2;
178191
cache_methods GET HEAD POST;
179192
cache_fulfill * *;
180-
181-
sticky {{
182-
cookie enforce name=cname max_misses={MAX_MISSES};
183-
js_challenge resp_code=503 delay_min={DELAY_MIN} delay_range={DELAY_RANGE}
184-
${{tempesta_workdir}}/js1.html;
193+
194+
http_chain {{
195+
hdr accept == "text/html" -> jsch;
196+
hdr accept == "text/\*" -> jsch;
197+
host == "dev.tempesta-tech.com" -> dev.tempesta-tech.com;
198+
-> tempesta-tech.com;
185199
}}
186200
"""
187201
}
@@ -217,7 +231,7 @@ def _test_first_request(self, client, request, method, accept, status, conn_is_c
217231
marks.Param(name="GET_and_accept_html", method="GET", accept="text/html", status="503"),
218232
marks.Param(name="GET_and_accept_all", method="GET", accept="*/*", status="403"),
219233
marks.Param(
220-
name="GET_and_accept_text_all", method="GET", accept="text/*", status="403"
234+
name="GET_and_accept_text_all", method="GET", accept="text/*", status="503"
221235
),
222236
marks.Param(name="GET_and_accept_image", method="GET", accept="image/*", status="403"),
223237
marks.Param(
@@ -229,9 +243,7 @@ def _test_first_request(self, client, request, method, accept, status, conn_is_c
229243
def test_first_request(self, name, method, accept, status):
230244
"""
231245
Not all requests are challengeable. Tempesta sends the challenge
232-
only if the client can accept it, i.e. request should has GET method and
233-
'Accept: text/html'. In other cases normal browsers don't eval
234-
JS code and TempestaFW is not trying to send the challenge to bots.
246+
only if the request matches http chain "jsch" rule.
235247
"""
236248
self.start_all_services()
237249

@@ -624,6 +636,24 @@ def test_method_override_with_cache(self, name, method, override, status):
624636
status,
625637
)
626638

639+
def test_vhost_no_jsch_configured(self):
640+
"""
641+
Verify that vhost with non-configured "sticky" module doesn't send JS challenge
642+
even if it matches http_chain "jsch" rule.
643+
"""
644+
self.start_all_services()
645+
646+
client = self.get_client("client-1")
647+
request = client.create_request(
648+
method="GET", authority="dev.tempesta-tech.com", headers=[("accept", "text/html")]
649+
)
650+
client.send_request(request, "200")
651+
resp = client.last_response
652+
self.assertIsNone(
653+
resp.headers.get("Set-Cookie", None),
654+
"Tempesta added a Set-Cookie header, but js challange is not configured for vhost.",
655+
)
656+
627657

628658
@marks.parameterize_class(
629659
[
@@ -657,6 +687,9 @@ class JSChallengeCookieExpiresAndMethodOverride(BaseJSChallenge):
657687
tls_certificate ${{tempesta_workdir}}/tempesta.crt;
658688
tls_certificate_key ${{tempesta_workdir}}/tempesta.key;
659689
tls_match_any_server_name;
690+
frang_limits {{
691+
http_strict_host_checking false;
692+
}}
660693
661694
block_action attack reply;
662695
block_action error reply;
@@ -670,6 +703,15 @@ class JSChallengeCookieExpiresAndMethodOverride(BaseJSChallenge):
670703
${{tempesta_workdir}}/js1.html;
671704
sess_lifetime 3;
672705
}}
706+
707+
vhost tempesta {{
708+
proxy_pass default;
709+
}}
710+
711+
http_chain {{
712+
hdr accept == "text/html" -> jsch;
713+
-> tempesta;
714+
}}
673715
"""
674716
}
675717

t_fault_injection/test_fault_injection_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,15 @@ def test_tfw_h2_prep_resp_for_sticky_ccokie(self):
410410
cookie enforce name=cname max_misses=5;
411411
js_challenge resp_code=503 delay_min=1 delay_range=3 %s/js1.html;
412412
}
413+
414+
vhost default {
415+
proxy_pass default;
416+
}
417+
418+
http_chain {
419+
hdr accept == "text/html" -> jsch;
420+
-> default;
421+
}
413422
"""
414423
% workdir
415424
)

0 commit comments

Comments
 (0)