diff --git a/poetry.lock b/poetry.lock index 86759e5..910ade4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -742,7 +742,6 @@ files = [ {file = "psycopg2_binary-2.9.9-cp311-cp311-win32.whl", hash = "sha256:dc4926288b2a3e9fd7b50dc6a1909a13bbdadfc67d93f3374d984e56f885579d"}, {file = "psycopg2_binary-2.9.9-cp311-cp311-win_amd64.whl", hash = "sha256:b76bedd166805480ab069612119ea636f5ab8f8771e640ae103e05a4aae3e417"}, {file = "psycopg2_binary-2.9.9-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:8532fd6e6e2dc57bcb3bc90b079c60de896d2128c5d9d6f24a63875a95a088cf"}, - {file = "psycopg2_binary-2.9.9-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:b0605eaed3eb239e87df0d5e3c6489daae3f7388d455d0c0b4df899519c6a38d"}, {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f8544b092a29a6ddd72f3556a9fcf249ec412e10ad28be6a0c0d948924f2212"}, {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2d423c8d8a3c82d08fe8af900ad5b613ce3632a1249fd6a223941d0735fce493"}, {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2e5afae772c00980525f6d6ecf7cbca55676296b580c0e6abb407f15f3706996"}, @@ -751,8 +750,6 @@ files = [ {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:cb16c65dcb648d0a43a2521f2f0a2300f40639f6f8c1ecbc662141e4e3e1ee07"}, {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:911dda9c487075abd54e644ccdf5e5c16773470a6a5d3826fda76699410066fb"}, {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:57fede879f08d23c85140a360c6a77709113efd1c993923c59fde17aa27599fe"}, - {file = "psycopg2_binary-2.9.9-cp312-cp312-win32.whl", hash = "sha256:64cf30263844fa208851ebb13b0732ce674d8ec6a0c86a4e160495d299ba3c93"}, - {file = "psycopg2_binary-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:81ff62668af011f9a48787564ab7eded4e9fb17a4a6a74af5ffa6a457400d2ab"}, {file = "psycopg2_binary-2.9.9-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:2293b001e319ab0d869d660a704942c9e2cce19745262a8aba2115ef41a0a42a"}, {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:03ef7df18daf2c4c07e2695e8cfd5ee7f748a1d54d802330985a78d2a5a6dca9"}, {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0a602ea5aff39bb9fac6308e9c9d82b9a35c2bf288e184a816002c9fae930b77"}, @@ -1133,7 +1130,7 @@ requests = "^2.31.0" type = "git" url = "https://github.com/cfpb/regtech-api-commons.git" reference = "HEAD" -resolved_reference = "741f6c6e956276f59924a497df8a03609eb82a62" +resolved_reference = "a1fb647c2fa13c8baace6029f89f15a1828071f8" [[package]] name = "requests" diff --git a/src/routers/admin.py b/src/routers/admin.py index 62b3886..6aea3bb 100644 --- a/src/routers/admin.py +++ b/src/routers/admin.py @@ -7,8 +7,8 @@ from regtech_api_commons.api import Router from entities.models import UserProfile -from regtech_api_commons.models.auth import AuthenticatedUser -from regtech_api_commons.oauth2.oauth2_admin import OAuth2Admin +from regtech_api_commons.models import RegTechUser +from regtech_api_commons.oauth2 import OAuth2Admin from config import kc_settings router = Router() @@ -16,10 +16,10 @@ oauth2_admin = OAuth2Admin(kc_settings) -@router.get("/me/", response_model=AuthenticatedUser) +@router.get("/me/", response_model=RegTechUser) @requires("authenticated") def get_me(request: Request): - return request.user + return oauth2_admin.get_user(request.user.id) @router.put("/me/", status_code=HTTPStatus.ACCEPTED, dependencies=[Depends(check_domain)]) diff --git a/tests/api/conftest.py b/tests/api/conftest.py index 6de83c8..8e35aea 100644 --- a/tests/api/conftest.py +++ b/tests/api/conftest.py @@ -4,7 +4,7 @@ from fastapi import FastAPI from pytest_mock import MockerFixture from starlette.authentication import AuthCredentials, UnauthenticatedUser -from regtech_api_commons.models.auth import AuthenticatedUser +from regtech_api_commons.models import AuthenticatedUser from entities.models import ( FinancialInstitutionDao, FinancialInstitutionDomainDao, @@ -37,7 +37,6 @@ def auth_mock(mocker: MockerFixture) -> Mock: @pytest.fixture def authed_user_mock(auth_mock: Mock) -> Mock: claims = { - "id": "test_user_id", "name": "test", "preferred_username": "test_user", "email": "test@local.host", diff --git a/tests/api/routers/test_admin_api.py b/tests/api/routers/test_admin_api.py index 875e7c0..7a549af 100644 --- a/tests/api/routers/test_admin_api.py +++ b/tests/api/routers/test_admin_api.py @@ -5,7 +5,7 @@ from pytest_mock import MockerFixture from starlette.authentication import AuthCredentials -from regtech_api_commons.models.auth import AuthenticatedUser +from regtech_api_commons.models import RegTechUser, AuthenticatedUser class TestAdminApi: @@ -15,13 +15,16 @@ def test_get_me_unauthed(self, app_fixture: FastAPI, unauthed_user_mock: Mock): assert res.status_code == 403 def test_get_me_authed(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock): + get_user_mock = mocker.patch("regtech_api_commons.oauth2.OAuth2Admin.get_user") + get_user_mock.return_value = authed_user_mock.return_value[1] client = TestClient(app_fixture) res = client.get("/v1/admin/me") + get_user_mock.assert_called_once_with("testuser123") assert res.status_code == 200 assert res.json().get("name") == "test" assert res.json().get("institutions") == [] - def test_get_me_authed_with_institutions(self, app_fixture: FastAPI, auth_mock: Mock): + def test_get_me_authed_with_institutions(self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock: Mock): claims = { "name": "test", "preferred_username": "test_user", @@ -33,6 +36,8 @@ def test_get_me_authed_with_institutions(self, app_fixture: FastAPI, auth_mock: AuthCredentials(["authenticated"]), AuthenticatedUser.from_claim(claims), ) + get_user_mock = mocker.patch("regtech_api_commons.oauth2.OAuth2Admin.get_user") + get_user_mock.return_value = RegTechUser.from_claim(claims) client = TestClient(app_fixture) res = client.get("/v1/admin/me") assert res.status_code == 200