#32567: Issues with ":" and "|" characters in URLs when using 
LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
               Reporter:  timoguic   |          Owner:  nobody
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Testing    |        Version:  3.1
  framework                          |       Keywords:  windows,
               Severity:  Normal     |  liveservertestcase, path
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I am using Python 3.8 32-bit on Windows: Python 3.8.5
 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
 on win32

 I installed Django and requests in a virtual environment:
 pip install django requests

 My virtual environment now has:
 {{{
 asgiref==3.3.1
 certifi==2020.12.5
 chardet==4.0.0
 Django==3.1.7
 idna==2.10
 pytz==2021.1
 requests==2.25.1
 sqlparse==0.4.1
 urllib3==1.26.4
 }}}

 I created a new Django project:
 {{{
 django-admin.exe startproject example
 cd example
 django-admin.exe startapp livecase
 }}}

 I used the following code in my example/livecase/views.py:
 {{{
 from django.http import HttpResponse

 def example(request):
     return HttpResponse("OK")
 }}}

 And the following in example/example/urls.py:
 {{{
 from django.contrib import admin
 from django.urls import path
 from livecase.views import example

 urlpatterns = [
     path('test:12345/', example),
     path('admin/', admin.site.urls),
 ]
 }}}

 I then used the following code in example/livecase/tests.py:
 {{{
 from django.test import LiveServerTestCase
 import requests

 class MyTest(LiveServerTestCase):
     def test_example(self):
         r = requests.get(f"{self.live_server_url}/test:12345/")
         self.assertEqual(r.status_code, 200)
 }}}

 I run the tests: python manage.py test

 I get the following error, with the traceback:
 {{{
 Traceback (most recent call last):
   File
 
"C:\[redacted]\AppData\Local\Programs\Python\Python38-32\lib\wsgiref\handlers.py",
 line 137, in run
     self.result = application(self.environ, self.start_response)
   File "C:\[redacted]\venv-test\lib\site-
 packages\django\test\testcases.py", line 1324, in __call__
     return self.application(environ, start_response)
   File "C:\[redacted]\venv-test\lib\site-
 packages\django\test\testcases.py", line 1325, in __call__
     return super().__call__(environ, start_response)
   File "C:\[redacted]\venv-test\lib\site-
 packages\django\core\handlers\wsgi.py", line 133, in __call__
     response = self.get_response(request)
   File "C:\[redacted]\venv-test\lib\site-
 packages\django\test\testcases.py", line 1305, in get_response
     return self.serve(request)
   File "C:\[redacted]\venv-test\lib\site-
 packages\django\test\testcases.py", line 1320, in serve
     return serve(request, final_rel_path,
 document_root=self.get_base_dir())
   File "C:\[redacted]\venv-test\lib\site-packages\django\views\static.py",
 line 38, in serve
     fullpath = Path(safe_join(document_root, path))
   File "C:\[redacted]\venv-test\lib\site-packages\django\utils\_os.py",
 line 29, in safe_join
     raise SuspiciousFileOperation(
 django.core.exceptions.SuspiciousFileOperation: The joined path (T:\12345)
 is located outside of the base path component (C:\[redacted]\example)
 F
 ======================================================================
 FAIL: test_example (livecase.tests.MyTest)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "C:\[redacted]\example\livecase\tests.py", line 9, in test_example
     self.assertEqual(r.status_code, 200)
 AssertionError: 500 != 200

 ----------------------------------------------------------------------
 Ran 1 test in 0.528s
 }}}

 If I use "|" instead of ":" in the URL in the test case, the same problem
 happens.
 If I use self.client.get, the test passes and no exception is raised.

 I tried to replicate the issue in a Linux environment, and I was not able
 to (although using Python 3.8 64 bit).

 I believe the path conversion issue is happening at
 
https://github.com/django/django/blob/45814af6197cfd8f4dc72ee43b90ecde305a1d5a/django/test/testcases.py#L1439

 Thanks.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32567>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.3334ae367c9bee6cf1cef1c572a9a056%40djangoproject.com.

Reply via email to