Skip to content

Commit 33e34fa

Browse files
committed
test: Add unit tests for auth states
#9 Branch: ServeNoAuthFlag-9 Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 2e8bde3 commit 33e34fa

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/commands/server/test_serve.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ def test_serve_with_reload(self) -> None:
4848
_, kwargs = mock_run.call_args
4949
assert kwargs.get("reload") is True
5050

51+
def test_serve_with_no_auth_sets_auth_required_false(self) -> None:
52+
"""Test serve command with --no-auth sets auth_required to False."""
53+
with patch("cforge.commands.server.serve.uvicorn.run") as mock_run, patch("cforge.commands.server.serve.set_serve_settings") as mock_set_settings:
54+
serve(no_auth=True, headless=False)
55+
mock_run.assert_called_once()
56+
# When headless=False (default), UI and admin API are enabled (not headless = True)
57+
# When no_auth=True, auth_required should be False (not no_auth = False)
58+
mock_set_settings.assert_called_once_with(
59+
mcpgateway_ui_enabled=True,
60+
mcpgateway_admin_api_enabled=True,
61+
auth_required=False,
62+
)
63+
64+
def test_serve_without_no_auth_sets_auth_required_true(self) -> None:
65+
"""Test serve command without --no-auth sets auth_required to True."""
66+
with patch("cforge.commands.server.serve.uvicorn.run") as mock_run, patch("cforge.commands.server.serve.set_serve_settings") as mock_set_settings:
67+
serve(no_auth=False, headless=False)
68+
mock_run.assert_called_once()
69+
# When headless=False (default), UI and admin API are enabled (not headless = True)
70+
# When no_auth=False (default), auth_required should be True (not no_auth = True)
71+
mock_set_settings.assert_called_once_with(
72+
mcpgateway_ui_enabled=True,
73+
mcpgateway_admin_api_enabled=True,
74+
auth_required=True,
75+
)
76+
5177

5278
class TestServeCommandIntegration:
5379
"""Integration tests for the serve command"""

0 commit comments

Comments
 (0)