Adding tests

This commit is contained in:
Michael Lazar 2021-05-12 10:59:06 -04:00
parent cc4901241f
commit cc4d842040
2 changed files with 29 additions and 5 deletions

View File

@ -0,0 +1 @@
this is a file

View File

@ -144,22 +144,38 @@ class FunctionalTestCase(unittest.TestCase):
self.assertEqual(resp, "51 Not Found\r\n") self.assertEqual(resp, "51 Not Found\r\n")
def test_directory_redirect(self): def test_directory_redirect(self):
resp = self.request("gemini://localhost/cgi-bin\r\n") resp = self.request("gemini://localhost/files\r\n")
self.assertEqual(resp, "31 gemini://localhost/cgi-bin/\r\n") self.assertEqual(resp, "31 gemini://localhost/files/\r\n")
def test_directory(self): def test_directory(self):
resp = self.request("gemini://localhost/cgi-bin/\r\n") resp = self.request("gemini://localhost/files/\r\n")
resp = resp.splitlines(keepends=True)[0]
self.assertEqual(resp, "20 text/gemini\r\n")
def test_directory_double_slash(self):
resp = self.request("gemini://localhost/files//\r\n")
resp = resp.splitlines(keepends=True)[0] resp = resp.splitlines(keepends=True)[0]
self.assertEqual(resp, "20 text/gemini\r\n") self.assertEqual(resp, "20 text/gemini\r\n")
def test_directory_up(self): def test_directory_up(self):
resp = self.request("gemini://localhost/cgi-bin/..\r\n") resp = self.request("gemini://localhost/files/..\r\n")
self.assertEqual(resp, "31 gemini://localhost/cgi-bin/../\r\n") self.assertEqual(resp, "31 gemini://localhost/files/../\r\n")
def test_directory_up_trailing_slash(self): def test_directory_up_trailing_slash(self):
resp = self.request("gemini://localhost/cgi-bin/../\r\n") resp = self.request("gemini://localhost/cgi-bin/../\r\n")
self.assertEqual(resp, "20 text/gemini\r\nJetforce rules!\n") self.assertEqual(resp, "20 text/gemini\r\nJetforce rules!\n")
def test_file_double_slash(self):
resp = self.request("gemini://localhost/files//test.txt\r\n")
self.assertEqual(resp, "20 text/plain\r\nthis is a file\n")
def test_file_trailing_slash(self):
"""
Will return the file, I'm not sure if this is desired behavior or not.
"""
resp = self.request("gemini://localhost/files/test.txt/\r\n")
self.assertEqual(resp, "20 text/plain\r\nthis is a file\n")
def test_non_utf8(self): def test_non_utf8(self):
resp = self.request("gemini://localhost/%AE\r\n") resp = self.request("gemini://localhost/%AE\r\n")
self.assertEqual(resp, "51 Not Found\r\n") self.assertEqual(resp, "51 Not Found\r\n")
@ -197,6 +213,13 @@ class FunctionalTestCase(unittest.TestCase):
self.assertEqual(data["SCRIPT_NAME"], "/cgi-bin/debug.py") self.assertEqual(data["SCRIPT_NAME"], "/cgi-bin/debug.py")
self.assertEqual(data["PATH_INFO"], "/extra/info/") self.assertEqual(data["PATH_INFO"], "/extra/info/")
def test_cgi_path_info_double_slashes(self):
resp = self.request("gemini://localhost//cgi-bin//debug.py//extra//info//\r\n")
data = self.parse_cgi_resp(resp)
self.assertEqual(data["QUERY_STRING"], "")
self.assertEqual(data["SCRIPT_NAME"], "/cgi-bin/debug.py")
self.assertEqual(data["PATH_INFO"], "/extra/info/")
def test_hostname_punycode(self): def test_hostname_punycode(self):
with mock.patch.object(self.server, "hostname", "xn--caf-dma.localhost"): with mock.patch.object(self.server, "hostname", "xn--caf-dma.localhost"):
resp = self.request("gemini://xn--caf-dma.localhost\r\n") resp = self.request("gemini://xn--caf-dma.localhost\r\n")