def get(self, request, signature, image_id, filter_spec, filename=None): if not verify_signature(signature.encode(), image_id, filter_spec, key=self.key): raise PermissionDenied image = get_object_or_404(self.model, id=image_id) # Get/generate the rendition try: rendition = image.get_rendition(filter_spec) except SourceImageIOError: return HttpResponse("Source image file not found", content_type='text/plain', status=410) except InvalidFilterSpecError: return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400) return getattr(self, self.action)(rendition)
def test_signature_changes_on_filter_spec(self): self.assertFalse( verify_signature("xnZOzQyUg6pkfciqcfRJRosOrGg=", 100, "fill-800x700"))
def test_signature_changes_on_image_id(self): self.assertFalse( verify_signature("xnZOzQyUg6pkfciqcfRJRosOrGg=", 200, "fill-800x600"))
def test_signature_verification(self): self.assertTrue( verify_signature("xnZOzQyUg6pkfciqcfRJRosOrGg=", 100, "fill-800x600"))
def test_signature_verification(self): self.assertTrue(verify_signature('xnZOzQyUg6pkfciqcfRJRosOrGg=', 100, 'fill-800x600'))