-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8090 from khoaguin/user-update-bug
Fix the bug "Guest user is able to change email to owner and essentially kills nodes"
- Loading branch information
Showing
3 changed files
with
50 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from syft import SyftSuccess | ||
from syft.client.api import SyftAPICall | ||
from syft.client.domain_client import DomainClient | ||
from syft.node.node import get_default_root_email | ||
from syft.node.worker import Worker | ||
from syft.service.context import AuthedServiceContext | ||
from syft.service.user.user import ServiceRole | ||
|
@@ -32,7 +33,7 @@ def get_users(worker): | |
) | ||
|
||
|
||
def get_mock_client(root_client, role): | ||
def get_mock_client(root_client, role) -> DomainClient: | ||
worker = root_client.api.connection.node | ||
client = worker.guest_client | ||
mail = Faker().email() | ||
|
@@ -66,17 +67,17 @@ def manually_call_service(worker, client, service, args=None, kwargs=None): | |
|
||
|
||
@pytest.fixture | ||
def guest_client(worker): | ||
def guest_client(worker) -> DomainClient: | ||
return get_mock_client(worker.root_client, ServiceRole.GUEST) | ||
|
||
|
||
@pytest.fixture | ||
def ds_client(worker): | ||
def ds_client(worker) -> DomainClient: | ||
return get_mock_client(worker.root_client, ServiceRole.DATA_SCIENTIST) | ||
|
||
|
||
@pytest.fixture | ||
def do_client(worker): | ||
def do_client(worker) -> DomainClient: | ||
return get_mock_client(worker.root_client, ServiceRole.DATA_OWNER) | ||
|
||
|
||
|
@@ -233,6 +234,24 @@ def test_user_update(root_client): | |
) | ||
|
||
|
||
def test_guest_user_update_to_root_email_failed( | ||
root_client: DomainClient, | ||
do_client: DomainClient, | ||
guest_client: DomainClient, | ||
ds_client: DomainClient, | ||
) -> None: | ||
default_root_email: str = get_default_root_email() | ||
user_update_to_root_email = UserUpdate(email=default_root_email) | ||
for client in [root_client, do_client, guest_client, ds_client]: | ||
res = client.api.services.user.update( | ||
uid=client.me.id, user_update=user_update_to_root_email | ||
) | ||
assert isinstance(res, SyftError) | ||
assert ( | ||
res.message == f"A user with the email {default_root_email} already exists." | ||
) | ||
|
||
|
||
def test_user_view_set_password(worker: Worker, root_client: DomainClient) -> None: | ||
root_client.me.set_password("123", confirm=False) | ||
email = root_client.me.email | ||
|
@@ -260,7 +279,6 @@ def test_user_view_set_invalid_email( | |
[ | ||
("[email protected]", "[email protected]"), | ||
("[email protected]", "[email protected]"), | ||
("[email protected]", "[email protected]"), | ||
], | ||
) | ||
def test_user_view_set_email_success( | ||
|
@@ -275,6 +293,22 @@ def test_user_view_set_email_success( | |
assert isinstance(result2, SyftSuccess) | ||
|
||
|
||
def test_user_view_set_default_admin_email_failed( | ||
ds_client: DomainClient, guest_client: DomainClient | ||
) -> None: | ||
default_root_email = get_default_root_email() | ||
result = ds_client.me.set_email(default_root_email) | ||
assert isinstance(result, SyftError) | ||
assert ( | ||
result.message == f"A user with the email {default_root_email} already exists." | ||
) | ||
result_2 = guest_client.me.set_email(default_root_email) | ||
assert isinstance(result_2, SyftError) | ||
assert ( | ||
result.message == f"A user with the email {default_root_email} already exists." | ||
) | ||
|
||
|
||
def test_user_view_set_duplicated_email( | ||
root_client: DomainClient, ds_client: DomainClient, guest_client: DomainClient | ||
) -> None: | ||
|