2018-12-17 17:27:05 +01:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2018-12-17 17:27:05 +01:00
|
|
|
class CamoURLTest(ZulipTestCase):
|
|
|
|
def test_legacy_camo_url(self) -> None:
|
2020-10-23 02:43:28 +02:00
|
|
|
# Test with valid hex and URL pair
|
2021-02-12 08:19:30 +01:00
|
|
|
result = self.client_get(
|
|
|
|
"/external_content/0f50f0bda30b6e65e9442c83ddb4076c74e75f96/687474703a2f2f7777772e72616e646f6d2e736974652f696d616765732f666f6f6261722e6a706567"
|
|
|
|
)
|
2018-12-17 17:27:05 +01:00
|
|
|
self.assertEqual(result.status_code, 302, result)
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertIn(
|
2021-02-12 08:20:45 +01:00
|
|
|
"/filters:no_upscale():quality(100)/aHR0cDovL3d3dy5yYW5kb20uc2l0ZS9pbWFnZXMvZm9vYmFyLmpwZWc=/source_type/external",
|
2021-02-12 08:19:30 +01:00
|
|
|
result.url,
|
|
|
|
)
|
2018-12-17 17:27:05 +01:00
|
|
|
|
2020-10-23 02:43:28 +02:00
|
|
|
# Test with invalid hex and URL pair
|
2021-02-12 08:19:30 +01:00
|
|
|
result = self.client_get(
|
|
|
|
"/external_content/074c5e6c9c6d4ce97db1c740d79dc561cf7eb379/687474703a2f2f7777772e72616e646f6d2e736974652f696d616765732f666f6f6261722e6a706567"
|
|
|
|
)
|
2018-12-17 17:27:05 +01:00
|
|
|
self.assertEqual(result.status_code, 403, result)
|
|
|
|
self.assert_in_response("Not a valid URL.", result)
|
|
|
|
|
|
|
|
def test_with_thumbor_disabled(self) -> None:
|
|
|
|
with self.settings(THUMBOR_SERVES_CAMO=False):
|
2021-02-12 08:19:30 +01:00
|
|
|
result = self.client_get(
|
|
|
|
"/external_content/074c5e6c9c6d4ce97db1c740d79dc561cf7eb379/687474703a2f2f7777772e72616e646f6d2e736974652f696d616765732f666f6f6261722e6a706567"
|
|
|
|
)
|
2018-12-17 17:27:05 +01:00
|
|
|
self.assertEqual(result.status_code, 404, result)
|