|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import unittest |
| 3 | +from pastepwn.scraping.pastebin import PastebinScraper |
| 4 | +from pastepwn.scraping.pastebin.exceptions import IPNotRegisteredError, PasteDeletedException, PasteNotReadyException, PasteEmptyException |
| 5 | + |
| 6 | + |
| 7 | +class TestPastebinscraper(unittest.TestCase): |
| 8 | + |
| 9 | + def setUp(self) -> None: |
| 10 | + self.pastebinscraper = PastebinScraper() |
| 11 | + |
| 12 | + def test_empty(self): |
| 13 | + with self.assertRaises(PasteEmptyException): |
| 14 | + self.pastebinscraper._check_error("") |
| 15 | + |
| 16 | + def test_not_ready(self): |
| 17 | + with self.assertRaises(PasteNotReadyException): |
| 18 | + self.pastebinscraper._check_error("File is not ready for scraping yet. Try again in 1 minute.") |
| 19 | + |
| 20 | + def test_deleted(self): |
| 21 | + with self.assertRaises(PasteDeletedException): |
| 22 | + self.pastebinscraper._check_error("Error, we cannot find this paste.") |
| 23 | + |
| 24 | + def _check_ip_not_registered(self, ip_list): |
| 25 | + shell = "YOUR IP: {} DOES NOT HAVE ACCESS. VISIT: https://pastebin.com/doc_scraping_api TO GET ACCESS!" |
| 26 | + for ip in ip_list: |
| 27 | + with self.assertRaises(IPNotRegisteredError): |
| 28 | + self.pastebinscraper._check_error(shell.format(ip)) |
| 29 | + print("The following IP was not detected: {}".format(ip)) |
| 30 | + |
| 31 | + def test_ipv4_not_registered(self): |
| 32 | + """Test if the _check_error method detects different IPv4 addresses. It's okay to also detect invalid addresses where an octed is > 255)""" |
| 33 | + ipv4_test = ["1.1.1.1", "10.1.5.6", "1.10.5.6", "1.1.50.6", "1.1.5.60", "1.1.50.60", "1.10.50.60", "10.10.50.60", "10.10.50.255", "10.10.255.255", |
| 34 | + "10.255.255.255", "255.255.255.255", "333.333.333.333"] |
| 35 | + |
| 36 | + self._check_ip_not_registered(ipv4_test) |
| 37 | + |
| 38 | + def test_ipv6_not_registered(self): |
| 39 | + ipv6_test = ["fe80::21d8:f50:c295:c4be", "2001:cdba:0000:0000:0000:0000:3257:9652", "2001:cdba:0:0:0:0:3257:9652", "2001:cdba::3257:9652", |
| 40 | + "2001:cdba::1222", "21DA:D3:0:2F3B:2AA:FF:FE28:9C5A", "2001:cdba::1:2:3:3257:9652", "FE80::8329", "FE80::FFFF:8329", |
| 41 | + "FE80::B3FF:FFFF:8329", "FE80::0202:B3FF:FFFF:8329", "FE80:0000:0000:0000:0202:B3FF:FFFF:8329"] |
| 42 | + # TODO: IPv6 addresses with double colon AND full zero groups (of 16 bits) are currently not recognized by the used regex. An example address would |
| 43 | + # be: `FE80::0000:0000:0202:B3FF:FFFF:8329` |
| 44 | + |
| 45 | + self._check_ip_not_registered(ipv6_test) |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == '__main__': |
| 49 | + unittest.main() |
0 commit comments