Trim group names on group creation

Usually we trim all user input. There is no reason why group names
should be an exception.

Change-Id: I18fc1d779fe09eceeb47e2ffbdef8aee6ad02f03
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2020-02-26 13:54:35 +01:00
parent 57d514b8bc
commit c5cd6286bd
2 changed files with 8 additions and 12 deletions

View File

@@ -35,6 +35,6 @@ public class CreateGroupArgs {
}
public void setGroupName(String n) {
groupName = n != null ? AccountGroup.nameKey(n) : null;
groupName = n != null ? AccountGroup.nameKey(n.trim()) : null;
}
}

View File

@@ -362,6 +362,13 @@ public class GroupsIT extends AbstractDaemonTest {
assertGroupInfo(group(newGroupName), g);
}
@Test
public void createGroupNameIsTrimmed() throws Exception {
String newGroupName = name("newGroup");
GroupInfo g = gApi.groups().create(" " + newGroupName + " ").get();
assertGroupInfo(group(newGroupName), g);
}
@Test
public void createDuplicateInternalGroupCaseSensitiveName_Conflict() throws Exception {
String dupGroupName = name("dupGroup");
@@ -1348,17 +1355,6 @@ public class GroupsIT extends AbstractDaemonTest {
assertStaleGroupAndReindex(groupUuid);
}
@Test
public void groupNamesWithLeadingAndTrailingWhitespace() throws Exception {
for (String leading : ImmutableList.of("", " ", " ")) {
for (String trailing : ImmutableList.of("", " ", " ")) {
String name = leading + name("group") + trailing;
GroupInfo g = gApi.groups().create(name).get();
assertThat(g.name).isEqualTo(name);
}
}
}
@Test
@Sandboxed
public void groupsOfUserCanBeListedInSlaveMode() throws Exception {