TEST: `ConnectAndGetToken` Returns Error on Non-200 Response
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start in keycloak_client.go at ConnectAndGetToken, then use an httptest.Server that returns 401 with the documented JSON body. Verify the returned error is non-nil, includes the 401 status, and has KindAPI classification. Done means the test reliably covers the non-200 response path and the full Keycloak client package has this critical case protected.
Written by the indexing model from the issue text.
Description
Reason/Context
Description
keycloak_client.go ConnectAndGetToken has no tests at all. The entire
Keycloak client package is untested. The most critical path to test is when
Keycloak returns a non-200 status (wrong credentials, realm not found, server
error) — the function should return a KindAPI error with the HTTP status code
and body. Currently nothing verifies this.
Why Necessary
Wrong credentials is the single most common failure a new user encounters. If
this error path regresses — e.g. the function panics, returns a nil error, or
swallows the body — users get no feedback and assume the server is down.
What If Not Present
A change to the response-parsing code (e.g. switching JSON library, restructuring
the token response) could silently break authentication for all users and no test
would catch it before release.
Diagram
sequenceDiagram
participant T as Test
participant KC as keycloakClient
participant TS as httptest.Server
T->>TS: register handler → always return 401 {"error":"unauthorized"}
T->>KC: NewKeycloakClient(server.URL, "id", "secret")
T->>KC: ConnectAndGetToken()
KC->>TS: POST /protocol/openid-connect/token
TS-->>KC: 401 {"error":"unauthorized"}
KC-->>T: error (KindAPI)
T->>T: assert error != nil
T->>T: assert error contains "401"
T->>T: assert KindOf(err) == KindAPI
Description
N/A
Implementation ideas
No response
- Dominant language
- Go
- Stars
- 57
- Forks
- 72
- Avg merge
- 1d 35m
- Merged PRs (30d)
- 24
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microcks/microcks-cli
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
microcks/microcks-cli#561 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microcks/microcks-cli#559 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
microcks/microcks-cli#551 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microcks/microcks-cli#545 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
microcks/microcks-cli#536 · 1 comment ·
Maintainers usually reply within 1 day
All issues in microcks/microcks-cli
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google/differential-privacy#516 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
lightninglabs/lndmon#140 ·
-
documentation good first issue ready-for-triage ready-to-code
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
release-engineering/fbc-update-planner#102 · 3 comments ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
yetone/magpie#562 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 4 days