diff --git a/src/restconfig/src/test/java/org/geoserver/rest/security/UserRoleRestControllerTest.java b/src/restconfig/src/test/java/org/geoserver/rest/security/UserRoleRestControllerTest.java index a6db1d1cd62..21853917472 100644 --- a/src/restconfig/src/test/java/org/geoserver/rest/security/UserRoleRestControllerTest.java +++ b/src/restconfig/src/test/java/org/geoserver/rest/security/UserRoleRestControllerTest.java @@ -6,9 +6,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.io.IOException; +import org.geoserver.rest.RestException; import org.geoserver.rest.security.xml.JaxbGroupList; import org.geoserver.rest.security.xml.JaxbRoleList; import org.geoserver.rest.security.xml.JaxbUser; @@ -17,6 +19,7 @@ import org.geoserver.test.GeoServerTestSupport; import org.junit.Before; import org.junit.Test; +import org.springframework.http.HttpStatus; public class UserRoleRestControllerTest extends GeoServerTestSupport { @@ -254,4 +257,27 @@ public void testGroups() throws PasswordPolicyException, IOException { assertTrue(roles.getRoles().contains("vozen")); assertFalse(roles.getRoles().contains("kwiestenbiebel")); } + + @Test + public void testDoubleUserGroupAssociation() throws PasswordPolicyException, IOException { + + JaxbUser user = new JaxbUser(); + user.setUserName("pipo"); + user.setPassword("secret"); + user.setEnabled(true); + + usersController.insertUser(USER_SERVICE, user); + usersController.insertGroup(USER_SERVICE, "clowns"); + usersController.associateUserToGroup(USER_SERVICE, "pipo", "clowns"); + + RestException exception = + assertThrows( + RestException.class, + () -> { + usersController.associateUserToGroup(USER_SERVICE, "pipo", "clowns"); + }); + + assertEquals("Username already associated with this groupname", exception.getMessage()); + assertEquals(HttpStatus.OK, exception.getStatus()); + } }