Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow change of login casing #663

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/main/java/com/faforever/api/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ public void changeLoginForced(String newLogin, User user, String ipAddress) {
}

private void internalChangeLogin(String newLogin, User user, String ipAddress, boolean force) {
validateUsername(newLogin);
String oldLogin = user.getLogin();
if (!newLogin.equalsIgnoreCase(oldLogin)) {
validateUsername(newLogin);
}

if (!force) {
int minDaysBetweenChange = properties.getUser().getMinimumDaysBetweenUsernameChange();
Expand All @@ -264,9 +267,9 @@ private void internalChangeLogin(String newLogin, User user, String ipAddress, b
});

}
log.info("Changing username for user ''{}'' to ''{}'', forced:''{}''", user.getLogin(), newLogin, force);
log.info("Changing username for user ''{}'' to ''{}'', forced:''{}''", oldLogin, newLogin, force);
NameRecord nameRecord = new NameRecord()
.setName(user.getLogin())
.setName(oldLogin)
.setPlayer(playerRepository.getReferenceById(user.getId()));
nameRecordRepository.save(nameRecord);

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/faforever/api/user/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ public void changeLoginUsernameReservedBySelf() {
verify(eventPublisher).publishEvent(any(UserUpdatedEvent.class));
}

@Test
public void changeLoginCasing() {
when(userRepository.save(any(User.class))).then(invocation -> ((User) invocation.getArgument(0)).setId(TEST_USERID));

instance.changeLogin(TEST_USERNAME.toUpperCase(), validUser, IP_ADDRESS);
verify(eventPublisher).publishEvent(any(UserUpdatedEvent.class));
}

@Test
@SuppressWarnings("unchecked")
public void resetPasswordByLogin() throws Exception {
Expand Down