pull/2127/head
Paul Pfeister 7 months ago
parent 08a12912c7
commit 2b24cca340
No known key found for this signature in database
GPG Key ID: 70D33A96CBD7A994

@ -6,3 +6,7 @@
# Changes made to these items without code owner approval may negatively
# impact packaging pipelines. Code owners may need time to verify or adapt.
/pyproject.toml @ppfeister @sdushantha
### REGRESSION
/tox.ini @ppfeister
/tests/ @ppfeister

@ -1,4 +1,6 @@
import os
import json
import urllib
import pytest
from sherlock.sites import SitesInformation
@ -12,3 +14,10 @@ def sites_info():
sites_obj = SitesInformation(data_file_path=os.path.join(os.path.dirname(__file__), "../sherlock/resources/data.json"))
sites_iterable = {site.name: site.information for site in sites_obj}
yield sites_iterable
@pytest.fixture(scope="session")
def remote_schema():
schema_url: str = 'https://raw.githubusercontent.com/sherlock-project/sherlock/master/sherlock/resources/data.schema.json'
with urllib.request.urlopen(schema_url) as remoteschema:
schemadat = json.load(remoteschema)
yield schemadat

@ -4,11 +4,17 @@ import subprocess
class Interactives:
def run_cli(args: str = "") -> str:
"""Pass arguments to Sherlock as a normal user on the command line"""
command = [f"sherlock {args}"]
proc_out = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
return proc_out.decode()
proc_out: str = ""
try:
proc_out = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
return proc_out.decode()
except subprocess.CalledProcessError as e:
raise InteractivesSubprocessError(e.output.decode())
def walk_sherlock_for_files_with(pattern: str) -> list[str]:
"""Check all files within the Sherlock package for matching patterns"""
pattern: re.Pattern = re.compile(pattern)
matching_files: list[str] = []
for root, dirs, files in os.walk("sherlock"):
@ -20,3 +26,6 @@ class Interactives:
if pattern.search(f.read()):
matching_files.append(file_path)
return matching_files
class InteractivesSubprocessError(Exception):
pass

@ -3,21 +3,31 @@ import json
import pytest
from jsonschema import validate
def validate_json(jsonfile: str, schemafile: str) -> bool:
with open(jsonfile, 'r') as f:
def test_validate_manifest_against_local_schema():
"""Ensures that the manifest matches the local schema, for situations where the schema is being changed."""
json_relative: str = '../sherlock/resources/data.json'
schema_relative: str = '../sherlock/resources/data.schema.json'
json_path: str = os.path.join(os.path.dirname(__file__), json_relative)
schema_path: str = os.path.join(os.path.dirname(__file__), schema_relative)
with open(json_path, 'r') as f:
jsondat = json.load(f)
with open(schemafile, 'r') as f:
with open(schema_path, 'r') as f:
schemadat = json.load(f)
validate(instance=jsondat, schema=schemadat)
return True
def test_validate_manifest_against_schema():
def test_validate_manifest_against_remote_schema(remote_schema):
"""Ensures that the manifest matches the remote schema, so as to not unexpectedly break clients."""
json_relative: str = '../sherlock/resources/data.json'
schema_relative: str = '../sherlock/resources/data.schema.json'
json_path: str = os.path.join(os.path.dirname(__file__), json_relative)
schema_path: str = os.path.join(os.path.dirname(__file__), schema_relative)
validate_json(jsonfile=json_path, schemafile=schema_path)
with open(json_path, 'r') as f:
jsondat = json.load(f)
validate(instance=jsondat, schema=remote_schema)
# Ensure that the expected values are beind returned by the site list
@pytest.mark.parametrize("target_name,target_expected_err_type", [

@ -1,5 +1,8 @@
import pytest
import subprocess
from sherlock import sherlock
from sherlock_interactives import Interactives
from sherlock_interactives import InteractivesSubprocessError
def test_remove_nsfw(sites_obj):
nsfw_target: str = 'Pornhub'
@ -25,9 +28,22 @@ def test_wildcard_username_expansion():
assert sherlock.check_for_parameter('test{?}test') is True
assert sherlock.check_for_parameter('test{.}test') is False
assert sherlock.check_for_parameter('test{}test') is False
assert sherlock.check_for_parameter('testtest') is False
assert sherlock.check_for_parameter('test{?test') is False
assert sherlock.check_for_parameter('test?}test') is False
assert sherlock.multiple_usernames('test{?}test') == ["test_test" , "test-test" , "test.test"]
@pytest.mark.parametrize('cliargs', [
'',
'--site urghrtuight --egiotr',
'--',
])
def test_no_usernames_provided(cliargs):
with pytest.raises(InteractivesSubprocessError, match=r"error: the following arguments are required: USERNAMES"):
Interactives.run_cli(cliargs)
#def test_area(self):
# test_usernames = ["test{?}test" , "test{?feo" , "test"]

Loading…
Cancel
Save