Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
820 B
Python
30 lines
820 B
Python
"""Unit tests for TOTP secret sanitization."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
SRC = Path(__file__).resolve().parent.parent / "src"
|
|
sys.path.insert(0, str(SRC))
|
|
|
|
from totp_utils import sanitize_totp_secret, validate_totp_secret # noqa: E402
|
|
|
|
|
|
def test_sanitize_strips_separators() -> None:
|
|
assert sanitize_totp_secret("jbsw y3dp-ehpk3pxp") == "JBSWY3DPEHPK3PXP"
|
|
|
|
|
|
def test_sanitize_maps_zero_one() -> None:
|
|
assert sanitize_totp_secret("JBSW03DP") == "JBSWO3DP"
|
|
|
|
|
|
def test_validate_rejects_invalid_chars() -> None:
|
|
with pytest.raises(ValueError, match="not valid Base32"):
|
|
validate_totp_secret("not-valid-secret!")
|
|
|
|
|
|
def test_validate_accepts_standard_secret() -> None:
|
|
assert validate_totp_secret("JBSWY3DPEHPK3PXP") == "JBSWY3DPEHPK3PXP"
|