예제 #1
0
 def test_validation_signature(self, signer: Signer, mocker):
     with pytest.raises(BadToken) as exc:
         signer.validate(
             signer.sign("value"),
             signature_validator=mocker.Mock(return_value=False),
         )
     assert str(exc.value) == "Signatures do not match"
예제 #2
0
 def test_validation_timeout(self, signer: Signer, mocker):
     with pytest.raises(BadToken) as exc:
         signer.validate(
             signer.sign("value"),
             timestamp_validator=mocker.Mock(return_value=False),
         )
     assert str(exc.value) == "Token has expired"
예제 #3
0
 def test_basic_signer_signature(self, signer: Signer):
     value = "foo"
     token = signer.sign(value)
     assert len(token.split(signer.sep)) == 3
     assert token != value
     assert (value == signer.validate(token=token, max_age=100) ==
             signer.validate(token=token) == signer.validate(
                 token=token, max_age=timedelta(seconds=100)))
예제 #4
0
def signer():
    return Signer(key="fake")
예제 #5
0
 def test_bad_separator(self):
     with pytest.raises(ValueError) as exc:
         Signer(key="fake", sep="a")
     assert str(exc.value).startswith("Unsafe Signer separator")
예제 #6
0
 def test_validation_token_parts(self, signer: Signer):
     with pytest.raises(BadToken) as exc:
         signer.validate(token=signer.sep.join(["has", "sep"]))
     assert str(exc.value) == "Invalid token structure"
예제 #7
0
 def test_validation_token_structure(self, signer: Signer):
     with pytest.raises(BadToken) as exc:
         signer.validate(token="nosep")
     assert str(exc.value) == "Separator not found in token"