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
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
def test_encode_payload_types() -> None: """Test encode `payload` parameter types.""" nsjwt.encode('secret', {}) nsjwt.encode('secret', MyMapping())
def test_encode_secret_types() -> None: """Test encode `secret` parameter types.""" nsjwt.encode(b'secret', {}) nsjwt.encode('secret', {}) nsjwt.encode(bytearray(b'secret'), {})
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