async def test_OIDCUser_disabled(): mock_request = mock.MagicMock(spec=Request) mock_request.headers = {"Authorization": "Bearer creds"} async def mock_introspect_token(client, token): return {"wrong_data": "wrong_data"} openid_bearer = OIDCUser("openid_url", "id", "secret", enabled=False) openid_bearer.openid_config = OIDCConfig.parse_obj(discovery) openid_bearer.introspect_token = mock_introspect_token # type:ignore result = await openid_bearer(mock_request) assert result is None
async def test_OIDCUser_no_creds_no_error(): mock_request = mock.MagicMock(spec=Request) mock_request.headers = {} async def mock_introspect_token(client, token): return {"wrong_data": "wrong_data"} openid_bearer = OIDCUser("openid_url", "id", "secret", auto_error=False) openid_bearer.openid_config = OIDCConfig.parse_obj(discovery) openid_bearer.introspect_token = mock_introspect_token # type:ignore result = await openid_bearer(mock_request, None) # type:ignore assert result is None
async def test_OIDCUser_invalid(): mock_request = mock.MagicMock(spec=Request) mock_request.headers = {"Authorization": "Bearer creds"} async def mock_introspect_token(client, token): return {"wrong_data": "wrong_data"} openid_bearer = OIDCUser("openid_url", "id", "secret") openid_bearer.openid_config = OIDCConfig.parse_obj(discovery) openid_bearer.introspect_token = mock_introspect_token # type:ignore with pytest.raises(HTTPException) as exception: await openid_bearer(mock_request) assert exception.value.status_code == 401
async def test_OIDCUser_with_token(): mock_request = mock.MagicMock(spec=Request) mock_request.headers = {"Authorization": "Bearer creds"} async def mock_introspect_token(client, token): return user_info_matching openid_bearer = OIDCUser("openid_url", "id", "secret") openid_bearer.openid_config = OIDCConfig.parse_obj(discovery) openid_bearer.introspect_token = mock_introspect_token # type:ignore result = await openid_bearer(mock_request, token="creds") # noqa: S106 assert result == user_info_matching