Exemplo n.º 1
0
def test_verify_exp_in_future(app):
    """Test that token expiry is verified as being in future."""
    payload = dict(
        foo=1, exp=datetime.datetime.utcnow() - datetime.timedelta(seconds=1)
    )
    t = _jwt_encode_dangerous(payload)
    with pytest.raises(jwt.exceptions.ExpiredSignatureError):
        _jwt_decode(t)
Exemplo n.º 2
0
def test_verify_sig(app):
    """Test that token is verified."""
    payload = dict(foo=1)
    t = _jwt_encode(payload)
    old_key = app.secret_key
    try:
        app.secret_key = 'foo'
        with pytest.raises(jwt.exceptions.DecodeError):
            _jwt_decode(t)
    finally:
        app.secret_key = old_key
Exemplo n.º 3
0
def test_verify_exp_present(app):
    """Test that token expiry is verified as being present."""
    payload = dict(foo=1)
    t = _jwt_encode_dangerous(payload)
    with pytest.raises(jwt.exceptions.MissingRequiredClaimError):
        _jwt_decode(t)
Exemplo n.º 4
0
def test_token_has_exp(app):
    """Test that token has exp field in payload."""
    payload = dict(foo=1)
    t = _jwt_encode(payload)
    p = _jwt_decode(t)
    assert 'exp' in p
Exemplo n.º 5
0
def test_token_enc_dec(app):
    """Test basic encoding and decoding of token."""
    payload = dict(foo=1)
    t = _jwt_encode(payload)
    p = _jwt_decode(t)
    assert p['foo'] == 1