Skip to content

Commit

Permalink
Fixes #465 Maps without author can be updated by anyone
Browse files Browse the repository at this point in the history
  • Loading branch information
bukajsytlos authored and Brutus5000 committed May 18, 2021
1 parent 4ea8ae0 commit 628f7bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/main/java/com/faforever/api/map/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -343,12 +342,10 @@ private Optional<Map> validateMapMetadata(MapLuaAccessor mapLua, MapNameBuilder
Optional<Map> existingMapOptional = mapRepository.findOneByDisplayName(displayName);
existingMapOptional
.ifPresent(existingMap -> {
Optional.ofNullable(existingMap.getAuthor())
.filter(existingMapAuthor -> !Objects.equals(existingMapAuthor, author))
.ifPresent(existingMapAuthor -> {
throw ApiException.of(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, existingMap.getDisplayName());
});

final Player existingMapAuthor = existingMap.getAuthor();
if (existingMapAuthor == null || !existingMapAuthor.equals(author)) {
throw ApiException.of(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, existingMap.getDisplayName());
}
if (existingMap.getVersions().stream()
.anyMatch(mapVersion -> mapVersion.getVersion() == newVersion)) {
throw ApiException.of(ErrorCode.MAP_VERSION_EXISTS, existingMap.getDisplayName(), newVersion);
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/faforever/api/map/MapServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ void notCorrectAuthor() {
uploadFails(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, "command_conquer_rush.v0007.zip");
}

@Test
void annonymousAuthor() {
when(fafApiProperties.getMap()).thenReturn(mapProperties);

Player me = new Player();
me.setId(1);

com.faforever.api.data.domain.Map map = new com.faforever.api.data.domain.Map().setAuthor(null);
when(mapRepository.findOneByDisplayName(any())).thenReturn(Optional.of(map));

uploadFails(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, "command_conquer_rush.v0007.zip");
}

@Test
void versionExistsAlready() {
when(fafApiProperties.getMap()).thenReturn(mapProperties);
Expand Down

0 comments on commit 628f7bb

Please sign in to comment.