Skip to content

fix(client): detect rejected credentials instead of reporting empty results - #154

Merged
f3rdy merged 1 commit into
masterfrom
fix/153-detect-rejected-credentials
Nov 3, 2026
Merged

f3rdy merged 1 commit into
masterfrom
fix/153-detect-rejected-credentials

Conversation

@f3rdy

@f3rdy f3rdy commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Closes #153

Problem

Jira Cloud answers most reads anonymously when Basic auth fails (measured):

Endpoint Invalid token
GET /rest/api/3/myself 401
GET /rest/api/3/search/jql 200, no issues
GET /rest/api/2/serverInfo 200
GET /rest/api/3/issue/KEY 404 "Issue does not exist or you do not have permission to see it."
GET /rest/api/3/project/search 200, empty list

So an expired or revoked token looked like an empty project (search), a missing issue (show) or an instance without projects (project list).

Fix

JiraClient verifies the credentials via /myself right after connecting:

  • 401 → AuthenticationError naming the connection, the user and the token source (api_token_ref / env var / stored credential) — never the token.
  • 403 → PermissionError; anything else → JiraAPIError.

Central check rather than per command, because every read path is affected.

Cost: one extra request per invocation (~260 ms measured against Jira Cloud). serverInfo cannot be dropped in exchange — the jira library derives the deployment type (_is_cloud) and version from it.

connect test already verified via current_user() and is unchanged.

Verification

  • 4 client tests (401 / 403 / other / happy path) and 2 CLI tests: a rejected token makes search exit 1 with the authentication error instead of "No issues found"; a valid token with no matches still prints "No issues found". The rejection test fails without the fix.
  • Full suite 1516 passed; ruff, mypy, pre-commit clean.
  • Live: a revoked token now fails with the authentication error; with a valid token an empty project still reports "No issues found" and a populated one returns issues.

…esults

Jira Cloud answers most reads anonymously when Basic auth fails:
search/jql returns 200 with no issues, issues return 404, project
search returns an empty list. Only endpoints that need a user, such
as /myself, return 401. An expired or revoked token therefore looked
like an empty project.

JiraClient now verifies the credentials via /myself right after
connecting and raises an AuthenticationError naming the connection,
the user and the token source (never the token). One extra request
per invocation; serverInfo cannot be dropped instead, the jira
library derives the deployment type and version from it.

Closes #153
@f3rdy
f3rdy merged commit a3b42d6 into master Nov 3, 2026
5 checks passed
@f3rdy
f3rdy deleted the fix/153-detect-rejected-credentials branch November 3, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid or expired API token is reported as "No issues found" instead of an authentication error

1 participant