Skip to content

Test : ConnectAndGetToken Returns Error on Non-200 Response - #555

Open
aniket866 wants to merge 1 commit into
microcks:masterfrom
aniket866:fix/Test-ConnectAndGetToken
Open

aniket866 wants to merge 1 commit into
microcks:masterfrom
aniket866:fix/Test-ConnectAndGetToken

Conversation

@aniket866

Copy link
Copy Markdown
Contributor

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 
Loading

Ai usage Disclosure: Chatgpt is used to review files and it's missing tests
Closes #554

Signed-off-by: aniket866 <iamaniketkumarmaner@gmail.com>

This branch was successfully deployed

1 active deployment
Build — a5436690 Deployed Sep 28, 2026 by aniket866 via build-verify-package #745
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.

TEST: ConnectAndGetToken Returns Error on Non-200 Response

1 participant