From 60531d453f7cab38b234c58b73e1065ee2265fb3 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 18 Dec 2022 19:37:18 -0800 Subject: [PATCH 1/8] Fix user creation as root --- .../api/v1/endpoints/test_user_endpoints.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/ops/api/v1/endpoints/test_user_endpoints.py b/tests/ops/api/v1/endpoints/test_user_endpoints.py index 128ae4cf78..b65ab374f1 100644 --- a/tests/ops/api/v1/endpoints/test_user_endpoints.py +++ b/tests/ops/api/v1/endpoints/test_user_endpoints.py @@ -159,6 +159,25 @@ def test_create_user( assert response_body == {"id": user.id} assert user.permissions is not None user.delete(db) + + def test_create_user_as_root( + self, + db, + api_client, + root_auth_header, + url, + ) -> None: + auth_header = root_auth_header + body = {"username": "test_user", "password": str_to_b64_str("TestP@ssword9")} + + response = api_client.post(url, headers=auth_header, json=body) + + user = FidesUser.get_by(db, field="username", value=body["username"]) + response_body = json.loads(response.text) + assert HTTP_201_CREATED == response.status_code + assert response_body == {"id": user.id} + assert user.permissions is not None + user.delete(db) def test_create_user_with_name( self, From d3dd9f2cd25be9782b9462df3fbd57f2e30f3ce0 Mon Sep 17 00:00:00 2001 From: Sean Preston Date: Mon, 19 Dec 2022 08:42:31 -0700 Subject: [PATCH 2/8] use correct verify_oauth_client logic --- src/fides/lib/oauth/api/routes/user_endpoints.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fides/lib/oauth/api/routes/user_endpoints.py b/src/fides/lib/oauth/api/routes/user_endpoints.py index 9bbd71634c..7117ebade0 100644 --- a/src/fides/lib/oauth/api/routes/user_endpoints.py +++ b/src/fides/lib/oauth/api/routes/user_endpoints.py @@ -22,7 +22,8 @@ from fides.lib.models.fides_user import FidesUser from fides.lib.models.fides_user_permissions import FidesUserPermissions from fides.lib.oauth.api import urn_registry as urls -from fides.lib.oauth.api.deps import get_db, verify_oauth_client + +from fides.lib.oauth.api.deps import get_db from fides.lib.oauth.schemas.oauth import AccessToken from fides.lib.oauth.schemas.user import ( UserCreate, @@ -37,6 +38,7 @@ USER_DELETE, USER_READ, ) +from fides.api.ops.util.oauth_util import verify_oauth_client router = APIRouter() From f4528bee1472429a6a3995002439fc1321dd1105 Mon Sep 17 00:00:00 2001 From: Sean Preston Date: Mon, 19 Dec 2022 10:17:40 -0700 Subject: [PATCH 3/8] updates import order --- src/fides/lib/oauth/api/routes/user_endpoints.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fides/lib/oauth/api/routes/user_endpoints.py b/src/fides/lib/oauth/api/routes/user_endpoints.py index 7117ebade0..7387d9879d 100644 --- a/src/fides/lib/oauth/api/routes/user_endpoints.py +++ b/src/fides/lib/oauth/api/routes/user_endpoints.py @@ -17,12 +17,12 @@ HTTP_404_NOT_FOUND, ) +from fides.api.ops.util.oauth_util import verify_oauth_client from fides.ctl.core.config import FidesConfig, get_config from fides.lib.models.client import ADMIN_UI_ROOT, ClientDetail from fides.lib.models.fides_user import FidesUser from fides.lib.models.fides_user_permissions import FidesUserPermissions from fides.lib.oauth.api import urn_registry as urls - from fides.lib.oauth.api.deps import get_db from fides.lib.oauth.schemas.oauth import AccessToken from fides.lib.oauth.schemas.user import ( @@ -38,7 +38,6 @@ USER_DELETE, USER_READ, ) -from fides.api.ops.util.oauth_util import verify_oauth_client router = APIRouter() From f85318ded19a2a78aec89e3a4b874da3a9fbf9b2 Mon Sep 17 00:00:00 2001 From: Sean Preston Date: Mon, 19 Dec 2022 10:18:43 -0700 Subject: [PATCH 4/8] run black formatting --- tests/ops/api/v1/endpoints/test_user_endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ops/api/v1/endpoints/test_user_endpoints.py b/tests/ops/api/v1/endpoints/test_user_endpoints.py index b65ab374f1..e338f41916 100644 --- a/tests/ops/api/v1/endpoints/test_user_endpoints.py +++ b/tests/ops/api/v1/endpoints/test_user_endpoints.py @@ -159,7 +159,7 @@ def test_create_user( assert response_body == {"id": user.id} assert user.permissions is not None user.delete(db) - + def test_create_user_as_root( self, db, From a2db4bdf1a373b350539e83f04b4b229e2742e97 Mon Sep 17 00:00:00 2001 From: Sean Preston Date: Mon, 19 Dec 2022 10:40:34 -0700 Subject: [PATCH 5/8] register AccessManulWebhook by importing it so that sqlalchemy can find it when instantiating ConnectionConfig --- tests/lib/test_fides_user_permissions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/lib/test_fides_user_permissions.py b/tests/lib/test_fides_user_permissions.py index b3d03437bc..249e3c891e 100644 --- a/tests/lib/test_fides_user_permissions.py +++ b/tests/lib/test_fides_user_permissions.py @@ -12,6 +12,10 @@ def test_create_user_permissions(): + from fides.api.ops.models.manual_webhook import ( + AccessManualWebhook, + ) # pylint: disable=unused-import + permissions: FidesUserPermissions = FidesUserPermissions.create( # type: ignore db=MagicMock(), data={"user_id": "test", "scopes": [PRIVACY_REQUEST_READ]}, @@ -23,6 +27,10 @@ def test_create_user_permissions(): def test_associated_privileges(): + from fides.api.ops.models.manual_webhook import ( + AccessManualWebhook, + ) # pylint: disable=unused-import + permissions: FidesUserPermissions = FidesUserPermissions.create( # type: ignore db=MagicMock(), data={ From af7ede4e9094c57e8c9b25c35d16277f29c38ac4 Mon Sep 17 00:00:00 2001 From: Sean Preston Date: Mon, 19 Dec 2022 10:44:48 -0700 Subject: [PATCH 6/8] solve issue at module level --- tests/lib/test_client_model.py | 6 ++++++ tests/lib/test_fides_user_permissions.py | 14 ++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/lib/test_client_model.py b/tests/lib/test_client_model.py index 9cc4e25d67..48c717aa9c 100644 --- a/tests/lib/test_client_model.py +++ b/tests/lib/test_client_model.py @@ -4,6 +4,12 @@ import pytest +# Included so that `AccessManualWebhook` can be located when +# `ConnectionConfig` is instantiated. +from fides.api.ops.models.manual_webhook import ( + AccessManualWebhook, +) # pylint: disable=unused-import + from fides.lib.cryptography.cryptographic_util import hash_with_salt from fides.lib.models.client import ClientDetail, _get_root_client_detail from fides.lib.oauth.scopes import SCOPES diff --git a/tests/lib/test_fides_user_permissions.py b/tests/lib/test_fides_user_permissions.py index 249e3c891e..bda6fd5471 100644 --- a/tests/lib/test_fides_user_permissions.py +++ b/tests/lib/test_fides_user_permissions.py @@ -2,6 +2,12 @@ from unittest.mock import MagicMock +# Included so that `AccessManualWebhook` can be located when +# `ConnectionConfig` is instantiated. +from fides.api.ops.models.manual_webhook import ( + AccessManualWebhook, +) # pylint: disable=unused-import + from fides.lib.models.fides_user_permissions import FidesUserPermissions from fides.lib.oauth.scopes import ( PRIVACY_REQUEST_READ, @@ -12,10 +18,6 @@ def test_create_user_permissions(): - from fides.api.ops.models.manual_webhook import ( - AccessManualWebhook, - ) # pylint: disable=unused-import - permissions: FidesUserPermissions = FidesUserPermissions.create( # type: ignore db=MagicMock(), data={"user_id": "test", "scopes": [PRIVACY_REQUEST_READ]}, @@ -27,10 +29,6 @@ def test_create_user_permissions(): def test_associated_privileges(): - from fides.api.ops.models.manual_webhook import ( - AccessManualWebhook, - ) # pylint: disable=unused-import - permissions: FidesUserPermissions = FidesUserPermissions.create( # type: ignore db=MagicMock(), data={ From 0dfcf439ffb700f85150406f2d28ff54e80af736 Mon Sep 17 00:00:00 2001 From: Sean Preston Date: Mon, 19 Dec 2022 10:51:12 -0700 Subject: [PATCH 7/8] include import in fixture where possible --- tests/lib/conftest.py | 6 ++++++ tests/lib/test_client_model.py | 6 ------ tests/lib/test_fides_user_permissions.py | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/lib/conftest.py b/tests/lib/conftest.py index 4138b364dc..a3e9eaa8a4 100644 --- a/tests/lib/conftest.py +++ b/tests/lib/conftest.py @@ -42,6 +42,12 @@ def config(): @pytest.fixture def db(config): """Yield a connection to the test DB.""" + # Included so that `AccessManualWebhook` can be located when + # `ConnectionConfig` is instantiated. + from fides.api.ops.models.manual_webhook import ( + AccessManualWebhook, + ) # pylint: disable=unused-import + # Create the test DB engine assert config.is_test_mode engine = get_db_engine( diff --git a/tests/lib/test_client_model.py b/tests/lib/test_client_model.py index 48c717aa9c..9cc4e25d67 100644 --- a/tests/lib/test_client_model.py +++ b/tests/lib/test_client_model.py @@ -4,12 +4,6 @@ import pytest -# Included so that `AccessManualWebhook` can be located when -# `ConnectionConfig` is instantiated. -from fides.api.ops.models.manual_webhook import ( - AccessManualWebhook, -) # pylint: disable=unused-import - from fides.lib.cryptography.cryptographic_util import hash_with_salt from fides.lib.models.client import ClientDetail, _get_root_client_detail from fides.lib.oauth.scopes import SCOPES diff --git a/tests/lib/test_fides_user_permissions.py b/tests/lib/test_fides_user_permissions.py index bda6fd5471..69ecf4a2f8 100644 --- a/tests/lib/test_fides_user_permissions.py +++ b/tests/lib/test_fides_user_permissions.py @@ -19,6 +19,7 @@ def test_create_user_permissions(): permissions: FidesUserPermissions = FidesUserPermissions.create( # type: ignore + # Not using the `db` here allows us to omit PK and FK data db=MagicMock(), data={"user_id": "test", "scopes": [PRIVACY_REQUEST_READ]}, ) @@ -30,6 +31,7 @@ def test_create_user_permissions(): def test_associated_privileges(): permissions: FidesUserPermissions = FidesUserPermissions.create( # type: ignore + # Not using the `db` here allows us to omit PK and FK data db=MagicMock(), data={ "user_id": "test", From b51967dcb9d7673f46111b6e5f58ebc56a1c32ad Mon Sep 17 00:00:00 2001 From: Sean Preston Date: Mon, 19 Dec 2022 10:57:23 -0700 Subject: [PATCH 8/8] isort --- tests/lib/conftest.py | 4 ++-- tests/lib/test_fides_user_permissions.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/lib/conftest.py b/tests/lib/conftest.py index a3e9eaa8a4..047ee55ceb 100644 --- a/tests/lib/conftest.py +++ b/tests/lib/conftest.py @@ -44,9 +44,9 @@ def db(config): """Yield a connection to the test DB.""" # Included so that `AccessManualWebhook` can be located when # `ConnectionConfig` is instantiated. - from fides.api.ops.models.manual_webhook import ( + from fides.api.ops.models.manual_webhook import ( # pylint: disable=unused-import AccessManualWebhook, - ) # pylint: disable=unused-import + ) # Create the test DB engine assert config.is_test_mode diff --git a/tests/lib/test_fides_user_permissions.py b/tests/lib/test_fides_user_permissions.py index 69ecf4a2f8..602575f267 100644 --- a/tests/lib/test_fides_user_permissions.py +++ b/tests/lib/test_fides_user_permissions.py @@ -4,10 +4,9 @@ # Included so that `AccessManualWebhook` can be located when # `ConnectionConfig` is instantiated. -from fides.api.ops.models.manual_webhook import ( +from fides.api.ops.models.manual_webhook import ( # pylint: disable=unused-import AccessManualWebhook, -) # pylint: disable=unused-import - +) from fides.lib.models.fides_user_permissions import FidesUserPermissions from fides.lib.oauth.scopes import ( PRIVACY_REQUEST_READ,