from pyeudiw.jwt.parse import DecodedJwt
from pyeudiw.tests.jwt import VALID_KID_JWT, VALID_TC_JWT


def test_kid_jwt():
    decoded_jwt = DecodedJwt.parse(VALID_KID_JWT)

    assert decoded_jwt.jwt == VALID_KID_JWT
    assert decoded_jwt.header == {"kid": "123456", "alg": "HS256", "typ": "JWT"}
    assert decoded_jwt.payload == {
        "sub": "1234567890",
        "name": "John Doe",
        "iat": 1516239022,
    }
    assert decoded_jwt.signature == "bjM57L1H4gB60_020lKBVvVEhiYCOeEWGzMVEt-XNjc"


def test_tc_jwt():
    decoded_jwt = DecodedJwt.parse(VALID_TC_JWT)

    assert decoded_jwt.jwt == VALID_TC_JWT
    assert decoded_jwt.header == {
        "trust_chain": [
            "eyJhbGciOiJFUzI1NiIsImtpZCI6ImFrNVBOMGR1WjNCeVlVUkVNMWszWm1RM1RFVnlOSEowWTJWVFlUWk1TSFI0VWsxSVExQk9USEpQU1EiLCJ0eXAiOiJlbnRpdHktc3RhdGVtZW50K2p3dCJ9.eyJleHAiOjE3Mjk5MDQzNDIsImlhdCI6MTcyOTYwNDM0MiwiaXNzIjoiaHR0cHM6Ly9jcmVkZW50aWFsX2lzc3Vlci5leGFtcGxlLm9yZyIsInN1YiI6Imh0dHBzOi8vY3JlZGVudGlhbF9pc3N1ZXIuZXhhbXBsZS5vcmciLCJqd2tzIjp7ImtleXMiOlt7Imt0eSI6IkVDIiwia2lkIjoiYWs1UE4wZHVaM0J5WVVSRU0xazNabVEzVEVWeU5ISjBZMlZUWVRaTVNIUjRVazFJUTFCT1RISlBTUSIsImFsZyI6IkVTMjU2IiwiY3J2IjoiUC0yNTYiLCJ4IjoiYjBIcmV6bTVxN1MzUE96ZVNobU9WRjJVV18zbnJvR0RNWnBaeFhlS1B0USIsInkiOiItME9HV0xnOGNoaVItQndPQ2pZeng1Mm1MZlE1b3BSVjVYQ0lVamlpaVRRIn1dfSwibWV0YWRhdGEiOnsib3BlbmlkX2NyZWRlbnRpYWxfaXNzdWVyIjp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zdC1hbmNob3IuZXhhbXBsZS5vcmcvbGlzdCIsIm9yZ2FuaXphdGlvbl9uYW1lIjoiVEEgZXhhbXBsZSIsImhvbWVwYWdlX3VyaSI6Imh0dHBzOi8vdHJ1c3QtYW5jaG9yLmV4YW1wbGUub3JnL2hvbWUiLCJwb2xpY3lfdXJpIjoiaHR0cHM6Ly90cnVzdC1hbmNob3IuZXhhbXBsZS5vcmcvcG9saWN5IiwibG9nb191cmkiOiJodHRwczovL3RydXN0LWFuY2hvci5leGFtcGxlLm9yZy9zdGF0aWMvbG9nby5zdmciLCJjb250YWN0cyI6WyJ0ZWNoQHRydXN0LWFuY2hvci5leGFtcGxlLm9yZyJdfX0sImNvbnN0cmFpbnRzIjp7Im1heF9wYXRoX2xlbmd0aCI6MX19.MbpXfe_NpPgbdWL_zN30SXA88aWrewaJyMWJFAegNrN-8Vy2umcpq3MQph7Yz3ZTawGgi6OGWX7UTDFOWWmf9w",
        ],
        "alg": "HS256",
        "typ": "JWT",
    }


def test_invalid_jwt():
    invalid_jwt = "eyJ"

    try:
        DecodedJwt.parse(invalid_jwt)
        assert False
    except ValueError:
        assert True
