Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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 != {}
Ejemplo n.º 5
0
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