22
33from utils import interfaces , bug , scenarios , weblog , rfc , missing_feature , flaky , features
44from utils ._context .core import context
5- from .test_blocking_block_id import is_valid_uuid4 , extract_block_id_from_json , extract_block_id_from_html
5+ from .test_blocking_security_response_id import (
6+ is_valid_uuid4 ,
7+ extract_security_response_id_from_json ,
8+ extract_security_response_id_from_html ,
9+ )
610
711
812BLOCK_TEMPLATE_JSON_MIN_V1 = "blocked.v1.min.json"
@@ -17,35 +21,35 @@ def _read_file(file_path: str) -> str:
1721
1822
1923def _is_valid_json_v3_template (body : str ) -> bool :
20- """Check if body matches v3 JSON template with valid dynamic block_id
24+ """Check if body matches v3 JSON template with valid dynamic security_response_id
2125
22- RFC-1070: Uses the actual block_id from the response for validation
26+ RFC-1070: Uses the actual security_response_id from the response for validation
2327 """
24- # Extract and validate block_id from actual response
25- block_id = extract_block_id_from_json (body )
26- if block_id is None or not is_valid_uuid4 (block_id ):
28+ # Extract and validate security_response_id from actual response
29+ security_response_id = extract_security_response_id_from_json (body )
30+ if security_response_id is None or not is_valid_uuid4 (security_response_id ):
2731 return False
2832
29- # Build expected response by injecting the actual block_id into the template
33+ # Build expected response by injecting the actual security_response_id into the template
3034 v3_template = _read_file (BLOCK_TEMPLATE_JSON_MIN_V3 ).rstrip ()
31- expected_response = v3_template .replace ("00000000-0000-4000-8000-000000000000" , block_id )
35+ expected_response = v3_template .replace ("00000000-0000-4000-8000-000000000000" , security_response_id )
3236
3337 return body .rstrip () == expected_response
3438
3539
3640def _is_valid_html_v3_template (body : str ) -> bool :
37- """Check if body matches v3 HTML template with valid dynamic block_id
41+ """Check if body matches v3 HTML template with valid dynamic security_response_id
3842
39- RFC-1070: Uses the actual block_id from the response for validation
43+ RFC-1070: Uses the actual security_response_id from the response for validation
4044 """
41- # Extract and validate block_id from actual response
42- block_id = extract_block_id_from_html (body )
43- if block_id is None or not is_valid_uuid4 (block_id ):
45+ # Extract and validate security_response_id from actual response
46+ security_response_id = extract_security_response_id_from_html (body )
47+ if security_response_id is None or not is_valid_uuid4 (security_response_id ):
4448 return False
4549
46- # Build expected response by injecting the actual block_id into the template
50+ # Build expected response by injecting the actual security_response_id into the template
4751 v3_template = _read_file (BLOCK_TEMPLATE_HTML_MIN_V3 ).rstrip ()
48- expected_response = v3_template .replace ("00000000-0000-4000-8000-000000000000" , block_id )
52+ expected_response = v3_template .replace ("00000000-0000-4000-8000-000000000000" , security_response_id )
4953
5054 return body .rstrip () == expected_response
5155
@@ -61,7 +65,7 @@ def assert_valid_html_blocked_template(body: str) -> None:
6165 _read_file (BLOCK_TEMPLATE_HTML_MIN_V2 ),
6266 }
6367
64- # Check for v3 template with dynamic block_id
68+ # Check for v3 template with dynamic security_response_id
6569 assert body in valid_templates or _is_valid_html_v3_template (body )
6670
6771
@@ -77,7 +81,7 @@ def assert_valid_json_blocked_template(body: str) -> None:
7781 _read_file (BLOCK_TEMPLATE_JSON_MIN_V1 ).rstrip (),
7882 }
7983
80- # Check for v3 template with dynamic block_id
84+ # Check for v3 template with dynamic security_response_id
8185 assert body in valid_templates or _is_valid_json_v3_template (body )
8286
8387
@@ -222,19 +226,19 @@ def setup_json_template_v1(self):
222226 @missing_feature (context .library < "python@2.11.0.dev" )
223227 @missing_feature (library = "ruby" )
224228 def test_json_template_v1 (self ):
225- """JSON block template is v1 minified (or v3 with block_id )"""
229+ """JSON block template is v1 minified (or v3 with security_response_id )"""
226230 assert self .r_json_v1 .status_code == 403
227231 assert self .r_json_v1 .headers .get ("content-type" , "" ).lower () in JSON_CONTENT_TYPES
228232
229- # Accept v1 template without block_id or v3 template with block_id
233+ # Accept v1 template without security_response_id or v3 template with security_response_id
230234 response_text = self .r_json_v1 .text .rstrip ()
231235 v1_template = _read_file (BLOCK_TEMPLATE_JSON_MIN_V1 ).rstrip ()
232236
233237 # Check if it's v1 template
234238 if response_text == v1_template :
235239 return
236240
237- # Check if it's v3 template with valid block_id
241+ # Check if it's v3 template with valid security_response_id
238242 assert _is_valid_json_v3_template (self .r_json_v1 .text ), "Response doesn't match v1 or v3 template"
239243
240244 def setup_html_template_v2 (self ):
@@ -247,19 +251,19 @@ def setup_html_template_v2(self):
247251 @missing_feature (context .library < "python@2.11.0.dev" )
248252 @missing_feature (library = "ruby" )
249253 def test_html_template_v2 (self ):
250- """HTML block template is v2 minified (or v3 with block_id )"""
254+ """HTML block template is v2 minified (or v3 with security_response_id )"""
251255 assert self .r_html_v2 .status_code == 403
252256 assert self .r_html_v2 .headers .get ("content-type" , "" ).lower () in HTML_CONTENT_TYPES
253257
254- # Accept v2 template without block_id or v3 template with block_id
258+ # Accept v2 template without security_response_id or v3 template with security_response_id
255259 response_text = self .r_html_v2 .text
256260 v2_template = _read_file (BLOCK_TEMPLATE_HTML_MIN_V2 )
257261
258262 # Check if it's v2 template
259263 if response_text == v2_template :
260264 return
261265
262- # Check if it's v3 template with valid block_id
266+ # Check if it's v3 template with valid security_response_id
263267 assert _is_valid_html_v3_template (self .r_html_v2 .text ), "Response doesn't match v2 or v3 template"
264268
265269
0 commit comments