Beispiel #1
0
def verify_token_is_not_valid(auth: BaseAuthentication,
                              token: str,
                              ttype: Optional[str] = None) -> None:
    unpacked_token = auth.verify_token(token, token_type=ttype)
    assert not unpacked_token[0]
    assert unpacked_token[1] is None
    assert unpacked_token[2] is None
    assert unpacked_token[3] is None

    with pytest.raises(Exception):
        auth.verify_token(token, token_type=ttype, raiseErrors=True)
Beispiel #2
0
def verify_token_is_not_valid(auth: BaseAuthentication,
                              token: str,
                              ttype: Optional[str] = None) -> None:
    unpacked_token = auth.verify_token(token, token_type=ttype)
    assert not unpacked_token[0]
    assert unpacked_token[1] is None
    assert unpacked_token[2] is None
    assert unpacked_token[3] is None

    try:
        auth.verify_token(token, token_type=ttype, raiseErrors=True)
        pytest.fail("No exception raised")  # pragma: no cover
    except BaseException:
        pass
Beispiel #3
0
def verify_token_is_valid(auth: BaseAuthentication,
                          token: str,
                          ttype: Optional[str] = None) -> None:
    unpacked_token = auth.verify_token(token, token_type=ttype)
    assert unpacked_token[0]
    assert unpacked_token[1] is not None
    assert unpacked_token[2] is not None
    assert unpacked_token[3] is not None
Beispiel #4
0
    def is_session_user_admin(request: FlaskRequest,
                              auth: BaseAuthentication) -> bool:
        if not request:
            return False

        _, token = HTTPTokenAuth.get_authorization_token(
            allow_access_token_parameter=False)
        _, _, _, user = auth.verify_token(token)

        return auth.is_admin(user)