-
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.
feat: add tests for pastebin url analyzer (#109)
* feat: add tests for pastebin url analyzer * fix: remove www from valid url * feat(url-analyzer): make pastbin www tests to positive * FIX: Analyzer should only catch certain links The pastebinurlanalyzer should only match on certain strings in the URL. I specified it a bit more precisely
- Loading branch information
1 parent
fc1d1ab
commit 88abf88
Showing
2 changed files
with
44 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.pastebinurlanalyzer import PastebinURLAnalyzer | ||
|
||
|
||
class TestPastebinURLAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = PastebinURLAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
self.paste.body = "https://pastebin.com/xyz" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "https://pastebin.com/xyz/" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "http://pastebin.com/xyz" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "http://pastebin.com/xyz/" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "https://pastebin.com/xyz " | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "www.pastebin.com/xyz" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "pastebin.com/xyx" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "This is a pastebin URL: pastebin.com/ya249asd - and this is a test" | ||
|
||
def test_match_negative(self): | ||
self.paste.body = "" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
self.paste.body = None | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
self.paste.body = "https://google.com/xyz" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
self.paste.body = "xyzpastebin.com/k" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
self.paste.body = "https://pastebin.com/" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |