def test_missing_signature( mocker: MockFixture, authenticator: Auth0Authenticator, tokens: Dict[str, str], sign_key: Dict[str, Any], ): mock_valid_time(mocker) with pytest.raises(Exception, match=r"Invalid signature"): authenticator._get_payload(tokens["noSignature"], sign_key)
def test_invalid_audience( mocker: MockFixture, authenticator: Auth0Authenticator, access_token: str, sign_key: Dict[str, Any], ): mock_valid_time(mocker) authenticator.audience = "SomeRandomAudience" with pytest.raises(Exception, match=r"Invalid claims"): authenticator._get_payload(access_token, sign_key)
def test_expired_token( mocker: MockFixture, authenticator: Auth0Authenticator, access_token: str, sign_key: Dict[str, Any], ): datetime_mock = mocker.patch("jose.jwt.datetime") datetime_mock.utcnow = Mock(return_value=datetime(2050, 1, 1)) authenticator.audience = "SomeRandomAudience" with pytest.raises(Exception, match=r"Token is expired"): authenticator._get_payload(access_token, sign_key)
def test_valid_token( mocker: MockFixture, authenticator: Auth0Authenticator, access_token: str, sign_key: Dict[str, Any], ): mock_valid_time(mocker) payload = authenticator._get_payload(access_token, sign_key) assert payload != {}
def test_testing_accepts_expired_token( mocker: MockFixture, authenticator: Auth0Authenticator, access_token: str, sign_key: Dict[str, Any], ): authenticator.testing = True datetime_mock = mocker.patch("jose.jwt.datetime") datetime_mock.utcnow = Mock(return_value=datetime(2050, 1, 1)) payload = authenticator._get_payload(access_token, sign_key) assert payload is not None