1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
import textwrap
import pytest
import pwndck
from pwndck.processpw import PwndException, get_hashes, get_sha, process_pw
foo_sha = "0BEEC7B5EA3F0FDBC95D0DD47F3C5BC275DA8A33"
foo_key = "0BEEC"
foo_hash = "7B5EA3F0FDBC95D0DD47F3C5BC275DA8A33"
def test_null():
pass
def test_pwndck_null():
get_sha("foo")
def test_get_sha():
assert get_sha("foo") == foo_sha
@pytest.fixture
def requests_fixture(mocker):
response_mock = mocker.Mock()
response_mock.status_code = 200
response_mock.text = textwrap.dedent(
f"""
{foo_hash}:5
"""
)
mocker.patch.object(
pwndck.processpw.requests, "get", return_value=response_mock
)
return response_mock
@pytest.mark.parametrize(
"pw, cnt",
[
("foo", 5),
("bar", 0),
],
)
def test_process_pw_patched(pw, cnt, requests_fixture):
assert process_pw(pw) == cnt
def test_process_pw_exception(requests_fixture):
requests_fixture.status_code = 100
with pytest.raises(PwndException):
process_pw("foo")
@pytest.mark.webtest
def test_get_hashes():
hash_list = get_hashes(foo_key)
assert foo_hash in hash_list
@pytest.mark.webtest
def test_process_pw():
assert process_pw("foo") > 5000
|