-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #675 from Onlineberatung/OB-6984-improve-log-error…
…-handling-for-rocketchat feat: add handling for restricted consultant admin role and improve rocketchat logging
- Loading branch information
Showing
9 changed files
with
114 additions
and
23 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
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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import static de.caritas.cob.userservice.api.adapters.web.controller.UserAdminControllerIT.ADMIN_DATA_PATH; | ||
import static de.caritas.cob.userservice.api.adapters.web.controller.UserAdminControllerIT.AGENCY_ADMIN_PATH; | ||
import static de.caritas.cob.userservice.api.adapters.web.controller.UserAdminControllerIT.CONSULTANT_PATH; | ||
import static de.caritas.cob.userservice.api.adapters.web.controller.UserAdminControllerIT.TENANT_ADMIN_PATH; | ||
import static de.caritas.cob.userservice.api.adapters.web.controller.UserAdminControllerIT.TENANT_ADMIN_PATH_WITHOUT_SLASH; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
@@ -22,6 +23,7 @@ | |
import de.caritas.cob.userservice.api.adapters.keycloak.dto.KeycloakCreateUserResponseDTO; | ||
import de.caritas.cob.userservice.api.adapters.rocketchat.RocketChatCredentialsProvider; | ||
import de.caritas.cob.userservice.api.adapters.web.dto.CreateAdminDTO; | ||
import de.caritas.cob.userservice.api.adapters.web.dto.CreateConsultantDTO; | ||
import de.caritas.cob.userservice.api.adapters.web.dto.PatchAdminDTO; | ||
import de.caritas.cob.userservice.api.adapters.web.dto.UpdateAgencyAdminDTO; | ||
import de.caritas.cob.userservice.api.adapters.web.dto.UpdateTenantAdminDTO; | ||
|
@@ -152,6 +154,60 @@ public void setUp() { | |
.thenReturn(keycloakResponse); | ||
} | ||
|
||
@Test | ||
@WithMockUser(authorities = {AuthorityValue.USER_ADMIN}) | ||
void createNewConsultant_Should_returnOk_When_requiredConsultantIsGiven() throws Exception { | ||
givenNewConsultantIsCreated(); | ||
} | ||
|
||
@Test | ||
@WithMockUser(authorities = {AuthorityValue.CREATE_NEW_CHAT}) | ||
void createNewConsultant_WithoutValidCredentials_Should_returnAccessDenied() throws Exception { | ||
// given | ||
CreateConsultantDTO createAdminDTO = new EasyRandom().nextObject(CreateConsultantDTO.class); | ||
createAdminDTO.setEmail("[email protected]"); | ||
|
||
// when, then | ||
this.mockMvc | ||
.perform( | ||
post(CONSULTANT_PATH) | ||
.cookie(CSRF_COOKIE) | ||
.header(CSRF_HEADER, CSRF_VALUE) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(createAdminDTO))) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
@WithMockUser(authorities = {AuthorityValue.CONSULTANT_CREATE_UPDATE}) | ||
void createNewConsultant_WithAuthorityConsultantCreateUpdate_Should_returnOK() throws Exception { | ||
givenNewConsultantIsCreated(); | ||
} | ||
|
||
private String givenNewConsultantIsCreated() throws Exception { | ||
// given | ||
CreateConsultantDTO createAdminDTO = new EasyRandom().nextObject(CreateConsultantDTO.class); | ||
createAdminDTO.setEmail("[email protected]"); | ||
|
||
// when | ||
MvcResult mvcResult = | ||
this.mockMvc | ||
.perform( | ||
post(CONSULTANT_PATH) | ||
.cookie(CSRF_COOKIE) | ||
.header(CSRF_HEADER, CSRF_VALUE) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(createAdminDTO))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("_embedded.id", notNullValue())) | ||
.andExpect(jsonPath("_embedded.username", notNullValue())) | ||
.andExpect(jsonPath("_embedded.lastname", notNullValue())) | ||
.andExpect(jsonPath("_embedded.email", is("[email protected]"))) | ||
.andReturn(); | ||
String content = mvcResult.getResponse().getContentAsString(); | ||
return JsonPath.read(content, "_embedded.id"); | ||
} | ||
|
||
@Test | ||
@WithMockUser(authorities = {AuthorityValue.USER_ADMIN}) | ||
void createNewAgencyAdmin_Should_returnOk_When_requiredCreateAgencyAdminIsGiven() | ||
|
Oops, something went wrong.