Skip to content

Commit 67258b5

Browse files
committed
Adapt for online testing
When using tox, pass `-e offline` to exclude online tests. When using pytest, pass `-m "not online"` to do the same.
1 parent d467758 commit 67258b5

File tree

4 files changed

+78
-63
lines changed

4 files changed

+78
-63
lines changed

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
addopts = --strict-markers
3+
markers =
4+
online: mark tests are requiring interest access.

tests/test_manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def test_validate_manifest_against_local_schema():
1919
validate(instance=jsondat, schema=schemadat)
2020

2121

22+
@pytest.mark.online
2223
def test_validate_manifest_against_remote_schema(remote_schema):
2324
"""Ensures that the manifest matches the remote schema, so as to not unexpectedly break clients."""
2425
json_relative: str = '../sherlock/resources/data.json'

tests/test_probes.py

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,77 +19,80 @@ def simple_query(sites_info: dict, site: str, username: str) -> QueryStatus:
1919
)[site]['status'].status
2020

2121

22-
# Known positives should only use sites trusted to be reliable and unchanging
23-
@pytest.mark.parametrize('site,username',[
24-
('GitLab', 'ppfeister'),
25-
('AllMyLinks', 'blue'),
26-
])
27-
def test_known_positives_via_message(sites_info, site, username):
28-
assert simple_query(sites_info=sites_info, site=site, username=username) is QueryStatus.CLAIMED
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
2932

3033

31-
# Known positives should only use sites trusted to be reliable and unchanging
32-
@pytest.mark.parametrize('site,username',[
33-
('GitHub', 'ppfeister'),
34-
('GitHub', 'sherlock-project'),
35-
('Docker Hub', 'ppfeister'),
36-
('Docker Hub', 'sherlock'),
37-
])
38-
def test_known_positives_via_status_code(sites_info, site, username):
39-
assert simple_query(sites_info=sites_info, site=site, username=username) is QueryStatus.CLAIMED
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
4043

4144

42-
# Known positives should only use sites trusted to be reliable and unchanging
43-
@pytest.mark.parametrize('site,username',[
44-
('BodyBuilding', 'blue'),
45-
('labpentestit', 'CSV'),
46-
])
47-
def test_known_positives_via_response_url(sites_info, site, username):
48-
assert simple_query(sites_info=sites_info, site=site, username=username) is QueryStatus.CLAIMED
45+
# Known positives should only use sites trusted to be reliable and unchanging
46+
@pytest.mark.parametrize('site,username',[
47+
('BodyBuilding', 'blue'),
48+
('labpentestit', 'CSV'),
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
4952

5053

51-
# Randomly generate usernames of high length and test for positive availability
52-
# Randomly generated usernames should be simple alnum for simplicity and high
53-
# compatibility. Several attempts may be made ~just in case~ a real username is
54-
# generated.
55-
@pytest.mark.parametrize('site,random_len',[
56-
('GitLab', 255),
57-
('Codecademy', 30)
58-
])
59-
def test_likely_negatives_via_message(sites_info, site, random_len):
60-
num_attempts: int = 3
61-
attempted_usernames: list[str] = []
62-
status: QueryStatus = QueryStatus.CLAIMED
63-
for i in range(num_attempts):
64-
acceptable_types = string.ascii_letters + string.digits
65-
random_handle = ''.join(random.choice(acceptable_types) for _ in range (random_len))
66-
attempted_usernames.append(random_handle)
67-
status = simple_query(sites_info=sites_info, site=site, username=random_handle)
68-
if status is QueryStatus.AVAILABLE:
69-
break
70-
assert status is QueryStatus.AVAILABLE, f"Could not validate available username after {num_attempts} attempts with randomly generated usernames {attempted_usernames}."
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}."
7174

7275

73-
# Randomly generate usernames of high length and test for positive availability
74-
# Randomly generated usernames should be simple alnum for simplicity and high
75-
# compatibility. Several attempts may be made ~just in case~ a real username is
76-
# generated.
77-
@pytest.mark.parametrize('site,random_len',[
78-
('GitHub', 39),
79-
('Docker Hub', 30)
80-
])
81-
def test_likely_negatives_via_status_code(sites_info, site, random_len):
82-
num_attempts: int = 3
83-
attempted_usernames: list[str] = []
84-
status: QueryStatus = QueryStatus.CLAIMED
85-
for i in range(num_attempts):
86-
acceptable_types = string.ascii_letters + string.digits
87-
random_handle = ''.join(random.choice(acceptable_types) for _ in range (random_len))
88-
attempted_usernames.append(random_handle)
89-
status = simple_query(sites_info=sites_info, site=site, username=random_handle)
90-
if status is QueryStatus.AVAILABLE:
91-
break
92-
assert status is QueryStatus.AVAILABLE, f"Could not validate available username after {num_attempts} attempts with randomly generated usernames {attempted_usernames}."
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}."
9396

9497

9598
def test_username_illegal_regex(sites_info):

tox.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ commands =
2121
coverage run --source=sherlock --module pytest -v
2222
coverage report --show-missing
2323

24+
[testenv:offline]
25+
deps =
26+
jsonschema
27+
pytest
28+
commands =
29+
pytest -v -m "not online"
30+
2431
[testenv:lint]
2532
description = Lint with Ruff
2633
deps =

0 commit comments

Comments
 (0)