Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Smythe authored and github-actions[bot] committed Jul 17, 2024
1 parent a46f6c7 commit fc22ad7
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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());
}
}

0 comments on commit fc22ad7

Please sign in to comment.