-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from d-Rickyy-b/dev
Multiple fixes and few new features
- Loading branch information
Showing
12 changed files
with
346 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.bcrypthashanalyzer import BcryptHashAnalyzer | ||
|
||
|
||
class TestBcryptHashAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = BcryptHashAnalyzer(None) | ||
self.obj = mock.Mock() | ||
|
||
def test_match(self): | ||
valid_hashes = ["$2a$10$BIgnlSmYE8qYiONM0NQ53eRWBw5G4HIJEbXKzcsRVt.08IDnqH/V.", | ||
"$2a$11$EppiRqR0kG9EKy56edDWTOnsv/oGW0dqAJB9ucmn3augbmcm8v/iy", | ||
"$2b$10$FpOpno43SIE8e1hWnlOdR.9hG2J8dd5FD1kQq8hn4zLdKa5eIiFUO", | ||
"$2a$10$SVy7GlMnWsemiZByHSnV0O3WoEHGImFt8v07uH.K3ZXwH5j9o/DP.", | ||
"$2a$10$59SNkcZ0rdC2VgeWaavVyea9PFget/xmtbV7.9IeJl3CUq.Q954i2", | ||
"$2b$10$Y8CJ9YIwrxt1YYgMqqU1delCYoTpIl18SRtYYI2kyM3jduKPHvWMC", | ||
"$2a$10$2tNCUb.FUpSutyhkbqmMBuNnLzhqI4q9Miqurnj6eu.XsiIjww7I6", | ||
"$2a$10$OyrADUFmj9QEqsd8frkEDOEYSPQalW5qoI1s2z6taCWwgUsjKzk5m"] | ||
|
||
invalid_hashes = ["7168D46050573DDA4CE409FA1515638BD28E86346D45F686310ED0678172BABCD4117FD15DD380B964352FE879FB745B573A730D526BB1188B2790FBA06E8ACA", | ||
"5FD924625F6AB16A19CC9807C7C506AE1813490E4BA675F843D5A10E0BAACDB8", | ||
"522F02FEA11E70C03C90C247C50410443246BFCB", | ||
"8433FD5A3B0ED71D21CFB9F291BD89B9", | ||
"$2a$124$SVy7GlMnWsemiZByHSnV0O3WoEHGImFt8v07uH.K3ZXwH5j9o/DP.a", | ||
"$2a$12$SVy7GlMnWsemiZByHSnV0O3WoEHGImFt8v{07uH.K3ZXwH5j9o/DP.a", | ||
"$2a$14$SVy7GlMnWsemiZByHSnV0O3WGImFt8v07uH.K3ZXwH5j9o/DP.a", | ||
"@x,Y8q+jnYeZr$;", | ||
"This is a test", | ||
"$2a$10$ asdf 1234 how are you?"] | ||
|
||
for test_hash in valid_hashes: | ||
self.obj.body = test_hash | ||
self.assertTrue(self.analyzer.match(self.obj), test_hash) | ||
|
||
for test_hash in invalid_hashes: | ||
self.obj.body = test_hash | ||
self.assertFalse(self.analyzer.match(self.obj), test_hash) | ||
|
||
def test_match_none(self): | ||
self.obj.body = None | ||
self.assertFalse(self.analyzer.match(self.obj)) | ||
|
||
self.obj = None | ||
self.assertFalse(self.analyzer.match(self.obj)) | ||
|
||
def test_match_empty(self): | ||
self.obj.body = "" | ||
self.assertFalse(self.analyzer.match(self.obj)) | ||
|
||
def test_actions_present(self): | ||
analyzer = BcryptHashAnalyzer(self.obj) | ||
self.assertEqual([self.obj], analyzer.actions) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.wordanalyzer import WordAnalyzer | ||
|
||
|
||
class TestWordAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.obj = mock.Mock() | ||
|
||
def test_match(self): | ||
analyzer = WordAnalyzer(None, "Test") | ||
self.obj.body = "This is a Test" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
analyzer = WordAnalyzer(None, "Test") | ||
self.obj.body = "There are tests for everything" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This is a Test for a longer sentence" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "Completely unrelated" | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
def test_blacklist(self): | ||
blacklist = ["fake", "bad"] | ||
analyzer = WordAnalyzer(None, "Test", blacklist=blacklist) | ||
|
||
self.obj.body = "This is a Test" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This is a fake Test" | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
analyzer = WordAnalyzer(None, "Test", blacklist=blacklist, case_sensitive=True) | ||
|
||
self.obj.body = "This is a Test" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This is a Fake Test" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
def test_multiple_words(self): | ||
analyzer = WordAnalyzer(None, None) | ||
self.assertEqual(analyzer.words, []) | ||
|
||
analyzer = WordAnalyzer(None, ["My", "first", "Test"]) | ||
self.obj.body = "This is a little test for something" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "You are my best friend so far!" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This is the first time I try this" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This time we try to match multiple words/tests for the first time." | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "None of the words are contained!" | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
# Check for case sensitivity for multiple words | ||
analyzer2 = WordAnalyzer(None, ["My", "first", "Test"], case_sensitive=True) | ||
|
||
self.obj.body = "That's not my issue!" | ||
self.assertFalse(analyzer2.match(self.obj)) | ||
|
||
self.obj.body = "That's not My issue!" | ||
self.assertTrue(analyzer2.match(self.obj)) | ||
|
||
def test_add_word(self): | ||
analyzer = WordAnalyzer(None, "Test") | ||
self.assertEqual(len(analyzer.words), 1) | ||
self.assertEqual(analyzer.words, ["Test"]) | ||
|
||
analyzer.add_word("second") | ||
self.assertEqual(len(analyzer.words), 2) | ||
self.assertEqual(analyzer.words, ["Test", "second"]) | ||
|
||
def test_case_sensitive(self): | ||
analyzer = WordAnalyzer(None, "Test", case_sensitive=True) | ||
self.obj.body = "This is a Test for case sensitivity" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This is a test for case sensitivity" | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This is a tESt for case sensitivity" | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
analyzer2 = WordAnalyzer(None, "Te1st") | ||
self.obj.body = "This is a te1st for case sensitivity" | ||
self.assertTrue(analyzer2.match(self.obj)) | ||
|
||
analyzer2 = WordAnalyzer(None, "Te1st") | ||
self.obj.body = "This is a tE1st for case sensitivity" | ||
self.assertTrue(analyzer2.match(self.obj)) | ||
|
||
def test_multiple_case_sensitive(self): | ||
"""Test if it's possible to match any of multiple words in a wordanalyzer when case sensitivty is activated""" | ||
analyzer = WordAnalyzer(None, ["My", "first", "Test"], case_sensitive=True) | ||
self.obj.body = "This is a little test for something" | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "You are my best friend so far!" | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This is a Test for case sensitivity" | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
self.obj.body = "This is a test for case sensitivity. It's the first of its kind." | ||
self.assertTrue(analyzer.match(self.obj)) | ||
|
||
def test_match_none(self): | ||
analyzer = WordAnalyzer(None, "Test") | ||
self.obj.body = None | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
self.obj = None | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
def test_match_empty(self): | ||
analyzer = WordAnalyzer(None, "Test") | ||
self.obj.body = "" | ||
self.assertFalse(analyzer.match(self.obj)) | ||
|
||
def test_actions_present(self): | ||
analyzer = WordAnalyzer(self.obj, "Test") | ||
self.assertEqual([self.obj], analyzer.actions) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.