def test_with_valid_token(self, app): prefix = app.config["JWT_AUTH_HEADER_PREFIX"] token = "a.nice.token" headers = {"Authorization": f"{prefix} {token}"} with app.test_request_context("/", headers=headers): _token = _get_request_jwt() assert token == _token
def test_without_authorization_http_header(self, request_ctx): with request_ctx("/"): token = _get_request_jwt() assert token is None
def test_with_empty_authorization_http_header(self, request_ctx): with request_ctx("/", headers={"Authorization": ""}): with pytest.raises(JWTError, match="Missing or malformed token"): _get_request_jwt()
def test_without_space_after_prefix(self, request_ctx): headers = {"Authorization": "Bearera.nice.token"} with request_ctx("/", headers=headers): with pytest.raises(JWTError, match="Missing or malformed token"): _get_request_jwt()
def test_with_wrong_prefix(self, request_ctx): headers = {"Authorization": "WRONG a.nice.token"} with request_ctx("/", headers=headers): with pytest.raises(JWTError, match="Unsupported authorization type"): _get_request_jwt()
def test_with_more_than_one_space(self, request_ctx): headers = {"Authorization": "Bearer this is a token with spaces"} with request_ctx("/", headers=headers): with pytest.raises(JWTError, match="The token contains spaces"): _get_request_jwt()