Skip to content
New issue

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

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

Already on GitHub? # to your account

Support for NameIdPolicyFormat Transient on the saml idp #661

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
1 change: 1 addition & 0 deletions provider/resource_keycloak_saml_identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var nameIdPolicyFormats = map[string]string{
"Kerberos": "urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos",
"X.509 Subject Name": "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName",
"Unspecified": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
"Transient": "urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
}

var signatureAlgorithms = []string{
Expand Down
50 changes: 50 additions & 0 deletions provider/resource_keycloak_saml_identity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ func TestAccKeycloakSamlIdentityProvider_customProviderId(t *testing.T) {
})
}

func TestAccKeycloakSamlIdentityProvider_nameIdPolicyFormatTransient(t *testing.T) {
t.Parallel()

samlName := acctest.RandomWithPrefix("tf-acc")

resource.Test(t, resource.TestCase{
ProviderFactories: testAccProviderFactories,
PreCheck: func() { testAccPreCheck(t) },
CheckDestroy: testAccCheckKeycloakSamlIdentityProviderDestroy(),
Steps: []resource.TestStep{
{
Config: testKeycloakSamlIdentityProvider_withNameIdPolicyFormat(samlName, "Transient"),
Check: testAccCheckKeycloakSamlIdentityProviderHasNameIdPolicyFormatValue("keycloak_saml_identity_provider.saml", "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"),
},
},
})
}

func TestAccKeycloakSamlIdentityProvider_extraConfig(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -240,6 +258,21 @@ func testAccCheckKeycloakSamlIdentityProviderHasCustomConfigValue(resourceName,
}
}

func testAccCheckKeycloakSamlIdentityProviderHasNameIdPolicyFormatValue(resourceName, nameIdPolicyFormatValue string) resource.TestCheckFunc {
return func(s *terraform.State) error {
fetchedSaml, err := getKeycloakSamlIdentityProviderFromState(s, resourceName)
if err != nil {
return err
}

if fetchedSaml.Config.NameIDPolicyFormat != nameIdPolicyFormatValue {
return fmt.Errorf("expected saml provider to have config with nameIdPolicyFormat with a value %s, but value was %s", nameIdPolicyFormatValue, fetchedSaml.Config.NameIDPolicyFormat)
}

return nil
}
}

func testAccCheckKeycloakSamlIdentityProviderDestroy() resource.TestCheckFunc {
return func(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
Expand Down Expand Up @@ -308,6 +341,23 @@ resource "keycloak_saml_identity_provider" "saml" {
`, testAccRealm.Realm, saml, providerId)
}

func testKeycloakSamlIdentityProvider_withNameIdPolicyFormat(saml, nameIdPolicyFormat string) string {
return fmt.Sprintf(`
data "keycloak_realm" "realm" {
realm = "%s"
}

resource "keycloak_saml_identity_provider" "saml" {
realm = data.keycloak_realm.realm.id
alias = "%s"
name_id_policy_format = "%s"
principal_type = "ATTRIBUTE"
entity_id = "https://example.com/entity_id"
single_sign_on_service_url = "https://example.com/auth"
}
`, testAccRealm.Realm, saml, nameIdPolicyFormat)
}

func testKeycloakSamlIdentityProvider_extra_config(alias, configKey, configValue string) string {
return fmt.Sprintf(`
data "keycloak_realm" "realm" {
Expand Down