Skip to content
Closed
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
6 changes: 3 additions & 3 deletions inkbox_codex/setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,9 +1359,9 @@ def _api_key_flow(
if subtype == _enum_value(ADMIN_SCOPED):
return _pick_admin_scoped(client, api_key, IdentityPhoneNumberCreateOptions, InkboxAPIError)

print_warning(f" Unrecognized API-key subtype: {subtype!r}.")
print_info(" Falling back to list_identities().")
return _pick_admin_scoped(client, api_key, IdentityPhoneNumberCreateOptions, InkboxAPIError)
print_error(f" Unsupported API-key subtype: {subtype!r}.")
print_info(" Use an admin-scoped or agent-scoped Inkbox API key.")
return None, "", False


def _pick_agent_scoped(client: Any, api_key: str) -> tuple[Any | None, str, bool]:
Expand Down
37 changes: 37 additions & 0 deletions tests/test_setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,43 @@ def fail_import():
assert "inkbox>=0.4.10" in out


# ----------------------------------------------------------------------
# API key scope handling
# ----------------------------------------------------------------------


def test_api_key_flow_rejects_unknown_auth_subtype(monkeypatch, capsys):
class FakeWhoamiApiKeyResponse:
auth_subtype = "future_scope"
organization_id = "org_123"

class FakeInkbox:
def __init__(self, **_kwargs):
pass

def whoami(self):
return FakeWhoamiApiKeyResponse()

def list_identities(self):
raise AssertionError("unknown subtypes must not fall back to identity listing")

monkeypatch.setattr(setup_wizard, "prompt", lambda *_args, **_kwargs: "ApiKey_test")

result = setup_wizard._api_key_flow(
"https://inkbox.ai",
FakeInkbox,
Exception,
FakeWhoamiApiKeyResponse,
"admin_scoped",
"agent_scoped_claimed",
"agent_scoped_unclaimed",
object,
)

assert result == (None, "", False)
assert "Unsupported API-key subtype" in capsys.readouterr().out


# ----------------------------------------------------------------------
# Project directory
# ----------------------------------------------------------------------
Expand Down
Loading