1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-24 04:31:31 +03:00

feat(package/checker): allow multiple breaches output in the Have I Been Pwned module

This commit is contained in:
Louistiti 2019-04-27 12:12:04 +08:00
parent 8374e54810
commit a476fd0f38
8 changed files with 70 additions and 55 deletions

View File

@ -8,4 +8,4 @@ packagejsonfile = open(path.dirname(path.realpath(__file__)) + '/../../package.j
packagejson = loads(packagejsonfile.read())
packagejsonfile.close()
useragent = 'Leon/' + packagejson['version']
useragent = 'Leon-Personal-Assistant/' + packagejson['version']

View File

@ -1,5 +1,9 @@
{
"isitdown": {
"options": {}
}
},
"haveibeenpwned": {
"emails": [],
"options": {}
}
}

View File

@ -26,17 +26,20 @@
},
"haveibeenpwned": {
"no-pwnage": [
"Great news, %email% hasn't been compromised in a data breach.",
"%email% looks good to me!"
"Great news, \"%email%\" hasn't been compromised in a data breach.",
"\"%email%\" looks good to me!"
],
"pwned": [
"Oops, looks like %email% has been compromised in a breach involving %breach%.",
"%breach% was involved in a breach. Sadly, %email% was affected.",
"Unfortunately, %email% has been exposed in a data breach affecting %breach%."
"Oops, looks like \"%email%\" has been compromised in at least one breach involving:<br><br><ul>%result%</ul>",
"Sadly, \"%email%\" was affected in the following breaches:<br><br><ul>%result%</ul>",
"Unfortunately, \"%email%\" has been exposed in a data breach affecting:<br><br><ul>%result%</ul>"
],
"list_element": [
"<li><a href=\"%url%\" target=\"_blank\">%name%</a> with a total of %total% accounts.</li>"
],
"checking": [
"I'm checking for a compromised email.",
"Trying to verify pwnage status."
"I'm checking for a compromised email...",
"Trying to verify pwnage status..."
],
"no-email": [
"Please provide one or more email addresses you need me to check."

View File

@ -19,9 +19,9 @@
"Has iifeoluwa.ao@gmail.com been exposed in a breach?",
"Is iifeoluwa.ao@gmail.com still uncompromised?",
"Is iifeoluwa.ao@gmail.com compromised?",
"Check that iifeoluwa.ao@gmail.com and louis.grenard@gmail.com haven't been compromised.",
"Check that iifeoluwa.ao@gmail.com and louis.grenard@gmail.com haven't been pwned.",
"Check that iifeoluwa.ao@gmail.com and louis.grenard@gmail.com haven't been exposed in a breach.",
"Check that iifeoluwa.ao@gmail.com and louis.grenard@gmail.com haven't been compromised",
"Check that iifeoluwa.ao@gmail.com and louis.grenard@gmail.com haven't been pwned",
"Check that iifeoluwa.ao@gmail.com and louis.grenard@gmail.com haven't been exposed in a breach",
"Verify the pwnage status of iifeoluwa.ao@gmail.com",
"Verify the pwnage status of iifeoluwa.ao@gmail.com and louis.grenard@gmail.com"
]

View File

@ -14,15 +14,13 @@
"Vérifies si amazon.com en ligne ou hors ligne"
],
"haveibeenpwned": [
"iifeoluwa.ao@gmail.com a-t-il été pwned?",
"iifeoluwa.ao@gmail.com a-t-il été compromis?",
"iifeoluwa.ao@gmail.com a-t-il été exposé à une brèche?",
"iifeoluwa.ao@gmail.com est-il toujours sans compromis?",
"Est-ce que iifeoluwa.ao@gmail.com est compromis?",
"Vérifiez que iifeoluwa.ao@gmail.com et louis.grenard@gmail.com n'ont pas été compromis.",
"Vérifiez que iifeoluwa.ao@gmail.com et louis.grenard@gmail.com n'ont pas été pwned.",
"Vérifiez que iifeoluwa.ao@gmail.com et louis.grenard@gmail.com n'ont pas été exposés à une brèche.",
"Vérifier le statut de iifeoluwa.ao@gmail.com",
"Vérifiez le statut de iifeoluwa.ao@gmail.com et louis.grenard@gmail.com"
"iifeoluwa.ao@gmail.com a-t-il été pwned ?",
"iifeoluwa.ao@gmail.com a-t-il été compromis ?",
"iifeoluwa.ao@gmail.com a-t-il été exposée à une brèche ?",
"iifeoluwa.ao@gmail.com est-il toujours non compromis ?",
"Est-ce que iifeoluwa.ao@gmail.com est compromis ?",
"Vérifies que iifeoluwa.ao@gmail.com et louis.grenard@gmail.com n'ont pas été compromis",
"Vérifies que iifeoluwa.ao@gmail.com et louis.grenard@gmail.com n'ont pas été pwned",
"Vérifies que iifeoluwa.ao@gmail.com et louis.grenard@gmail.com n'ont pas été exposées à une brèche"
]
}

View File

@ -8,16 +8,17 @@ from requests import codes, exceptions
def haveibeenpwned(string, entities):
emails = []
for item in entities:
if item['entity'] == 'email':
emails.append(item['resolution']['value'])
if not emails:
emails = utils.config('emails')
if not emails:
return utils.output('end', 'no-email', utils.translate('no-email'))
utils.output('inter', 'checking', utils.translate('checking'))
for index, email in enumerate(emails):
@ -25,16 +26,25 @@ def haveibeenpwned(string, entities):
breached = checkForBreach(email)
data = { 'email': email }
# HaveIBeenPwned API returns a 403 when accessed by unauthorized/banned clients
# Have I Been Pwned API returns a 403 when accessed by unauthorized/banned clients
if breached == 403:
return utils.output('end', 'blocked', utils.translate('blocked', { 'website_name': 'HaveIBeenPwned' }))
return utils.output('end', 'blocked', utils.translate('blocked', { 'website_name': 'Have I Been Pwned' }))
elif not breached:
if isLastEmail:
return utils.output('end', 'no-pwnage', utils.translate('no-pwnage', data))
else:
utils.output('inter', 'no-pwnage', utils.translate('no-pwnage', data))
else:
data['breach'] = breached[0]['Name']
data['result'] = ''
for index, b in enumerate(breached):
data['result'] += utils.translate('list_element', {
'url': 'http://' + b['Domain'],
'name': b['Name'],
'total': b['PwnCount']
}
)
if isLastEmail:
return utils.output('end', 'pwned', utils.translate('pwned', data))
else:
@ -44,16 +54,16 @@ def checkForBreach(email):
# Delay for 2 seconds before making request to accomodate API usage policy
sleep(2)
truncate = '?truncateResponse=true'
url = 'https://haveibeenpwned.com/api/v2/breachedaccount/' + parse.quote_plus(email) + truncate
url = 'https://haveibeenpwned.com/api/v2/breachedaccount/' + parse.quote_plus(email)
try:
response = utils.http('GET', url)
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' }))
return utils.output('end', 'down', utils.translate('errors', { 'website_name': 'Have I Been Pwned' }))

View File

@ -1,9 +1,9 @@
'use strict'
describe('checker:haveibeenpwned', async () => {
test('checks that an email has been pwned', async () => {
test('checks if an email address has been pwned', async () => {
global.nlu.brain.execute = jest.fn()
await global.nlu.process('Has iifeoluwa.ao@gmail.com been pwned?')
await global.nlu.process('Has supercleanemailaddress@supercleandomainname.com been pwned?')
const [obj] = global.nlu.brain.execute.mock.calls
await global.brain.execute(obj[0])
@ -11,9 +11,9 @@ describe('checker:haveibeenpwned', async () => {
expect(global.brain.finalOutput.codes).toIncludeSameMembers(['checking', 'no-pwnage'])
})
test('checks that multiple emails have been pwned', async () => {
test('checks if multiple email addresses have been pwned', async () => {
global.nlu.brain.execute = jest.fn()
await global.nlu.process('Verify the pwnage status of iifeoluwa.ao@gmail.com and ifeoluwa1990@yahoo.com')
await global.nlu.process('Verify the pwnage status of supercleanemailaddress@supercleandomainname.com and test@toto.com')
const [obj] = global.nlu.brain.execute.mock.calls
await global.brain.execute(obj[0])

View File

@ -1,31 +1,31 @@
{
"lang": "en",
"package": "checker",
"module": "isitdown",
"query": "Check if github.com, mozilla.org and twitter.com are up",
"module": "haveibeenpwned",
"query": "Check if louis.grenard@gmail.com and louistiti42@gmail.com have been pwned",
"entities": [
{
"sourceText": "github.com",
"utteranceText": "github.com",
"entity": "url",
"start": 12,
"end": 33,
"len": 22,
"accuracy": 0.95,
"sourceText": "something@somehost.com",
"utteranceText": "something@somehost.com",
"entity": "email",
"resolution": {
"value": "github.com"
"value": "louis.grenard@gmail.com"
}
},
{
"sourceText": "mozilla.org",
"utteranceText": "mozilla.org",
"entity": "url",
"start": 12,
"end": 33,
"len": 22,
"accuracy": 0.95,
"sourceText": "something@somehost.com",
"utteranceText": "something@somehost.com",
"entity": "email",
"resolution": {
"value": "mozilla.org"
}
},
{
"sourceText": "twitter.com",
"utteranceText": "twitter.com",
"entity": "url",
"resolution": {
"value": "twitter.com"
"value": "louistiti42@gmail.com"
}
}
]