Skip to content

Commit

Permalink
add test for mismatched domain
Browse files Browse the repository at this point in the history
  • Loading branch information
craddm committed Nov 26, 2024
1 parent 469f1d6 commit 2abd14b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/commands/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pytest import fixture
from typer.testing import CliRunner

from data_safe_haven.administration.users.entra_users import EntraUsers
from data_safe_haven.administration.users.research_user import ResearchUser
from data_safe_haven.config import (
Context,
ContextManager,
Expand Down Expand Up @@ -260,3 +262,14 @@ def tmp_contexts_none(tmp_path, context_yaml):
with open(config_file_path, "w") as f:
f.write(context_yaml)
return tmp_path


@fixture
def mock_entra_user_list(mocker):
test_user = ResearchUser(
given_name="Harry",
surname="Lime",
sam_account_name="harry.lime",
user_principal_name="[email protected]",
)
mocker.patch.object(EntraUsers, "list", return_value=[test_user])
20 changes: 20 additions & 0 deletions tests/commands/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ def test_invalid_shm(
assert result.exit_code == 1
assert "Have you deployed the SHM?" in result.stdout

def test_mismatched_domain(
self,
mock_graphapi_get_credential, # noqa: ARG002
mock_pulumi_config_no_key_from_remote, # noqa: ARG002
mock_shm_config_from_remote, # noqa: ARG002
mock_sre_config_from_remote, # noqa: ARG002
mock_entra_user_list, # noqa: ARG002
runner,
tmp_contexts, # noqa: ARG002
):
result = runner.invoke(
users_command_group, ["register", "-u", "harry.lime", "sandbox"]
)

assert result.exit_code == 0
assert (
"principal domain name must match the domain of the SRE to be registered"
in result.stdout
)

def test_invalid_sre(
self,
mock_pulumi_config_from_remote, # noqa: ARG002
Expand Down

0 comments on commit 2abd14b

Please sign in to comment.