From 35efa40ebbce0c6d693159e10f9179dcc7375ef9 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 9 Sep 2022 09:58:36 +0200 Subject: [PATCH] fix role generation for contact+person --- .../resources/db/changelog/203-hs-admin-contact-rbac.sql | 2 +- .../resources/db/changelog/213-hs-admin-person-rbac.sql | 2 +- .../contact/HsAdminContactRepositoryIntegrationTest.java | 8 ++++++-- .../person/HsAdminPersonRepositoryIntegrationTest.java | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/resources/db/changelog/203-hs-admin-contact-rbac.sql b/src/main/resources/db/changelog/203-hs-admin-contact-rbac.sql index b1557dcd..63f19c09 100644 --- a/src/main/resources/db/changelog/203-hs-admin-contact-rbac.sql +++ b/src/main/resources/db/changelog/203-hs-admin-contact-rbac.sql @@ -26,7 +26,7 @@ begin return roleDescriptor('hs_admin_contact', contact.uuid, 'owner'); end; $$; -create or replace function hsAdminContactOwner(contact hs_admin_contact) +create or replace function hsAdminContactAdmin(contact hs_admin_contact) returns RbacRoleDescriptor language plpgsql strict as $$ diff --git a/src/main/resources/db/changelog/213-hs-admin-person-rbac.sql b/src/main/resources/db/changelog/213-hs-admin-person-rbac.sql index 26b86084..906263e0 100644 --- a/src/main/resources/db/changelog/213-hs-admin-person-rbac.sql +++ b/src/main/resources/db/changelog/213-hs-admin-person-rbac.sql @@ -26,7 +26,7 @@ begin return roleDescriptor('hs_admin_person', person.uuid, 'owner'); end; $$; -create or replace function hsAdminPersonOwner(person hs_admin_person) +create or replace function hsAdminPersonAdmin(person hs_admin_person) returns RbacRoleDescriptor language plpgsql strict as $$ diff --git a/src/test/java/net/hostsharing/hsadminng/hs/admin/contact/HsAdminContactRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/admin/contact/HsAdminContactRepositoryIntegrationTest.java index c982f1d8..3d4a5d72 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/admin/contact/HsAdminContactRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/admin/contact/HsAdminContactRepositoryIntegrationTest.java @@ -14,6 +14,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.annotation.DirtiesContext; +import org.testcontainers.junit.jupiter.Container; import javax.persistence.EntityManager; import javax.servlet.http.HttpServletRequest; @@ -50,6 +51,9 @@ class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest { @MockBean HttpServletRequest request; + @Container + Container postgres; + @Nested class CreateContact { @@ -104,13 +108,13 @@ class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest { // then final var roles = roleRepo.findAll(); assertThat(roleNamesOf(roles)).containsAll(List.of( - "hs_admin_contact#anothernewcontact.admin", + "hs_admin_contact#anothernewcontact.owner", "hs_admin_contact#anothernewcontact.tenant")); assertThat(roles.size()).as("invalid number of roles created") .isEqualTo(initialRoleCount + 2); final var grants = grantRepo.findAll(); assertThat(grantDisplaysOf(grants)).containsAll(List.of( - "{ grant assumed role hs_admin_contact#anothernewcontact.admin to user drew@hostsharing.org by role global#global.admin }")); + "{ grant assumed role hs_admin_contact#anothernewcontact.owner to user drew@hostsharing.org by role global#global.admin }")); assertThat(grants.size()).as("invalid number of grants created") .isEqualTo(initialGrantCount + 1); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/admin/person/HsAdminPersonRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/admin/person/HsAdminPersonRepositoryIntegrationTest.java index 71e957f6..345c180f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/admin/person/HsAdminPersonRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/admin/person/HsAdminPersonRepositoryIntegrationTest.java @@ -104,13 +104,13 @@ class HsAdminPersonRepositoryIntegrationTest extends ContextBasedTest { // then final var roles = roleRepo.findAll(); assertThat(roleNamesOf(roles)).containsAll(List.of( - "hs_admin_person#anothernewperson.admin", + "hs_admin_person#anothernewperson.owner", "hs_admin_person#anothernewperson.tenant")); assertThat(roles.size()).as("invalid number of roles created") .isEqualTo(initialRoleCount + 2); final var grants = grantRepo.findAll(); assertThat(grantDisplaysOf(grants)).containsAll(List.of( - "{ grant assumed role hs_admin_person#anothernewperson.admin to user drew@hostsharing.org by role global#global.admin }")); + "{ grant assumed role hs_admin_person#anothernewperson.owner to user drew@hostsharing.org by role global#global.admin }")); assertThat(grants.size()).as("invalid number of grants created") .isEqualTo(initialGrantCount + 1); }