-
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 #184 add permissions to DomainBlacklist
- Loading branch information
1 parent
0a9aed7
commit 66db6eb
Showing
5 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
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()); | ||
} | ||
} |
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,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
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