Skip to content
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
5 changes: 5 additions & 0 deletions limacharlie/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ def logout(ctx: click.Context, environment: str | None) -> None:
@pass_context
def whoami(ctx: click.Context, show_perms: bool, check_perm: str | None) -> None:
client = _get_client(ctx)
# --check-perm requires a real OID — fail early before the fallback.
if check_perm is not None and client.oid is None:
raise click.UsageError(
"--check-perm requires an OID to be specified (use --oid or set the LC_OID environment variable)"
)
# whoami works without a specific org — fall back to "-" if no OID resolved.
if client.oid is None:
client = _get_client(ctx, oid_override="-")
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ def test_whoami_check_perm_in_user_perms(self, mock_org_cls, mock_client_cls):
parsed = json.loads(result.output)
assert parsed["has_perm"] is True

@patch("limacharlie.commands.auth.Client")
def test_whoami_check_perm_requires_oid(self, mock_client_cls):
mock_client = MagicMock()
mock_client.oid = None
mock_client_cls.return_value = mock_client

runner = CliRunner()
result = runner.invoke(cli, ["--output", "json", "auth", "whoami", "--check-perm", "ai_agent.operate"])
assert result.exit_code != 0
assert "--check-perm requires an OID" in result.output

@patch("limacharlie.commands.auth.Client")
def test_auth_test_success(self, mock_client_cls):
mock_client = MagicMock()
Expand Down