Ejemplo n.º 1
0
def test_encode_eight_nul_bytes_with_zero_timestamp():
    key = unhexlify(
        "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974")
    branca = Branca(key)

    branca._nonce = unhexlify(
        "beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef")
    token = branca.encode(b"\x00\x00\x00\x00\x00\x00\x00\x00", timestamp=0)

    assert token == "1jIBheHbDdkCDFQmtgw4RUZeQoOJgGwTFJSpwOAk3XYpJJr52DEpILLmmwYl4tjdSbbNqcF1"
Ejemplo n.º 2
0
def test_encode_non_utf8_payload():
    key = unhexlify(
        "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974")
    branca = Branca(key)

    branca._nonce = unhexlify(
        "beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef")
    token = branca.encode(b"", timestamp=0)

    assert token == "4sfD0vPFhIif8cy4nB3BQkHeJqkOkDvinI4zIhMjYX4YXZU5WIq9ycCVjGzB5"
Ejemplo n.º 3
0
def test_encode_hello_world_with_november_27_timestamp():
    key = unhexlify(
        "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974")
    branca = Branca(key)

    branca._nonce = unhexlify(
        "beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef")
    token = branca.encode("Hello world!", timestamp=123206400)

    assert token == "875GH23U0Dr6nHFA63DhOyd9LkYudBkX8RsCTOMz5xoYAMw9sMd5QwcEqLDRnTDHPenOX7nP2trlT"
Ejemplo n.º 4
0
def test_encode_hello_world_with_max_timestamp():
    key = unhexlify(
        "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974")
    branca = Branca(key)

    branca._nonce = unhexlify(
        "beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef")
    token = branca.encode("Hello world!", timestamp=4294967295)

    assert token == "89i7YCwu5tWAJNHUDdmIqhzOi5hVHOd4afjZcGMcVmM4enl4yeLiDyYv41eMkNmTX6IwYEFErCSqr"
Ejemplo n.º 5
0
def test_encode_hello_world_with_zero_timestamp():
    key = unhexlify(
        "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974")
    branca = Branca(key)

    branca._nonce = unhexlify(
        "beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef")
    token = branca.encode("Hello world!", timestamp=0)

    assert token == "870S4BYxgHw0KnP3W9fgVUHEhT5g86vJ17etaC5Kh5uIraWHCI1psNQGv298ZmjPwoYbjDQ9chy2z"
Ejemplo n.º 6
0
def test_should_throw_when_expired():
    key = unhexlify(
        "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974")
    branca = Branca(key)

    branca._nonce = unhexlify(
        "0102030405060708090a0b0c0102030405060708090a0b0c")
    token = branca.encode(b"Hello world!", timestamp=123206400)

    with pytest.raises(RuntimeError):
        branca.decode(token, 3600)
Ejemplo n.º 7
0
def test_encode_eight_nul_bytes_with_november_27_timestamp():
    key = unhexlify(
        "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974")
    branca = Branca(key)

    branca._nonce = unhexlify(
        "beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef")
    token = branca.encode(b"\x00\x00\x00\x00\x00\x00\x00\x00",
                          timestamp=123206400)

    assert token == "1jJDJOEjuwVb9Csz1Ypw1KBWSkr0YDpeBeJN6NzJWx1VgPLmcBhu2SbkpQ9JjZ3nfUf7Aytp"
Ejemplo n.º 8
0
def test_encode_eight_nul_bytes_with_zero_timestamp():
    key = unhexlify(
        "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974")
    branca = Branca(key)

    branca._nonce = unhexlify(
        "beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef")
    token = branca.encode(b"\x00\x00\x00\x00\x00\x00\x00\x00",
                          timestamp=4294967295)

    assert token == "1jrx6DUu5q06oxykef2e2ZMyTcDRTQot9ZnwgifUtzAphGtjsxfbxXNhQyBEOGtpbkBgvIQx"