from salt import hash_password, main def test_main_supports_hash_shortcut() -> None: assert main(["secret"]) == 0 def test_main_verify_round_trip() -> None: salt, hashed = hash_password("secret-value") assert main(["verify", "secret-value", salt, hashed]) == 0 assert main(["verify", "wrong", salt, hashed]) == 1 def test_main_hash_with_algorithm_pbkdf2() -> None: """Test hash command with --algorithm pbkdf2.""" assert main(["hash", "--algorithm", "pbkdf2", "test-password"]) == 0 def test_main_hash_with_algorithm_argon2() -> None: """Test hash command with --algorithm argon2.""" assert main(["hash", "--algorithm", "argon2", "test-password"]) == 0 def test_main_hash_with_algorithm_bcrypt() -> None: """Test hash command with --algorithm bcrypt.""" assert main(["hash", "--algorithm", "bcrypt", "test-password"]) == 0 def test_main_verify_with_algorithm() -> None: """Test verify command with --algorithm option.""" # Test with each algorithm for algo in ["pbkdf2", "argon2", "bcrypt"]: salt, hashed = hash_password("test-pw", algorithm=algo) assert main(["verify", "--algorithm", algo, "test-pw", salt, hashed]) == 0 assert main(["verify", "--algorithm", algo, "wrong", salt, hashed]) == 1 def test_main_hash_algorithm_shortcut() -> None: """Test shortcut syntax with --algorithm option.""" # Should support: python3 salt.py --algorithm argon2 mypassword assert main(["--algorithm", "argon2", "test-password"]) == 0