def test_secretlink_serializer_noencryption(app, db):
    """Test that token is not encrypted."""
    with app.app_context():
        s = SecretLinkSerializer()
        t1 = s.create_token(1, dict(recid=1))
        with pytest.raises(BadSignature):
            JSONWebSignatureSerializer('anotherkey').loads(t1)
def test_secretlink_serializer_creation(app, db):
    """Ensure that no two tokens are identical."""
    with app.app_context():
        s = SecretLinkSerializer()
        t1 = s.create_token(98765, dict(recid=4321))
        t2 = s.create_token(98765, dict(recid=4321))
        assert t1 != t2
Пример #3
0
 def test_create_validate(self):
     """Test token creation."""
     s = SecretLinkSerializer()
     t = s.create_token(1234, dict(recid=56789))
     data = s.validate_token(t)
     self.assertEqual(data['id'], 1234)
     self.assertEqual(data['data']['recid'], 56789)
def test_secretlink_serializer_create_validate(app, db):
    """Test token creation."""
    with app.app_context():
        s = SecretLinkSerializer()
        t = s.create_token(1234, dict(recid=56789))
        data = s.validate_token(t)
        assert data['id'] == 1234
        assert data['data']['recid'] == 56789
Пример #5
0
 def test_noencryption(self):
     """Test that token is not encrypted."""
     s = SecretLinkSerializer()
     t1 = s.create_token(1, dict(recid=1))
     self.assertRaises(
         BadSignature,
         JSONWebSignatureSerializer('anotherkey').loads,
         t1
     )
def test_secretlink_factory_creation(app, db):
    """Test token creation."""
    extra_data = dict(recid='1')
    with app.app_context():
        d = datetime.utcnow()+timedelta(days=1)

        t = SecretLinkFactory.create_token(1, extra_data)

        assert SecretLinkSerializer().validate_token(
            t, expected_data=extra_data) is not None
        assert TimedSecretLinkSerializer().validate_token(
            t, expected_data=extra_data) is None

        t1 = SecretLinkFactory.create_token(
            1, extra_data, expires_at=d
        )
        t2 = SecretLinkFactory.create_token(1, extra_data)

        assert SecretLinkSerializer().validate_token(
            t1, expected_data=extra_data) is None
        assert TimedSecretLinkSerializer().validate_token(
            t1, expected_data=extra_data) is not None
        assert t1 != t2
Пример #7
0
 def test_creation(self):
     """Ensure that no two tokens are identical."""
     s = SecretLinkSerializer()
     t1 = s.create_token(98765, dict(recid=4321))
     t2 = s.create_token(98765, dict(recid=4321))
     self.assertNotEqual(t1, t2)