@Test
public void create_group_on_default_organization() throws Exception {
- loginAsAdmin();
+ loginAsAdminOnDefaultOrganization();
newRequest()
.setParam("name", "some-product-bu")
" }" +
"}");
- assertThat(db.users().selectGroup(defaultOrganizationProvider.getDto(), "some-product-bu")).isPresent();
+ assertThat(db.users().selectGroup(db.getDefaultOrganization(), "some-product-bu")).isPresent();
}
@Test
public void create_group_on_specific_organization() throws Exception {
OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+ loginAsAdmin(org);
- loginAsAdmin();
newRequest()
.setParam("organization", org.getKey())
.setParam("name", "some-product-bu")
assertThat(createdGroup.getOrganizationUuid()).isEqualTo(org.getUuid());
}
- @Test(expected = ForbiddenException.class)
- public void require_admin_permission() throws Exception {
+ @Test
+ public void fail_if_not_administrator() throws Exception {
userSession.login("not-admin");
+ expectedException.expect(ForbiddenException.class);
+
newRequest()
.setParam("name", "some-product-bu")
.setParam("description", "Business Unit for Some Awesome Product")
.execute();
}
+ @Test
+ public void fail_if_administrator_of_another_organization() throws Exception {
+ OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
+ OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
+ loginAsAdmin(org2);
+
+ expectedException.expect(ForbiddenException.class);
+
+ newRequest()
+ .setParam("organization", org1.getKey())
+ .setParam("name", "some-product-bu")
+ .setParam("description", "Business Unit for Some Awesome Product")
+ .execute();
+ }
+
@Test(expected = IllegalArgumentException.class)
public void fail_if_name_is_too_short() throws Exception {
- loginAsAdmin();
+ loginAsAdminOnDefaultOrganization();
newRequest()
.setParam("name", "")
.execute();
@Test(expected = IllegalArgumentException.class)
public void fail_if_name_is_too_long() throws Exception {
- loginAsAdmin();
+ loginAsAdminOnDefaultOrganization();
newRequest()
.setParam("name", StringUtils.repeat("a", 255 + 1))
.execute();
@Test(expected = IllegalArgumentException.class)
public void fail_if_name_is_anyone() throws Exception {
- loginAsAdmin();
+ loginAsAdminOnDefaultOrganization();
newRequest()
.setParam("name", "AnYoNe")
.execute();
@Test
public void fail_if_group_with_same_name_already_exists() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "the-group");
+ GroupDto group = db.users().insertGroup();
+ loginAsAdminOnDefaultOrganization();
expectedException.expect(ServerException.class);
expectedException.expectMessage("Group '" + group.getName() + "' already exists");
- loginAsAdmin();
newRequest()
.setParam("name", group.getName())
.execute();
public void fail_if_group_with_same_name_already_exists_in_the_organization() throws Exception {
OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
GroupDto group = db.users().insertGroup(org, "the-group");
+ loginAsAdmin(org);
expectedException.expect(ServerException.class);
expectedException.expectMessage("Group '" + group.getName() + "' already exists");
- loginAsAdmin();
newRequest()
.setParam("organization", org.getKey())
.setParam("name", group.getName())
OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
GroupDto group = db.users().insertGroup(org1, name);
+ loginAsAdmin(org2);
- loginAsAdmin();
newRequest()
.setParam("organization", org2.getKey())
.setParam("name", name)
@Test(expected = IllegalArgumentException.class)
public void fail_if_description_is_too_long() throws Exception {
- loginAsAdmin();
+ loginAsAdminOnDefaultOrganization();
newRequest()
.setParam("name", "long-desc")
.setParam("description", StringUtils.repeat("a", 1_000))
return ws.newPostRequest("api/user_groups", "create");
}
- private void loginAsAdmin() {
- userSession.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ private void loginAsAdminOnDefaultOrganization() {
+ loginAsAdmin(db.getDefaultOrganization());
+ }
+
+ private void loginAsAdmin(OrganizationDto org) {
+ userSession.login().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
}
private GroupWsSupport newGroupWsSupport() {