Skip to content

Lack of Integration and Authentication Protocol Tests for Keycloak Authorization Exchanges #484

Description

@aniket866

Describe the bug

  • Location: pkg/connectors/keycloak_client.go -> ConnectAndGetToken & ConnectAndGetTokenAndRefreshToken

  • Detailed Description:
    This is about how the CLI logs us in for the first time. It has to send our credentials to the authentication server (Keycloak), format the request headers (including base64 encoding), and parse the token payload we get back.

    Since we don't have tests for these authentication functions, any minor code change could break the login flow. If this fails, users won't even be able to connect to the Microcks server at all. We should test that our request payload format is correct and that we handle server response errors cleanly.

  • Test Requirements:

    • Verify that the client correctly formats base64 authorization headers for basic authentication.
    • Make sure the credential request parameters are correctly URL-encoded.
    • Verify that we cleanly parse successful response tokens and handle common server failures (like invalid password or server offline) without crashing.

Simulation Diagram

sequenceDiagram
    autonumber
    actor Test as Test Runner
    participant KC as keycloakClient
    participant mockOIDC as Mock OIDC Provider (httptest)

    Test->>KC: Invoke ConnectAndGetToken()
    activate KC
    KC->>KC: Base64 Encode Username:Password
    KC->>mockOIDC: POST /protocol/openid-connect/token (grant_type=client_credentials)
    Note over mockOIDC: Validate Basic Auth header & Body form-params
    activate mockOIDC
    mockOIDC-->>KC: HTTP 200 OK {"access_token": "mock-token", "token_type": "Bearer"}
    deactivate mockOIDC
    KC-->>Test: Return "mock-token"
    deactivate KC
Loading

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Microcks version or git rev

No response

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions