Skip to content

Commit d33c726

Browse files
committed
[fix] Add Test for DeleteRoleScopeMapping
Signed-off-by: foch01 <[email protected]>
1 parent ad894de commit d33c726

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

provider/resource_keycloak_generic_role_mapper_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,100 @@ resource "keycloak_generic_role_mapper" "client-with-some-other-role" {
376376
}
377377
`, testAccRealm.Realm, clientName, someRoleName, someOtherRoleName)
378378
}
379+
380+
func TestAccKeycloakGenericClientRoleMapper_deleteRoleScopeMappingRealmRole(t *testing.T) {
381+
t.Parallel()
382+
383+
var role = &keycloak.Role{}
384+
var childClient = &keycloak.GenericClient{}
385+
386+
roleName := acctest.RandomWithPrefix("tf-acc")
387+
childClientName := acctest.RandomWithPrefix("tf-acc")
388+
389+
resource.Test(t, resource.TestCase{
390+
ProviderFactories: testAccProviderFactories,
391+
PreCheck: func() { testAccPreCheck(t) },
392+
Steps: []resource.TestStep{
393+
{
394+
Config: testKeycloakGenericClientRoleMapper_realmRole(roleName, childClientName),
395+
Check: resource.ComposeTestCheckFunc(
396+
testAccCheckKeycloakGenericClientRoleMapperExists("keycloak_generic_client_role_mapper.child-client-with-realm-role"),
397+
testAccCheckKeycloakRoleFetch("keycloak_role.realm-role", role),
398+
testAccCheckKeycloakGenericClientFetch("keycloak_openid_client.child-client", childClient),
399+
),
400+
},
401+
{
402+
PreConfig: func() {
403+
err := keycloakClient.DeleteRoleScopeMapping(testCtx, childClient.RealmId, childClient.Id, "", role)
404+
if err != nil {
405+
t.Fatalf("Erreur lors de la suppression du mapping de rôle realm: %s", err)
406+
}
407+
},
408+
Config: testKeycloakGenericClientRoleMapper_realmRole(roleName, childClientName),
409+
Check: testAccCheckKeycloakGenericClientRoleMapperExists("keycloak_generic_client_role_mapper.child-client-with-realm-role"),
410+
},
411+
},
412+
})
413+
}
414+
415+
func TestAccKeycloakGenericClientRoleMapper_deleteRoleScopeMappingClientRole(t *testing.T) {
416+
t.Parallel()
417+
418+
var role = &keycloak.Role{}
419+
var childClient = &keycloak.GenericClient{}
420+
421+
parentClientName := acctest.RandomWithPrefix("tf-acc")
422+
parentRoleName := acctest.RandomWithPrefix("tf-acc")
423+
childClientName := acctest.RandomWithPrefix("tf-acc")
424+
425+
resource.Test(t, resource.TestCase{
426+
ProviderFactories: testAccProviderFactories,
427+
PreCheck: func() { testAccPreCheck(t) },
428+
Steps: []resource.TestStep{
429+
{
430+
Config: testKeycloakGenericClientRoleMapper_basic(parentClientName, parentRoleName, childClientName),
431+
Check: resource.ComposeTestCheckFunc(
432+
testAccCheckKeycloakGenericClientRoleMapperExists("keycloak_generic_client_role_mapper.child-client-with-parent-client-role"),
433+
testAccCheckKeycloakRoleFetch("keycloak_role.parent-role", role),
434+
testAccCheckKeycloakGenericClientFetch("keycloak_openid_client.child-client", childClient),
435+
),
436+
},
437+
{
438+
PreConfig: func() {
439+
// Test de la nouvelle implémentation avec un rôle client (ClientRole=true)
440+
err := keycloakClient.DeleteRoleScopeMapping(testCtx, childClient.RealmId, childClient.Id, "", role)
441+
if err != nil {
442+
t.Fatalf("Erreur lors de la suppression du mapping de rôle client: %s", err)
443+
}
444+
},
445+
Config: testKeycloakGenericClientRoleMapper_basic(parentClientName, parentRoleName, childClientName),
446+
Check: testAccCheckKeycloakGenericClientRoleMapperExists("keycloak_generic_client_role_mapper.child-client-with-parent-client-role"),
447+
},
448+
},
449+
})
450+
}
451+
452+
func testKeycloakGenericClientRoleMapper_realmRole(roleName, childClientName string) string {
453+
return fmt.Sprintf(`
454+
data "keycloak_realm" "realm" {
455+
realm = "%s"
456+
}
457+
458+
resource "keycloak_role" "realm-role" {
459+
realm_id = data.keycloak_realm.realm.id
460+
name = "%s"
461+
}
462+
463+
resource "keycloak_openid_client" "child-client" {
464+
realm_id = data.keycloak_realm.realm.id
465+
client_id = "%s"
466+
access_type = "PUBLIC"
467+
}
468+
469+
resource "keycloak_generic_client_role_mapper" "child-client-with-realm-role" {
470+
realm_id = data.keycloak_realm.realm.id
471+
client_id = keycloak_openid_client.child-client.id
472+
role_id = keycloak_role.realm-role.id
473+
}
474+
`, testAccRealm.Realm, roleName, childClientName)
475+
}

0 commit comments

Comments
 (0)