Files
zulip/zerver/tests/test_camo.py
Aditya Bansal 079dfadf1a camo: Add endpoint to handle camo requests.
This endpoint serves requests which might originate from an image
preview link which had an http url and the message holding the image
link was rendered before we introduced thumbnailing. In that case
we would have used a camo proxy to proxy http content over https and
avoid mix content warnings.

In near future, we plan to drop use of camo and just rely on thumbor
to serve such images. This endpoint helps maintain backward
compatibility for links which were already rendered.
2019-01-04 10:27:04 -08:00

20 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
from zerver.lib.test_classes import ZulipTestCase
class CamoURLTest(ZulipTestCase):
def test_legacy_camo_url(self) -> None:
# Test with valid hex and url pair
result = self.client_get("/external_content/0f50f0bda30b6e65e9442c83ddb4076c74e75f96/687474703a2f2f7777772e72616e646f6d2e736974652f696d616765732f666f6f6261722e6a706567")
self.assertEqual(result.status_code, 302, result)
self.assertIn('/filters:no_upscale():quality(100)/aHR0cDovL3d3dy5yYW5kb20uc2l0ZS9pbWFnZXMvZm9vYmFyLmpwZWc=/source_type/external', result.url)
# Test with invalid hex and url pair
result = self.client_get("/external_content/074c5e6c9c6d4ce97db1c740d79dc561cf7eb379/687474703a2f2f7777772e72616e646f6d2e736974652f696d616765732f666f6f6261722e6a706567")
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):
result = self.client_get("/external_content/074c5e6c9c6d4ce97db1c740d79dc561cf7eb379/687474703a2f2f7777772e72616e646f6d2e736974652f696d616765732f666f6f6261722e6a706567")
self.assertEqual(result.status_code, 404, result)