Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sherlock-project
GitHub Repository: sherlock-project/sherlock
Path: blob/master/tests/test_probes.py
761 views
1
import pytest
2
import random
3
import string
4
import re
5
from sherlock_project.sherlock import sherlock
6
from sherlock_project.notify import QueryNotify
7
from sherlock_project.result import QueryStatus
8
#from sherlock_interactives import Interactives
9
10
11
def simple_query(sites_info: dict, site: str, username: str) -> QueryStatus:
12
query_notify = QueryNotify()
13
site_data: dict = {}
14
site_data[site] = sites_info[site]
15
return sherlock(
16
username=username,
17
site_data=site_data,
18
query_notify=query_notify,
19
)[site]['status'].status
20
21
22
@pytest.mark.online
23
class TestLiveTargets:
24
"""Actively test probes against live and trusted targets"""
25
# Known positives should only use sites trusted to be reliable and unchanging
26
@pytest.mark.parametrize('site,username',[
27
('GitLab', 'ppfeister'),
28
('AllMyLinks', 'blue'),
29
])
30
def test_known_positives_via_message(self, sites_info, site, username):
31
assert simple_query(sites_info=sites_info, site=site, username=username) is QueryStatus.CLAIMED
32
33
34
# Known positives should only use sites trusted to be reliable and unchanging
35
@pytest.mark.parametrize('site,username',[
36
('GitHub', 'ppfeister'),
37
('GitHub', 'sherlock-project'),
38
('Docker Hub', 'ppfeister'),
39
('Docker Hub', 'sherlock'),
40
])
41
def test_known_positives_via_status_code(self, sites_info, site, username):
42
assert simple_query(sites_info=sites_info, site=site, username=username) is QueryStatus.CLAIMED
43
44
45
# Known positives should only use sites trusted to be reliable and unchanging
46
@pytest.mark.parametrize('site,username',[
47
('Keybase', 'blue'),
48
('devRant', 'blue'),
49
])
50
def test_known_positives_via_response_url(self, sites_info, site, username):
51
assert simple_query(sites_info=sites_info, site=site, username=username) is QueryStatus.CLAIMED
52
53
54
# Randomly generate usernames of high length and test for positive availability
55
# Randomly generated usernames should be simple alnum for simplicity and high
56
# compatibility. Several attempts may be made ~just in case~ a real username is
57
# generated.
58
@pytest.mark.parametrize('site,random_len',[
59
('GitLab', 255),
60
('Codecademy', 30)
61
])
62
def test_likely_negatives_via_message(self, sites_info, site, random_len):
63
num_attempts: int = 3
64
attempted_usernames: list[str] = []
65
status: QueryStatus = QueryStatus.CLAIMED
66
for i in range(num_attempts):
67
acceptable_types = string.ascii_letters + string.digits
68
random_handle = ''.join(random.choice(acceptable_types) for _ in range (random_len))
69
attempted_usernames.append(random_handle)
70
status = simple_query(sites_info=sites_info, site=site, username=random_handle)
71
if status is QueryStatus.AVAILABLE:
72
break
73
assert status is QueryStatus.AVAILABLE, f"Could not validate available username after {num_attempts} attempts with randomly generated usernames {attempted_usernames}."
74
75
76
# Randomly generate usernames of high length and test for positive availability
77
# Randomly generated usernames should be simple alnum for simplicity and high
78
# compatibility. Several attempts may be made ~just in case~ a real username is
79
# generated.
80
@pytest.mark.parametrize('site,random_len',[
81
('GitHub', 39),
82
('Docker Hub', 30)
83
])
84
def test_likely_negatives_via_status_code(self, sites_info, site, random_len):
85
num_attempts: int = 3
86
attempted_usernames: list[str] = []
87
status: QueryStatus = QueryStatus.CLAIMED
88
for i in range(num_attempts):
89
acceptable_types = string.ascii_letters + string.digits
90
random_handle = ''.join(random.choice(acceptable_types) for _ in range (random_len))
91
attempted_usernames.append(random_handle)
92
status = simple_query(sites_info=sites_info, site=site, username=random_handle)
93
if status is QueryStatus.AVAILABLE:
94
break
95
assert status is QueryStatus.AVAILABLE, f"Could not validate available username after {num_attempts} attempts with randomly generated usernames {attempted_usernames}."
96
97
98
def test_username_illegal_regex(sites_info):
99
site: str = 'BitBucket'
100
invalid_handle: str = '*#$Y&*JRE'
101
pattern = re.compile(sites_info[site]['regexCheck'])
102
# Ensure that the username actually fails regex before testing sherlock
103
assert pattern.match(invalid_handle) is None
104
assert simple_query(sites_info=sites_info, site=site, username=invalid_handle) is QueryStatus.ILLEGAL
105
106
107