Beispiel #1
0
def test_encode_invalid_payload():
    """Test encode with invalid signature type."""
    secret = 'secret'
    payload = 'not-mapping-payload'
    with pytest.raises(nsjwt.ExpectedMappingError) as exc_info:
        nsjwt.encode(secret, payload)
    assert str(exc_info.value) == (
        'Invalid payload, expected Mapping: not-mapping-payload')
    assert exc_info.type == nsjwt.ExpectedMappingError
Beispiel #2
0
def test_decode_invalid_sig():
    """Test decode with unexpected signature type."""
    secret_encode = 'secret-encode'
    secret_decode = 'secret-decode'
    payload = {'sub': '42', 'name': 'Glenn Jones', 'admin': True}
    with pytest.raises(nsjwt.SignatureMismatchError) as exc_info:
        nsjwt.decode(secret_decode, nsjwt.encode(secret_encode, payload))
    assert str(exc_info.value) == "Invalid signature"
    assert exc_info.type == nsjwt.SignatureMismatchError
Beispiel #3
0
def test_encode_payload_types() -> None:
    """Test encode `payload` parameter types."""
    nsjwt.encode('secret', {})
    nsjwt.encode('secret', MyMapping())
Beispiel #4
0
def test_encode_secret_types() -> None:
    """Test encode `secret` parameter types."""
    nsjwt.encode(b'secret', {})
    nsjwt.encode('secret', {})
    nsjwt.encode(bytearray(b'secret'), {})
Beispiel #5
0
def test_secret_types(secret):
    """Test encode/decode with different types of `secret` parameter."""
    payload = {'sub': '42', 'name': 'Джон Фэи', 'admin': True}
    token = nsjwt.encode(secret, payload)
    assert nsjwt.decode(secret, token) == payload