from telegram_gateway_verification.webhook import (
    compute_signature,
    verify_callback_signature,
)


def test_compute_signature_and_verify_success() -> None:
    token = "test_token"
    timestamp = "1710000000"
    body = b'{"request_id":"abc"}'

    signature = compute_signature(token, timestamp, body)

    assert verify_callback_signature(
        api_token=token,
        timestamp_header=timestamp,
        signature_header=signature,
        raw_body=body,
        now=1710000005,
    )


def test_verify_signature_fails_on_expired_timestamp() -> None:
    token = "test_token"
    timestamp = "1710000000"
    body = b"{}"
    signature = compute_signature(token, timestamp, body)

    assert not verify_callback_signature(
        api_token=token,
        timestamp_header=timestamp,
        signature_header=signature,
        raw_body=body,
        max_age_seconds=30,
        now=1710000100,
    )


def test_verify_signature_fails_on_mismatch() -> None:
    assert not verify_callback_signature(
        api_token="token",
        timestamp_header="1710000000",
        signature_header="deadbeef",
        raw_body=b"{}",
        now=1710000001,
    )
