theHarvester/tests/discovery/test_linkedin_links.py

45 lines
1.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# coding=utf-8
2019-09-08 10:54:59 +08:00
from theHarvester.discovery import linkedinsearch
2019-09-09 00:35:07 +08:00
from theHarvester.discovery.constants import splitter
2019-09-07 11:00:22 +08:00
import pytest
2019-09-08 08:59:58 +08:00
import os
2019-09-08 08:34:11 +08:00
import re
class TestGetLinks(object):
2019-09-09 00:35:07 +08:00
def test_splitter(self):
results = [
2019-09-09 00:43:20 +08:00
'https://www.linkedin.com/in/don-draper-b1045618',
'https://www.linkedin.com/in/don-draper-b59210a',
'https://www.linkedin.com/in/don-draper-b5bb50b3',
'https://www.linkedin.com/in/don-draper-b83ba26',
'https://www.linkedin.com/in/don-draper-b854a51'
]
2019-09-09 00:35:07 +08:00
filtered_results = splitter(results)
assert len(filtered_results) == 1
2019-09-08 10:54:59 +08:00
def test_get_links(self):
search = linkedinsearch.SearchLinkedin("facebook.com", '100')
search.process()
links = search.get_links()
assert type(links) == list
2019-09-08 08:34:11 +08:00
def test_links_linkedin(self):
2019-09-08 08:59:58 +08:00
dir_path = os.path.dirname(os.path.realpath(__file__))
2019-09-08 09:29:07 +08:00
mock_response = open(dir_path + "/test_linkedin_links.txt")
mock_response_content = mock_response.read()
mock_response.close()
2019-09-08 08:34:11 +08:00
reg_links = re.compile(r"url=https:\/\/www\.linkedin.com(.*?)&")
2019-09-08 09:29:07 +08:00
temp = reg_links.findall(mock_response_content)
2019-09-08 08:34:11 +08:00
resul = []
for regex_item in temp:
stripped_url = regex_item.replace("url=", "")
2019-09-08 09:20:35 +08:00
resul.append("https://www.linkedin.com" + stripped_url)
2019-09-08 08:34:11 +08:00
assert set(resul)
if __name__ == '__main__':
pytest.main()