You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TEST: ConnectAndGetToken Returns Error on Non-200 Response #554
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
changed the title [-]`ConnectAndGetToken` Returns Error on Non-200 Response (HIGH)[/-][+]TEST: `ConnectAndGetToken` Returns Error on Non-200 Response (HIGH)[/+]on Sep 28, 2026
changed the title [-]TEST: `ConnectAndGetToken` Returns Error on Non-200 Response (HIGH)[/-][+]TEST: `ConnectAndGetToken` Returns Error on Non-200 Response[/+]on Sep 28, 2026
Activity
[-]`ConnectAndGetToken` Returns Error on Non-200 Response (HIGH)[/-][+]TEST: `ConnectAndGetToken` Returns Error on Non-200 Response (HIGH)[/+][-]TEST: `ConnectAndGetToken` Returns Error on Non-200 Response (HIGH)[/-][+]TEST: `ConnectAndGetToken` Returns Error on Non-200 Response[/+]test: ConnectAndGetToken returns error on non-200 response (microcks#555