-
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.
Add update permission on GroupPermission to allow updates to userGrou…
…p assigned permissions
- Loading branch information
1 parent
7ada576
commit 3fc1e24
Showing
5 changed files
with
253 additions
and
2 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/inttest/java/com/faforever/api/data/GroupPermissionTest.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,83 @@ | ||
package com.faforever.api.data; | ||
|
||
import com.faforever.api.AbstractIntegrationTest; | ||
import com.faforever.api.data.domain.GroupPermission; | ||
import com.faforever.api.security.OAuthScope; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.context.jdbc.Sql.ExecutionPhase; | ||
|
||
import static com.faforever.api.data.JsonApiMediaType.JSON_API_MEDIA_TYPE; | ||
import static org.hamcrest.Matchers.hasSize; | ||
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.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/truncateTables.sql") | ||
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultData.sql") | ||
public class GroupPermissionTest extends AbstractIntegrationTest { | ||
private static final String testPost = """ | ||
{ | ||
"data": { | ||
"type": "groupPermission", | ||
"attributes": { | ||
"technicalName": "test", | ||
"nameKey": "test" | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
@Test | ||
public void emptyResultWithoutScope() throws Exception { | ||
mockMvc.perform(get("/data/groupPermission") | ||
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_READ_USER_GROUP))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.data", hasSize(0))); | ||
} | ||
|
||
@Test | ||
public void emptyResultWithoutRole() throws Exception { | ||
mockMvc.perform(get("/data/groupPermission") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._READ_SENSIBLE_USERDATA, NO_AUTHORITIES))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.data", hasSize(0))); | ||
} | ||
|
||
@Test | ||
public void canReadPermissionsWithScopeAndRole() throws Exception { | ||
mockMvc.perform(get("/data/groupPermission") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._READ_SENSIBLE_USERDATA, GroupPermission.ROLE_READ_USER_GROUP))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.data", hasSize(23))); | ||
} | ||
|
||
@Test | ||
public void cannotCreatePermissionWithoutScope() throws Exception { | ||
mockMvc.perform(post("/data/groupPermission") | ||
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_WRITE_USER_GROUP)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPost)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void cannotCreatePermissionWithoutRole() throws Exception { | ||
mockMvc.perform(post("/data/groupPermission") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPost)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void cannotCreatePermissionWithScopeAndRole() throws Exception { | ||
mockMvc.perform(post("/data/groupPermission") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_WRITE_USER_GROUP)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPost)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
src/inttest/java/com/faforever/api/data/UserGroupTest.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,163 @@ | ||
package com.faforever.api.data; | ||
|
||
import com.faforever.api.AbstractIntegrationTest; | ||
import com.faforever.api.data.domain.GroupPermission; | ||
import com.faforever.api.security.OAuthScope; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.context.jdbc.Sql.ExecutionPhase; | ||
|
||
import static com.faforever.api.data.JsonApiMediaType.JSON_API_MEDIA_TYPE; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/truncateTables.sql") | ||
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultData.sql") | ||
public class UserGroupTest extends AbstractIntegrationTest { | ||
private static final String testPatch = """ | ||
{ | ||
"data": { | ||
"type": "userGroup", | ||
"id": "3", | ||
"attributes": { | ||
"public": false | ||
}, | ||
"relationships": { | ||
"members": { | ||
"data": [{ | ||
"type": "player", | ||
"id": "1" | ||
}, { | ||
"type": "player", | ||
"id": "2" | ||
} | ||
] | ||
}, | ||
"permissions": { | ||
"data": [{ | ||
"type": "groupPermission", | ||
"id": "17" | ||
}, { | ||
"type": "groupPermission", | ||
"id": "19" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
private static final String testPost = """ | ||
{ | ||
"data": { | ||
"type": "userGroup", | ||
"attributes": { | ||
"technicalName": "faf_test", | ||
"nameKey": "faf.test", | ||
"public": false | ||
}, | ||
"relationships": { | ||
"members": { | ||
"data": [] | ||
}, | ||
"permissions": { | ||
"data": [{ | ||
"type": "groupPermission", | ||
"id": "17" | ||
}, { | ||
"type": "groupPermission", | ||
"id": "19" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
@Test | ||
public void canSeePublicGroupWithoutScope() throws Exception { | ||
mockMvc.perform(get("/data/userGroup/4") | ||
.with(getOAuthTokenWithTestUser(NO_SCOPE, NO_AUTHORITIES))) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
public void cannotSeePrivateGroupWithoutScope() throws Exception { | ||
mockMvc.perform(get("/data/userGroup/5") | ||
.with(getOAuthTokenWithTestUser(NO_SCOPE, NO_AUTHORITIES))) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void cannotSeePrivateGroupWithoutRole() throws Exception { | ||
mockMvc.perform(get("/data/userGroup/5") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._READ_SENSIBLE_USERDATA, NO_AUTHORITIES))) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void canSeePrivateGroupWithScopeAndRole() throws Exception { | ||
mockMvc.perform(get("/data/userGroup/5") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._READ_SENSIBLE_USERDATA, GroupPermission.ROLE_READ_USER_GROUP))) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
public void cannotCreateUserGroupWithoutScope() throws Exception { | ||
mockMvc.perform(post("/data/userGroup") | ||
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_READ_USER_GROUP)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPost)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void cannotCreateUserGroupWithoutRole() throws Exception { | ||
mockMvc.perform(post("/data/userGroup") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPost)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void canCreateUserGroupWithScopeAndRole() throws Exception { | ||
mockMvc.perform(post("/data/userGroup") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_WRITE_USER_GROUP)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPost)) | ||
.andExpect(status().isCreated()); | ||
} | ||
|
||
@Test | ||
public void cannotUpdateUserGroupWithoutScope() throws Exception { | ||
mockMvc.perform(patch("/data/userGroup/3") | ||
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_WRITE_USER_GROUP)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPatch)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void cannotUpdateUserGroupWithoutRole() throws Exception { | ||
mockMvc.perform(patch("/data/userGroup/3") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPatch)) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void canUpdateUserGroupWithScopeAndRole() throws Exception { | ||
mockMvc.perform(patch("/data/userGroup/3") | ||
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_WRITE_USER_GROUP)) | ||
.header(HttpHeaders.CONTENT_TYPE, JSON_API_MEDIA_TYPE) | ||
.content(testPatch)) | ||
.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
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