-
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.
- Loading branch information
Showing
26 changed files
with
676 additions
and
84 deletions.
There are no files selected for viewing
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
87 changes: 87 additions & 0 deletions
87
src/inttest/java/com/faforever/api/data/DomainBlacklistTest.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,87 @@ | ||
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.hamcrest.Matchers.hasSize; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
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/prepDomainBlacklistData.sql") | ||
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:sql/cleanDomainBlacklistData.sql") | ||
public class DomainBlacklistTest extends AbstractIntegrationTest { | ||
private static final String NEW_DOMAIN = "{\"data\":{\"type\":\"domainBlacklist\",\"id\":\"google.com\"}}"; | ||
|
||
@Test | ||
@WithUserDetails(AUTH_USER) | ||
public void emptyResultDomainBlacklistAsUser() throws Exception { | ||
mockMvc.perform(get("/data/domainBlacklist")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string("{\"data\":[]}")); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_USER) | ||
public void cannotReadSpecificDomainBlacklistAsUser() throws Exception { | ||
mockMvc.perform(get("/data/domainBlacklist/spam.org")) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_MODERATOR) | ||
public void canReadDomainBlacklistAsModerator() throws Exception { | ||
mockMvc.perform(get("/data/domainBlacklist")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.data", hasSize(1))); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_MODERATOR) | ||
public void canReadSpecificDomainBlacklistAsModerator() throws Exception { | ||
mockMvc.perform(get("/data/domainBlacklist/spam.org")) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
|
||
@Test | ||
@WithUserDetails(AUTH_USER) | ||
public void cannotCreateDomainBlacklistAsUser() throws Exception { | ||
mockMvc.perform( | ||
post("/data/domainBlacklist") | ||
.content(NEW_DOMAIN)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_MODERATOR) | ||
public void canCreateDomainBlacklistAsModerator() throws Exception { | ||
mockMvc.perform( | ||
post("/data/domainBlacklist") | ||
.content(NEW_DOMAIN)) | ||
.andExpect(status().isCreated()); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_USER) | ||
public void cannotDeleteDomainBlacklistAsUser() throws Exception { | ||
mockMvc.perform( | ||
delete("/data/domainBlacklist/spam.org")) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_MODERATOR) | ||
public void canDeleteDomainBlacklistAsModerator() throws Exception { | ||
mockMvc.perform( | ||
delete("/data/domainBlacklist/spam.org")) | ||
.andExpect(status().isNoContent()); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/inttest/java/com/faforever/api/data/UserNoteTest.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,102 @@ | ||
package com.faforever.api.data; | ||
|
||
import com.faforever.api.AbstractIntegrationTest; | ||
import com.faforever.api.player.PlayerRepository; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
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.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
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/prepUserNoteData.sql") | ||
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:sql/cleanUserNoteData.sql") | ||
public class UserNoteTest extends AbstractIntegrationTest { | ||
/* | ||
{ | ||
"data": { | ||
"type": "userNote", | ||
"attributes": { | ||
"watched": false, | ||
"note": "This note will be posted" | ||
}, | ||
"relationships": { | ||
"author": { | ||
"data": { | ||
"type": "player", | ||
"id": "1" | ||
} | ||
}, | ||
"player": { | ||
"data": { | ||
"type": "player", | ||
"id": "3" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
*/ | ||
private static final String testPost = "{\"data\":{\"type\":\"userNote\",\"attributes\":{\"watched\":false,\"note\":\"This note will be posted\"},\"relationships\":{\"author\":{\"data\":{\"type\":\"player\",\"id\":\"1\"}},\"player\":{\"data\":{\"type\":\"player\",\"id\":\"3\"}}}}}"; | ||
@Autowired | ||
PlayerRepository playerRepository; | ||
|
||
@Test | ||
@WithUserDetails(AUTH_USER) | ||
public void emptyResultUserNoteAsUser() throws Exception { | ||
mockMvc.perform(get("/data/userNote")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string("{\"data\":[]}")); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_USER) | ||
public void cannotReadSpecificUserNoteAsUser() throws Exception { | ||
mockMvc.perform(get("/data/userNote/1")) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_USER) | ||
public void cannotCreateUserNoteAsUser() throws Exception { | ||
mockMvc.perform(post("/data/userNote") | ||
.content(testPost)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_MODERATOR) | ||
public void canReadUserNoteAsModerator() throws Exception { | ||
mockMvc.perform(get("/data/userNote")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.data", hasSize(1))); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_MODERATOR) | ||
public void canReadSpecificUserNoteAsModerator() throws Exception { | ||
mockMvc.perform(get("/data/userNote/1")) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
@WithUserDetails(AUTH_MODERATOR) | ||
public void canCreateUserNoteAsModerator() throws Exception { | ||
assertThat(playerRepository.getOne(3).getUserNotes().size(), is(0)); | ||
|
||
mockMvc.perform(post("/data/userNote") | ||
.content(testPost)) | ||
.andExpect(status().isCreated()); | ||
|
||
assertThat(playerRepository.getOne(3).getUserNotes().size(), is(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
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 @@ | ||
DELETE FROM email_domain_blacklist; |
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 @@ | ||
DELETE FROM user_notes; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DELETE FROM email_domain_blacklist; | ||
INSERT INTO email_domain_blacklist VALUES ('spam.org'); |
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,8 @@ | ||
DELETE FROM ban_revoke; | ||
DELETE FROM ban; | ||
|
||
INSERT INTO login (id, login, email, password) VALUES | ||
(4, 'BANNED', 'banned@faforever.com', 'not relevant'); | ||
|
||
INSERT INTO user_notes (id, user_id, author, watched, note) VALUES | ||
(1, 4, 1, 0, 'Test user note'); |
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
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
Oops, something went wrong.