Skip to content

fix: avoid nil interface panic on Keycloak config discovery#272

Open
pulkitvats2007-crypto wants to merge 1 commit intomicrocks:masterfrom
pulkitvats2007-crypto:fix-keycloak-panic
Open

fix: avoid nil interface panic on Keycloak config discovery#272
pulkitvats2007-crypto wants to merge 1 commit intomicrocks:masterfrom
pulkitvats2007-crypto:fix-keycloak-panic

Conversation

@pulkitvats2007-crypto
Copy link
Copy Markdown

Description

  • Fixes a critical runtime panic in GetKeycloakURL() when interacting with a Microcks server that has Keycloak disabled.
  • Previously, the CLI performed unconditional type assertions on auth-server-url and realm fields, which are absent when the /api/keycloak/config endpoint returns { "enabled": false }. This caused a fatal panic:
    panic: interface conversion: interface {} is nil, not string.
  • Updated logic to first check the enabled flag and only access Keycloak-specific fields when it is true.
  • Ensures the CLI returns "null" safely when Keycloak is disabled instead of crashing.

Implementation Details

enabled := configResp["enabled"].(bool)

if enabled {
    authServerURL := configResp["auth-server-url"].(string)
    realmName := configResp["realm"].(string)
    return authServerURL + "/realms/" + realmName + "/", nil
}
return "null", nil

Testing & Prevention

  • Added unit tests in pkg/connectors/microcks_client_test.go using httptest.Server.
  • Covered both scenarios:
    • Keycloak enabled → validates correct URL construction.
    • Keycloak disabled → verifies no panic and correct "null" return.
  • All tests pass successfully.

Impact

  • Prevents fatal runtime crashes during CLI operations such as:
    • microcks login
    • microcks test
    • Token refresh flows
  • Enables seamless usage of the CLI with Microcks deployments where Keycloak is intentionally disabled (common in local setups and CI/CD pipelines).
  • Eliminates a class of interface conversion panics caused by unsafe type assertions on missing JSON fields.
  • Improves overall CLI robustness and production reliability.

Related issue(s)

Fixes #267

Signed-off-by: pulkitvats2007-crypto <pulkitvats2007@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

👋 @pulkitvats2007-crypto

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

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.

fix: replace bare type assertions in API clients with proper error handling

1 participant