Skip to content

Commit

Permalink
feat(package/checker): Handle case where request is blocked by HaveIB…
Browse files Browse the repository at this point in the history
…eenPwned service
  • Loading branch information
iifeoluwa committed Apr 17, 2019
1 parent 6d0c0b6 commit c73ba52
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/checker/data/answers/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"I think %website_name% is down at the moment, please try again later.",
"I'm having trouble reaching %website_name%. Please check that your internet connection is active.",
"Bad news, %website_name% is not responding. Maybe try at a later time?"
],
"blocked": [
"There was an issue acessing %website_name%'s service.",
"Unfortunate news, %website_name% isn't granting me access to its service."
]
}
}
4 changes: 4 additions & 0 deletions packages/checker/data/answers/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"Je pense que %website_name% est en panne pour le moment, veuillez réessayer plus tard.",
"J'ai du mal à joindre %website_name%. Veuillez vérifier que votre connexion Internet est active.",
"Mauvaise nouvelle, %website_name% ne répond pas. Peut-être essayer plus tard?"
],
"blocked": [
"Il y avait un problème d'accès au service de %website_name%.",
"Malheureusement, %website_name% ne me donne pas accès à son service."
]
}
}
9 changes: 7 additions & 2 deletions packages/checker/haveibeenpwned.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def haveibeenpwned(string, entities):
breached = checkForBreach(email)
data = { 'email': email }

if not breached:
# HaveIBeenPwned API returns a 403 when accessed by unauthorized/banned clients
if breached == 403:
return utils.output('end', 'blocked', utils.translate('blocked', { 'website_name': 'HaveIBeenPwned' }))
elif not breached:
if isLastEmail:
return utils.output('end', 'no-pwnage', utils.translate('no-pwnage', data))
else:
Expand All @@ -48,7 +51,9 @@ def checkForBreach(email):

if response.status_code == 404:
return None
elif response.status_code == 200:
return response.json

return response.json()
return response.status_code
except exceptions.RequestException as e:
return utils.output('end', 'down', utils.translate('errors', { 'website_name': 'HaveIBeenPwned' }))

0 comments on commit c73ba52

Please sign in to comment.