Skip to content

Commit

Permalink
[bug 932300] Fix mixed-content issues with Gravatars
Browse files Browse the repository at this point in the history
  • Loading branch information
rehandalal committed Oct 29, 2013
1 parent d61e696 commit dd0c2c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion kitsune/users/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ def profile_avatar(user, size=48):
avatar = (profile.avatar.url if profile and profile.avatar else
settings.STATIC_URL + settings.DEFAULT_AVATAR)

if avatar.startswith('//'):
avatar = 'https:%s' % avatar

if user and hasattr(user, 'email'):
email_hash = hashlib.md5(user.email.lower()).hexdigest()
else:
email_hash = '00000000000000000000000000000000'

return '//www.gravatar.com/avatar/%s?s=%s&d=%s' % (
return 'https://secure.gravatar.com/avatar/%s?s=%s&d=%s' % (
email_hash, size, urllib.quote(avatar))


Expand Down
6 changes: 3 additions & 3 deletions kitsune/users/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ def test_profile_url(self):
def test_profile_avatar_default(self):
profile(user=self.u)
email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
gravatar_url = '//www.gravatar.com/avatar/%s?s=48&d=%s' % (
gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48&d=%s' % (
email_hash, settings.STATIC_URL + settings.DEFAULT_AVATAR)
eq_(gravatar_url, profile_avatar(self.u))

def test_profile_avatar_anonymous(self):
email_hash = '00000000000000000000000000000000'
gravatar_url = '//www.gravatar.com/avatar/%s?s=48&d=%s' % (
gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48&d=%s' % (
email_hash, settings.STATIC_URL + settings.DEFAULT_AVATAR)
eq_(gravatar_url, profile_avatar(AnonymousUser()))

def test_profile_avatar(self):
profile(user=self.u, avatar='images/foo.png')
email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
gravatar_url = '//www.gravatar.com/avatar/%s?s=48&d=%s' % (
gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48&d=%s' % (
email_hash, settings.MEDIA_URL + 'images/foo.png')
eq_(gravatar_url, profile_avatar(self.u))

Expand Down

0 comments on commit dd0c2c0

Please sign in to comment.