Save progress

This commit is contained in:
Istvan Ruzman
2020-08-13 09:17:20 +02:00
parent 93193ee18d
commit 6023ec948a
5 changed files with 147 additions and 62 deletions

View File

@@ -11,6 +11,8 @@ import pytest
# def test_valid_header(header):
# utils.parse_header(header)
SECRET = b"secret"
@pytest.mark.parametrize(
"header",
@@ -24,3 +26,53 @@ import pytest
def test_invalid_header(header):
with pytest.raises(utils.PacketError):
utils.parse_header(header)
@pytest.mark.parametrize(
"plaintext, obfuscated, authenticator",
[
(
b"short_password",
"ed9b49281f9de8edefae1b09b04beb86",
"7b19486d8372b8c136ccf2444d0a5b2c",
),
(
b"superlongpassword_exeeding_16_bytes",
"1f123e277869997fdfb93f6df037024463918d29064c9fcd5831c57dccd9308ac6b835e6d8f70995d1498a6c5a2a5b71",
"12441ce350ce269c04f650f7923058e1",
),
],
)
def test_password(plaintext, obfuscated, authenticator):
obfuscated = bytes.fromhex(obfuscated)
authenticator = bytes.fromhex(authenticator)
encoded = utils.password_encode(SECRET, authenticator, plaintext)
assert len(encoded) == len(obfuscated)
assert encoded == obfuscated
decoded = utils.password_decode(SECRET, authenticator, encoded)
plaintext_str = plaintext.decode("utf-8")
assert len(decoded) == len(plaintext_str)
assert decoded == plaintext_str
assert utils.validate_pap_password(
SECRET, authenticator, encoded, plaintext
)
@pytest.mark.parametrize(
"plaintext, chap, challenge",
[
(
b"short_password",
bytes.fromhex("2302a92821f675a52df8e5a3b10e49b0ab"),
b"1234567890ABCDEF",
),
],
)
def test_chap_password(plaintext, chap, challenge):
chapid = chap[:1]
encoded = utils.create_chap_password(chapid, challenge, plaintext)
assert len(encoded) == len(chap)
assert encoded == chap
assert utils.validate_chap_password(chapid, challenge, chap, plaintext)