Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for tests that are failing on keycloak version >= 9 #300

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
environment:
- KEYCLOAK_USER=keycloak
- KEYCLOAK_PASSWORD=password
- KEYCLOAK_LOGLEVEL=DEBUG
- KEYCLOAK_LOGLEVEL=INFO
- DB_VENDOR=POSTGRES
- DB_ADDR=postgres
- DB_PORT=5432
Expand Down
28 changes: 15 additions & 13 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,21 @@ resource keycloak_oidc_google_identity_provider google {
accepts_prompt_none_forward_from_client = false
}

resource keycloak_oidc_identity_provider custom_oidc_idp {
realm = "${keycloak_realm.test.id}"
provider_id = "customIdp"
alias = "custom"
authorization_url = "https://example.com/auth"
token_url = "https://example.com/token"
client_id = "example_id"
client_secret = "example_token"

extra_config = {
dummyConfig = "dummyValue"
}
}
//This example does not work in keycloak 10, because the interfaces that our customIdp implements, have changed in the keycloak latest version.
//We need to make decide which keycloak version we going to support and test for the customIdp
//resource keycloak_oidc_identity_provider custom_oidc_idp {
// realm = "${keycloak_realm.test.id}"
// provider_id = "customIdp"
// alias = "custom"
// authorization_url = "https://example.com/auth"
// token_url = "https://example.com/token"
// client_id = "example_id"
// client_secret = "example_token"
//
// extra_config = {
// dummyConfig = "dummyValue"
// }
//}

resource keycloak_attribute_importer_identity_provider_mapper oidc {
realm = "${keycloak_realm.test.id}"
Expand Down
13 changes: 12 additions & 1 deletion keycloak/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ type PasswordCredentials struct {
}

func (keycloakClient *KeycloakClient) NewUser(user *User) error {
_, location, err := keycloakClient.post(fmt.Sprintf("/realms/%s/users", user.RealmId), user)
newUser := User{
Id: user.Id,
RealmId: user.RealmId,
Username: user.Username,
Email: user.Email,
EmailVerified: user.EmailVerified,
FirstName: user.FirstName,
LastName: user.LastName,
Enabled: user.Enabled,
Attributes: user.Attributes,
}
_, location, err := keycloakClient.post(fmt.Sprintf("/realms/%s/users", user.RealmId), newUser)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAccKeycloakOidcGoogleIdentityProvider_basic(t *testing.T) {
})
}

func TestAccKeycloakOidcGoogleIdentityProvider_custom(t *testing.T) {
func TestAccKeycloakOidcGoogleIdentityProvider_customConfig(t *testing.T) {
realmName := "terraform-" + acctest.RandString(10)
customConfigValue := "terraform-" + acctest.RandString(10)

Expand All @@ -35,7 +35,7 @@ func TestAccKeycloakOidcGoogleIdentityProvider_custom(t *testing.T) {
CheckDestroy: testAccCheckKeycloakOidcGoogleIdentityProviderDestroy(),
Steps: []resource.TestStep{
{
Config: testKeycloakOidcGoogleIdentityProvider_custom(realmName, customConfigValue),
Config: testKeycloakOidcGoogleIdentityProvider_customConfig(realmName, customConfigValue),
Check: resource.ComposeTestCheckFunc(
testAccCheckKeycloakOidcGoogleIdentityProviderExists("keycloak_oidc_google_identity_provider.google_custom"),
testAccCheckKeycloakOidcGoogleIdentityProviderHasCustomConfigValue("keycloak_oidc_google_identity_provider.google_custom", customConfigValue),
Expand Down Expand Up @@ -242,15 +242,15 @@ resource "keycloak_oidc_google_identity_provider" "google" {
`, realm)
}

func testKeycloakOidcGoogleIdentityProvider_custom(realm, customConfigValue string) string {
func testKeycloakOidcGoogleIdentityProvider_customConfig(realm, customConfigValue string) string {
return fmt.Sprintf(`
resource "keycloak_realm" "realm" {
realm = "%s"
}

resource "keycloak_oidc_google_identity_provider" "google_custom" {
realm = "${keycloak_realm.realm.id}"
provider_id = "customGoogleIdp"
provider_id = "google"
client_id = "example_id"
client_secret = "example_token"
extra_config = {
Expand Down
48 changes: 43 additions & 5 deletions provider/resource_keycloak_oidc_identity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,28 @@ func TestAccKeycloakOidcIdentityProvider_basic(t *testing.T) {
})
}

func TestAccKeycloakOidcIdentityProvider_custom(t *testing.T) {
//This test does not work in keycloak 10, because the interfaces that our customIdp implements, have changed in the keycloak latest version.
//We need to decide which keycloak version we going to support and test for the customIdp
//func TestAccKeycloakOidcIdentityProvider_custom(t *testing.T) {
// realmName := "terraform-" + acctest.RandString(10)
// oidcName := "terraform-" + acctest.RandString(10)
//
// resource.Test(t, resource.TestCase{
// Providers: testAccProviders,
// PreCheck: func() { testAccPreCheck(t) },
// CheckDestroy: testAccCheckKeycloakOidcIdentityProviderDestroy(),
// Steps: []resource.TestStep{
// {
// Config: testKeycloakOidcIdentityProvider_custom(realmName, oidcName),
// Check: resource.ComposeTestCheckFunc(
// testAccCheckKeycloakOidcIdentityProviderExists("keycloak_oidc_identity_provider.oidc"),
// ),
// },
// },
// })
//}

func TestAccKeycloakOidcIdentityProvider_extra_config(t *testing.T) {
realmName := "terraform-" + acctest.RandString(10)
oidcName := "terraform-" + acctest.RandString(10)
customConfigValue := "terraform-" + acctest.RandString(10)
Expand All @@ -37,9 +58,8 @@ func TestAccKeycloakOidcIdentityProvider_custom(t *testing.T) {
CheckDestroy: testAccCheckKeycloakOidcIdentityProviderDestroy(),
Steps: []resource.TestStep{
{
Config: testKeycloakOidcIdentityProvider_custom(realmName, oidcName, customConfigValue),
Config: testKeycloakOidcIdentityProvider_extra_config(realmName, oidcName, customConfigValue),
Check: resource.ComposeTestCheckFunc(
testAccCheckKeycloakOidcIdentityProviderExists("keycloak_oidc_identity_provider.oidc"),
testAccCheckKeycloakOidcIdentityProviderHasCustomConfigValue("keycloak_oidc_identity_provider.oidc", customConfigValue),
),
},
Expand Down Expand Up @@ -284,7 +304,7 @@ resource "keycloak_oidc_identity_provider" "oidc" {
`, realm, oidc)
}

func testKeycloakOidcIdentityProvider_custom(realm, alias, customConfigValue string) string {
func testKeycloakOidcIdentityProvider_custom(realm, alias string) string {
return fmt.Sprintf(`
resource "keycloak_realm" "realm" {
realm = "%s"
Expand All @@ -298,6 +318,24 @@ resource "keycloak_oidc_identity_provider" "oidc" {
token_url = "https://example.com/token"
client_id = "example_id"
client_secret = "example_token"
}
`, realm, alias)
}

func testKeycloakOidcIdentityProvider_extra_config(realm, alias, customConfigValue string) string {
return fmt.Sprintf(`
resource "keycloak_realm" "realm" {
realm = "%s"
}

resource "keycloak_oidc_identity_provider" "oidc" {
realm = "${keycloak_realm.realm.id}"
provider_id = "oidc"
alias = "%s"
authorization_url = "https://example.com/auth"
token_url = "https://example.com/token"
client_id = "example_id"
client_secret = "example_token"
extra_config = {
dummyConfig = "%s"
}
Expand All @@ -313,7 +351,7 @@ resource "keycloak_realm" "realm" {

resource "keycloak_oidc_identity_provider" "oidc" {
realm = "${keycloak_realm.realm.id}"
provider_id = "customIdp"
provider_id = "oidc"
alias = "%s"
authorization_url = "https://example.com/auth"
token_url = "https://example.com/token"
Expand Down