-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restrict FI data retrieval (#120)
closes #111
- Loading branch information
1 parent
236c19f
commit b469f4a
Showing
7 changed files
with
226 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,26 @@ def test_get_institutions_authed( | |
assert res.status_code == 200 | ||
assert res.json()[0].get("name") == "Test Bank 123" | ||
|
||
def test_get_institutions_authed_not_admin( | ||
self, | ||
mocker: MockerFixture, | ||
app_fixture: FastAPI, | ||
auth_mock: Mock, | ||
): | ||
claims = { | ||
"name": "test", | ||
"preferred_username": "test_user", | ||
"email": "[email protected]", | ||
"sub": "testuser123", | ||
} | ||
auth_mock.return_value = ( | ||
AuthCredentials(["manage-account", "authenticated"]), | ||
AuthenticatedUser.from_claim(claims), | ||
) | ||
client = TestClient(app_fixture) | ||
res = client.get("/v1/institutions/") | ||
assert res.status_code == 403 | ||
|
||
def test_create_institution_unauthed(self, app_fixture: FastAPI, unauthed_user_mock: Mock): | ||
client = TestClient(app_fixture) | ||
res = client.post("/v1/institutions/", json={"name": "testName", "lei": "testLei"}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
from typing import Tuple | ||
from fastapi import Request | ||
import pytest | ||
|
||
from pytest_mock import MockerFixture | ||
from starlette.authentication import AuthCredentials | ||
from regtech_api_commons.models import AuthenticatedUser, RegTechUser | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
|
@@ -10,3 +14,26 @@ def setup(mocker: MockerFixture): | |
mocked_engine.return_value = MockedEngine.return_value | ||
mocker.patch("fastapi.security.OAuth2AuthorizationCodeBearer") | ||
mocker.patch("entities.engine.get_session") | ||
|
||
|
||
@pytest.fixture | ||
def mock_auth() -> Tuple[AuthCredentials, RegTechUser]: | ||
creds = AuthCredentials(["manage-account", "authenticated"]) | ||
user = AuthenticatedUser.from_claim( | ||
{ | ||
"name": "test", | ||
"preferred_username": "test_user", | ||
"email": "[email protected]", | ||
"sub": "testuser123", | ||
"institutions": ["TESTBANK123"], | ||
} | ||
) | ||
return creds, user | ||
|
||
|
||
@pytest.fixture | ||
def mock_request(mocker: MockerFixture, mock_auth: Tuple[AuthCredentials, RegTechUser]) -> Request: | ||
request: Request = mocker.patch("fastapi.Request").return_value | ||
request.auth = mock_auth[0] | ||
request.user = mock_auth[1] | ||
return request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters