mirror of
https://github.com/laramies/theHarvester.git
synced 2024-09-20 15:26:31 +08:00
Tidy up tests and remove duplicated code
This commit is contained in:
parent
193f6695f2
commit
ff82dfbf68
|
@ -5,26 +5,25 @@
|
|||
import requests
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestCertspotter(object):
|
||||
@staticmethod
|
||||
def domain() -> str:
|
||||
return 'metasploit.com'
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api(self):
|
||||
base_url = f'https://api.certspotter.com/v1/issuances?domain={TestCertspotter.domain()}&expand=dns_names'
|
||||
headers = {'User-Agent': Core.get_user_agent()}
|
||||
request = requests.get(base_url, headers=headers)
|
||||
assert request.status_code == 200
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search(self):
|
||||
search = certspottersearch.SearchCertspoter(TestCertspotter.domain())
|
||||
await search.process()
|
||||
assert isinstance(await search.get_hostnames(), set)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_no_results(self):
|
||||
search = certspottersearch.SearchCertspoter('radiant.eu')
|
||||
await search.process()
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
from requests import Response
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestSearchGithubCode:
|
||||
|
||||
|
@ -64,55 +66,47 @@ class MalformedResponse:
|
|||
response.json = MagicMock(return_value=json)
|
||||
response.status_code = 200
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_missing_key(self):
|
||||
with pytest.raises(MissingKey):
|
||||
Core.github_key = MagicMock(return_value=None)
|
||||
githubcode.SearchGithubCode(word="test", limit=500)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fragments_from_response(self):
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = test_class_instance.fragments_from_response(self.OkResponse.response)
|
||||
test_result = await test_class_instance.fragments_from_response(self.OkResponse.response)
|
||||
assert test_result == ["test1", "test2"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_fragments_from_response(self):
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = test_class_instance.fragments_from_response(self.MalformedResponse.response)
|
||||
assert test_result == []
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_response_ok(self):
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = test_class_instance.handle_response(self.OkResponse.response)
|
||||
assert isinstance(test_result, SuccessResult)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_response_retry(self):
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = test_class_instance.handle_response(self.RetryResponse.response)
|
||||
assert isinstance(test_result, RetryResult)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_response_fail(self):
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = test_class_instance.handle_response(self.FailureResponse.response)
|
||||
assert isinstance(test_result, ErrorResult)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_next_page(self):
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = githubcode.SuccessResult(list(), next_page=2, last_page=4)
|
||||
assert(2 == test_class_instance.next_page_or_end(test_result))
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_last_page(self):
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
import re
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestGetLinks(object):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_splitter(self):
|
||||
results = [
|
||||
'https://www.linkedin.com/in/don-draper-b1045618',
|
||||
|
@ -21,14 +22,12 @@ async def test_splitter(self):
|
|||
filtered_results = await splitter(results)
|
||||
assert len(filtered_results) == 1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_links(self):
|
||||
search = linkedinsearch.SearchLinkedin("facebook.com", '100')
|
||||
await search.process()
|
||||
links = await search.get_links()
|
||||
assert isinstance(links, list)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_links_linkedin(self):
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
mock_response = open(dir_path + "/test_linkedin_links.txt")
|
||||
|
@ -44,4 +43,4 @@ async def test_links_linkedin(self):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pytest.main()
|
||||
pytest.main()
|
||||
|
|
|
@ -5,26 +5,25 @@
|
|||
import requests
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestOtx(object):
|
||||
@staticmethod
|
||||
def domain() -> str:
|
||||
return 'metasploit.com'
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api(self):
|
||||
base_url = f'https://otx.alienvault.com/api/v1/indicators/domain/{TestOtx.domain()}/passive_dns'
|
||||
headers = {'User-Agent': Core.get_user_agent()}
|
||||
request = requests.get(base_url, headers=headers)
|
||||
assert request.status_code == 200
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search(self):
|
||||
search = otxsearch.SearchOtx(TestOtx.domain())
|
||||
await search.process()
|
||||
assert isinstance(await search.get_hostnames(), set)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_no_results(self):
|
||||
search = otxsearch.SearchOtx('radiant.eu')
|
||||
await search.process()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from theHarvester.lib.core import *
|
||||
import json
|
||||
#import grequests
|
||||
# import json
|
||||
# import grequests
|
||||
import re
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue