@@ -69,22 +69,29 @@ def _runner_test_various_file_slash(client, file_uri):
6969 wait_for_all_checks (client )
7070 res = client .get (url_for ("index" ))
7171
72+ substrings = [b"URLs with hostname components are not permitted" , b"No connection adapters were found for" ]
73+
74+
7275 # If it is enabled at test time
7376 if strtobool (os .getenv ('ALLOW_FILE_URI' , 'false' )):
74- # So it should permit it, but it should fall back to the 'requests' library giving an error
75- # (but means it gets passed to playwright etc)
76- assert b"URLs with hostname components are not permitted" in res .data
77- assert b"_runner_test_various_file_slash" in res .data # Can read this file OK
78- else :
79- # Default should be here
80- assert b'file:// type access is denied for security reasons.' in res .data
77+ if file_uri .startswith ('file:///' ):
78+ # This one should be the full qualified path to the file and should get the contents of this file
79+ res = client .get (
80+ url_for ("preview_page" , uuid = "first" ),
81+ follow_redirects = True
82+ )
83+ assert b'_runner_test_various_file_slash' in res .data
84+ else :
85+ # This will give some error from requests or if it went to chrome, will give some other error :-)
86+ assert any (s in res .data for s in substrings )
8187
8288 res = client .get (url_for ("form_delete" , uuid = "all" ), follow_redirects = True )
8389 assert b'Deleted' in res .data
8490
8591def test_file_slash_access (client , live_server , measure_memory_usage ):
8692 #live_server_setup(live_server)
87- # file: is permitted by default, but it will be caught by ALLOW_FILE_URI
93+
94+ # file: is NOT permitted by default, so it will be caught by ALLOW_FILE_URI check
8895
8996 test_file_path = os .path .abspath (__file__ )
9097 _runner_test_various_file_slash (client , file_uri = f"file://{ test_file_path } " )
0 commit comments