Skip to content

Commit

Permalink
feat: add tests for pastebin url analyzer (#109)
Browse files Browse the repository at this point in the history
* 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
Sree Siva Sandeep Palaparthi authored and d-Rickyy-b committed Nov 11, 2019
1 parent fc1d1ab commit 88abf88
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pastepwn/analyzers/pastebinurlanalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class PastebinURLAnalyzer(URLAnalyzer):
name = "PastebinURLAnalyzer"

def __init__(self, actions, resolve=False):
regex = r"((?:https?:\/\/)?pastebin.com\/\S+)"
regex = r"((?:https?:\/\/)?pastebin.com\/[a-zA-Z0-9]{3,})"
super().__init__(actions, regex, resolve)
43 changes: 43 additions & 0 deletions pastepwn/analyzers/tests/pastebinurlanalyzer_test.py
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()

0 comments on commit 88abf88

Please sign in to comment.