fix: avoid nil interface panic on Keycloak config discovery - #272
fix: avoid nil interface panic on Keycloak config discovery#272pulkitvats2007-crypto wants to merge 1 commit into
Conversation
Signed-off-by: pulkitvats2007-crypto <pulkitvats2007@gmail.com>
|
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! |
|
This pull request has been automatically marked as stale because it has not had recent activity 😴 It will be closed in 30 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation. There can be many reasons why some specific pull request has no activity. The most probable cause is lack of time, not lack of interest. Microcks is a Cloud Native Computing Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model. Let us figure out together how to push this pull request forward. Connect with us through one of many communication channels we established here. Thank you for your patience ❤️ |
| realmName := configResp["realm"].(string) | ||
| return authServerURL + "/realms/" + realmName + "/", nil | ||
| } | ||
| return "null", nil |
There was a problem hiding this comment.
Why return the string "null" and not just ""? Is something downstream actually expecting the literal string "null"? A comment here would help a lot.
There was a problem hiding this comment.
@pulkitvats2007-crypto
Need a rebase, and resolve conflicts
| @@ -238,11 +238,11 @@ func (c *microcksClient) GetKeycloakURL() (string, error) { | |||
|
|
|||
| // Retrieve auth server url and realm name. | |||
| enabled := configResp["enabled"].(bool) | |||
There was a problem hiding this comment.
This is still an unchecked type assertion. If the enabled key is missing or "enabled": null in the response, this line panics; exactly the class of bug this PR is meant to fix.
| enabled := configResp["enabled"].(bool) | |
| enabled, ok := configResp["enabled"].(bool) | |
| if !ok || !enabled { | |
| return "null", nil | |
| } |
| authServerURL := configResp["auth-server-url"].(string) | ||
| realmName := configResp["realm"].(string) | ||
|
|
||
| // Return a proper URL or 'null' if Keycloak is disables. |
There was a problem hiding this comment.
minor typo: "disables" to "disabled"
There was a problem hiding this comment.
Tests cover enabled/disabled but not the missing-enabled-key case that the comma-ok fix addresses.
|
@pulkitvats2007-crypto I Agree with @Vaishnav88sk's review, can you please have look? |
|
As per my comments here I believe this can be closed. You will notice merge conflicts |
Description
GetKeycloakURL()when interacting with a Microcks server that has Keycloak disabled.auth-server-urlandrealmfields, which are absent when the/api/keycloak/configendpoint returns{ "enabled": false }. This caused a fatal panic:panic: interface conversion: interface {} is nil, not string.enabledflag and only access Keycloak-specific fields when it istrue."null"safely when Keycloak is disabled instead of crashing.Implementation Details
Testing & Prevention
pkg/connectors/microcks_client_test.gousinghttptest.Server."null"return.Impact
microcks loginmicrocks testRelated issue(s)
Fixes #267