-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #213
- Loading branch information
Showing
7 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/inttest/java/com/faforever/api/data/MapVersionElideTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.faforever.api.data; | ||
|
||
import com.faforever.api.AbstractIntegrationTest; | ||
import org.junit.Test; | ||
import org.springframework.security.test.context.support.WithUserDetails; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.context.jdbc.Sql.ExecutionPhase; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultUser.sql") | ||
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepMapVersion.sql") | ||
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:sql/cleanMapVersion.sql") | ||
public class MapVersionElideTest extends AbstractIntegrationTest { | ||
|
||
private static final String MAP_VERSION_HIDE_FALSE_ID_1 = "{\n" + | ||
" \"data\": {\n" + | ||
" \"type\": \"mapVersion\",\n" + | ||
" \"id\": \"1\",\n" + | ||
" \"attributes\": {\n" + | ||
" \t\"hidden\": false\n" + | ||
" }\n" + | ||
" } \n" + | ||
"}"; | ||
private static final String MAP_VERSION_HIDE_TRUE_ID_1 = "{\n" + | ||
" \"data\": {\n" + | ||
" \"type\": \"mapVersion\",\n" + | ||
" \"id\": \"1\",\n" + | ||
" \"attributes\": {\n" + | ||
" \t\"hidden\": true\n" + | ||
" }\n" + | ||
" } \n" + | ||
"}"; | ||
private static final String MAP_VERSION_RANKED_FALSE_ID_1 = "{\n" + | ||
" \"data\": {\n" + | ||
" \"type\": \"mapVersion\",\n" + | ||
" \"id\": \"1\",\n" + | ||
" \"attributes\": {\n" + | ||
" \t\"ranked\": false\n" + | ||
" }\n" + | ||
" } \n" + | ||
"}"; | ||
private static final String MAP_VERSION_RANKED_TRUE_ID_1 = "{\n" + | ||
" \"data\": {\n" + | ||
" \"type\": \"mapVersion\",\n" + | ||
" \"id\": \"1\",\n" + | ||
" \"attributes\": {\n" + | ||
" \t\"ranked\": true\n" + | ||
" }\n" + | ||
" } \n" + | ||
"}"; | ||
|
||
|
||
@WithUserDetails(AUTH_USER) | ||
@Test | ||
public void testUpdateHideToTrueDoesWork() throws Exception { | ||
mockMvc.perform( | ||
patch("/data/mapVersion/1") | ||
.content(MAP_VERSION_HIDE_TRUE_ID_1)) | ||
.andExpect(status().isNoContent()); | ||
} | ||
|
||
@WithUserDetails(AUTH_USER) | ||
@Test | ||
public void testUpdateHideToFalseDoesNotWork() throws Exception { | ||
mockMvc.perform( | ||
patch("/data/mapVersion/1") | ||
.content(MAP_VERSION_HIDE_FALSE_ID_1)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
|
||
@WithUserDetails(AUTH_USER) | ||
@Test | ||
public void testUpdateRankedToFalseDoesWork() throws Exception { | ||
mockMvc.perform( | ||
patch("/data/mapVersion/1") | ||
.content(MAP_VERSION_RANKED_FALSE_ID_1)) | ||
.andExpect(status().isNoContent()); | ||
} | ||
|
||
@WithUserDetails(AUTH_USER) | ||
@Test | ||
public void testUpdateRankedToTrueDoesNotWork() throws Exception { | ||
mockMvc.perform( | ||
patch("/data/mapVersion/1") | ||
.content(MAP_VERSION_RANKED_TRUE_ID_1)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DELETE FROM map_version; | ||
DELETE FROM map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
DELETE FROM map_version; | ||
DELETE FROM map; | ||
|
||
INSERT INTO map (id, display_name, map_type, battle_type, author) VALUES (1, 'display name', 'mtype', 'btype', 1); | ||
INSERT INTO map_version (id, description, max_players, width, height, version, filename, map_id, hidden, ranked) | ||
VALUES (1, 'des', 2, 2, 2, 1, 'map/ghb.zip', 1, 0, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/faforever/api/data/checks/BooleanChange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.faforever.api.data.checks; | ||
|
||
import com.yahoo.elide.security.ChangeSpec; | ||
import com.yahoo.elide.security.RequestScope; | ||
import com.yahoo.elide.security.checks.OperationCheck; | ||
|
||
import java.util.Optional; | ||
|
||
public class BooleanChange { | ||
|
||
public static final String TO_FALSE_EXPRESSION = "boolean changed to false"; | ||
public static final String TO_TRUE_EXPRESSION = "boolean changed to true"; | ||
|
||
|
||
public static class ToFalse extends OperationCheck<Object> { | ||
|
||
@Override | ||
public boolean ok(Object entity, RequestScope requestScope, Optional<ChangeSpec> optionalChangeSpec) { | ||
if (!optionalChangeSpec.isPresent()) { | ||
return true; | ||
} | ||
ChangeSpec changeSpec = optionalChangeSpec.get(); | ||
if (!(changeSpec.getModified() instanceof Boolean)) { | ||
throw new IllegalStateException("This Expression can only be applied to boolean fields"); | ||
} | ||
return !((Boolean) changeSpec.getModified()); | ||
} | ||
|
||
} | ||
|
||
public static class ToTrue extends OperationCheck<Object> { | ||
|
||
@Override | ||
public boolean ok(Object entity, RequestScope requestScope, Optional<ChangeSpec> optionalChangeSpec) { | ||
if (!optionalChangeSpec.isPresent()) { | ||
return true; | ||
} | ||
ChangeSpec changeSpec = optionalChangeSpec.get(); | ||
if (!(changeSpec.getModified() instanceof Boolean)) { | ||
throw new IllegalStateException("This Expression can only be applied to boolean fields"); | ||
} | ||
return ((Boolean) changeSpec.getModified()); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters