diff --git a/avatar/models.py b/avatar/models.py index a3e7413..aeaa6ae 100644 --- a/avatar/models.py +++ b/avatar/models.py @@ -140,7 +140,7 @@ class Avatar(models.Model): try: orientation = image._getexif()[0x0112] ops = EXIF_ORIENTATION_STEPS[orientation] - except TypeError: + except (AttributeError, TypeError): ops = [] for method in ops: image = image.transpose(getattr(Image, method)) diff --git a/tests/tests.py b/tests/tests.py index 3045a08..5661b32 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -129,6 +129,18 @@ class AvatarTests(TestCase): self.assertEqual(len(response.redirect_chain), 0) # Redirect only if it worked self.assertNotEqual(response.context["upload_avatar_form"].errors, {}) + # We allow the .tiff file extension and the mime type + @override_settings(AVATAR_ALLOWED_FILE_EXTS=(".png", ".gif", ".jpg", ".tiff")) + @override_settings( + AVATAR_ALLOWED_MIMETYPES=("image/png", "image/gif", "image/jpeg", "image/tiff") + ) + def test_supported_image_format_upload(self): + """Check with python-magic that we detect corrupted / unapprovd image files correctly""" + response = upload_helper(self, "test.tiff") + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.redirect_chain), 1) # Redirect only if it worked + self.assertEqual(response.context["upload_avatar_form"].errors, {}) + @override_settings(AVATAR_ALLOWED_FILE_EXTS=(".jpg", ".png")) def test_image_without_wrong_extension(self): response = upload_helper(self, "imagefilewithoutext")