Example #1
0
def test_valid_token():
    valid_token = create_token({"typ": "Bearer", "exp": FUTURE_TIMESTAMP})
    assert is_valid(valid_token)

    near_future = utc_timestamp() + 7 * 60
    near_future_token = create_token({"typ": "Bearer", "exp": near_future})
    assert is_valid(near_future_token)
Example #2
0
def test_old_token():
    old_token = create_token({"exp": 1419064452})
    assert not is_valid(old_token)

    # Verify that a token valid for less than 5 min will be considered invalid
    expire_soon_date = utc_timestamp() + 4 * 60
    expire_soon_token = create_token({"exp": expire_soon_date})
    assert not is_valid(expire_soon_token)
Example #3
0
def test_token_str():
    token = ("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhZGFjb3JlLmNvbSI"
             "sImlhdCI6MTUxOTExOTcxMSwiZXhwIjoxNTUwNjU1NzExLCJhdWQiOiJ3d3cuYWR"
             "hY29yZS5jb20iLCJzdWIiOiJ0ZXN0IiwiR2l2ZW5OYW1lIjoiVG90byIsIlN1cm5"
             "hbWUiOiIxMjMiLCJFbWFpbCI6InRvdG9AZXhhbXBsZS5jb20iLCJSb2xlIjoidGV"
             "zdGVyIn0.UERDJuUFh6A30TXIEKbNu6BbDOUCdsLGMKuQS8DfboA")
    payload = get_payload(token)
    expected = {
        "GivenName": "Toto",
        "Email": "*****@*****.**",
        "Role": "tester",
        "iss": "adacore.com",
        "sub": "test",
        "exp": 1550655711,
        "iat": 1519119711,
        "Surname": "123",
        "aud": "www.adacore.com",
    }
    assert payload == expected
    assert not is_valid(token)
Example #4
0
def test_token_str():
    token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhZGFjb3JlLmNvbSI'\
            'sImlhdCI6MTUxOTExOTcxMSwiZXhwIjoxNTUwNjU1NzExLCJhdWQiOiJ3d3cuYWR'\
            'hY29yZS5jb20iLCJzdWIiOiJ0ZXN0IiwiR2l2ZW5OYW1lIjoiVG90byIsIlN1cm5'\
            'hbWUiOiIxMjMiLCJFbWFpbCI6InRvdG9AZXhhbXBsZS5jb20iLCJSb2xlIjoidGV'\
            'zdGVyIn0.UERDJuUFh6A30TXIEKbNu6BbDOUCdsLGMKuQS8DfboA'
    payload = get_payload(token)
    expected = {
        u'GivenName': u'Toto',
        u'Email': u'*****@*****.**',
        u'Role': u'tester',
        u'iss': u'adacore.com',
        u'sub': u'test',
        u'exp': 1550655711,
        u'iat': 1519119711,
        u'Surname': u'123',
        u'aud': u'www.adacore.com'
    }
    assert payload == expected
    assert not is_valid(token)
Example #5
0
def test_exception_pass():
    assert not is_valid("..")
Example #6
0
def test_wrong_token_type():
    badtype_token = create_token({"typ": "badtype", "exp": FUTURE_TIMESTAMP})
    assert not is_valid(badtype_token)
Example #7
0
def test_old_token():
    old_token = create_token({u'typ': u'Bearer', u'exp': 1419064452})
    assert not is_valid(old_token)
Example #8
0
def test_wrong_token_type():
    badtype_token = create_token({
        u'typ': u'badtype',
        u'exp': FUTURE_TIMESTAMP
    })
    assert not is_valid(badtype_token)
Example #9
0
def test_valid_token():
    valid_token = create_token({u'typ': u'Bearer', u'exp': FUTURE_TIMESTAMP})
    assert is_valid(valid_token)