Skip to content

Commit

Permalink
feat(package/checker): Add test for haveibeenpwned module
Browse files Browse the repository at this point in the history
  • Loading branch information
iifeoluwa committed Apr 17, 2019
1 parent 3636866 commit a7a6d88
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__pycache__/
.idea/
.vscode/
**/dist/
**/node_modules/
test/coverage/
Expand All @@ -25,3 +26,4 @@ packages/**/data/db/*.json
server/src/data/expressions/classifier.json
app/js/main.js
package.json.backup
.python-version
10 changes: 6 additions & 4 deletions packages/checker/haveibeenpwned.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def haveibeenpwned(string, entities):
if not emails:
emails = utils.config('emails')
if not emails:
utils.output('end', 'no-email', utils.translate('no-email'))
return utils.output('end', 'no-email', utils.translate('no-email'))

utils.output('inter', 'checking', utils.translate('checking'))

for index, email in enumerate(emails):
isLastEmail = index == len(emails) - 1
Expand All @@ -25,13 +27,13 @@ def haveibeenpwned(string, entities):

if not breached:
if isLastEmail:
utils.output('end', 'no-pwnage', utils.translate('no-pwnage', data))
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']
if isLastEmail:
utils.output('end', '', utils.translate('pwned', data))
return utils.output('end', 'pwned', utils.translate('pwned', data))
else:
utils.output('inter', 'pwned', utils.translate('pwned', data))

Expand All @@ -49,4 +51,4 @@ def checkForBreach(email):

return response.json()
except exceptions.RequestException as e:
utils.output('end', 'down', utils.translate('errors', { 'website_name': 'HaveIBeenPwned' }))
return utils.output('end', 'down', utils.translate('errors', { 'website_name': 'HaveIBeenPwned' }))
23 changes: 23 additions & 0 deletions packages/checker/test/haveibeenpwned.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

describe('checker:haveibeenpwned', async () => {
test('checks that an email has been pwned', async () => {
global.nlu.brain.execute = jest.fn()
await global.nlu.process('Has iifeoluwa.ao@gmail.com been pwned?')

const [obj] = global.nlu.brain.execute.mock.calls
await global.brain.execute(obj[0])

expect(global.brain.finalOutput.codes).toIncludeSameMembers(['checking', 'no-pwnage'])
})

test('checks that multiple emails 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')

const [obj] = global.nlu.brain.execute.mock.calls
await global.brain.execute(obj[0])

expect(global.brain.finalOutput.codes).toIncludeSameMembers(['checking', 'no-pwnage', 'pwned'])
})
})

0 comments on commit a7a6d88

Please sign in to comment.