|
11 | 11 | InvalidExternalVersionError,
|
12 | 12 | InvalidPathForVersionedProjectError,
|
13 | 13 | InvalidSchemeError,
|
| 14 | + InvalidSubdomainError, |
14 | 15 | SuspiciousHostnameError,
|
15 | 16 | TranslationNotFoundError,
|
16 | 17 | TranslationWithoutVersionError,
|
17 | 18 | VersionNotFoundError,
|
18 | 19 | unresolve,
|
| 20 | + unresolver, |
19 | 21 | )
|
20 | 22 | from readthedocs.projects.constants import SINGLE_VERSION_WITHOUT_TRANSLATIONS
|
21 | 23 | from readthedocs.projects.models import Domain
|
@@ -372,8 +374,34 @@ def test_unresolve_invalid_scheme(self):
|
372 | 374 | "fttp://pip.readthedocs.io/en/latest/",
|
373 | 375 | "fttps://pip.readthedocs.io/en/latest/",
|
374 | 376 | "ssh://pip.readthedocs.io/en/latest/",
|
| 377 | + "javascript://pip.readthedocs.io/en/latest/", |
375 | 378 | "://pip.readthedocs.io/en/latest/",
|
376 | 379 | ]
|
377 | 380 | for url in invalid_urls:
|
378 | 381 | with pytest.raises(InvalidSchemeError):
|
379 | 382 | unresolve(url)
|
| 383 | + |
| 384 | + # A triple slash is interpreted as a URL without domain, |
| 385 | + # we don't support that. |
| 386 | + with pytest.raises(InvalidSubdomainError): |
| 387 | + unresolve("https:///pip.readthedocs.io/en/latest/") |
| 388 | + |
| 389 | + def test_unresolve_domain_with_full_url(self): |
| 390 | + result = unresolver.unresolve_domain("https://pip.readthedocs.io/en/latest/") |
| 391 | + self.assertIsNone(result.domain) |
| 392 | + self.assertEqual(result.project, self.pip) |
| 393 | + self.assertTrue(result.is_from_public_domain) |
| 394 | + self.assertEqual(result.source_domain, "pip.readthedocs.io") |
| 395 | + |
| 396 | + def test_unresolve_domain_with_full_url_invalid_protocol(self): |
| 397 | + invalid_protocols = [ |
| 398 | + "fttp", |
| 399 | + "fttps", |
| 400 | + "ssh", |
| 401 | + "javascript", |
| 402 | + ] |
| 403 | + for protocol in invalid_protocols: |
| 404 | + with pytest.raises(InvalidSchemeError): |
| 405 | + unresolver.unresolve_domain( |
| 406 | + f"{protocol}://pip.readthedocs.io/en/latest/" |
| 407 | + ) |
0 commit comments