Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user creation as root #2082

Merged
merged 8 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/fides/lib/oauth/api/routes/user_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
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, 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,
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( # pylint: disable=unused-import
AccessManualWebhook,
)

# Create the test DB engine
assert config.is_test_mode
engine = get_db_engine(
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/test_fides_user_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

from unittest.mock import MagicMock

# Included so that `AccessManualWebhook` can be located when
# `ConnectionConfig` is instantiated.
from fides.api.ops.models.manual_webhook import ( # pylint: disable=unused-import
AccessManualWebhook,
)
from fides.lib.models.fides_user_permissions import FidesUserPermissions
from fides.lib.oauth.scopes import (
PRIVACY_REQUEST_READ,
Expand All @@ -13,6 +18,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]},
)
Expand All @@ -24,6 +30,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",
Expand Down
19 changes: 19 additions & 0 deletions tests/ops/api/v1/endpoints/test_user_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ def test_create_user(
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,
db,
Expand Down