JPA Refactoring (3) (#2109)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-12-02 13:50:06 +02:00
committed by GitHub
parent 794f26bea2
commit a9f3d1491a
37 changed files with 151 additions and 246 deletions

View File

@@ -46,7 +46,7 @@ public class CorsTest extends AbstractSecurityTest {
@Test
@Description("Ensures that Cors is working.")
@WithUser(authorities = SpRole.TENANT_ADMIN)
@WithUser(authorities = SpRole.TENANT_ADMIN, autoCreateTenant = false)
public void validateCorsRequest() throws Exception {
performOptionsRequestToRestWithOrigin(ALLOWED_ORIGIN_FIRST).andExpect(status().isOk())
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, ALLOWED_ORIGIN_FIRST));

View File

@@ -30,56 +30,46 @@ public class PreAuthorizeEnabledTest extends AbstractSecurityTest {
@Test
@Description("Tests whether request fail if a role is forbidden for the user")
@WithUser(authorities = { SpPermission.READ_TARGET })
@WithUser(authorities = { SpPermission.READ_TARGET }, autoCreateTenant = false)
public void failIfNoRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets"))
.andExpect(result ->
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.FORBIDDEN.value()));
.andExpect(result -> assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.FORBIDDEN.value()));
}
@Test
@Description("Tests whether request succeed if a role is granted for the user")
@WithUser(authorities = { SpPermission.READ_REPOSITORY })
@WithUser(authorities = { SpPermission.READ_REPOSITORY }, autoCreateTenant = false)
public void successIfHasRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets"))
.andExpect(result -> {
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
});
.andExpect(result -> assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()));
}
@Test
@Description("Tests whether request succeed if a role is granted for the user")
@WithUser(authorities = { SpRole.TENANT_ADMIN })
@WithUser(authorities = { SpRole.TENANT_ADMIN }, autoCreateTenant = false)
public void successIfHasTenantAdminRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets"))
.andExpect(result -> {
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
});
.andExpect(result -> assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()));
}
@Test
@Description("Tests whether read tenant config request fail if a tenant config (or read read) is not " +
"granted for the user")
@WithUser(authorities = { SpPermission.READ_TARGET })
@Description("Tests whether read tenant config request fail if a tenant config (or read read) is not granted for the user")
@WithUser(authorities = { SpPermission.READ_TARGET }, autoCreateTenant = false)
public void onlyDSIfNoTenantConfig() throws Exception {
mvc.perform(get("/rest/v1/system/configs"))
.andExpect(result -> {
// returns default DS type because of READ_TARGET
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(
new ObjectMapper().reader().readValue(result.getResponse().getContentAsString(), HashMap.class)
.size())
assertThat(new ObjectMapper().reader().readValue(result.getResponse().getContentAsString(), HashMap.class).size())
.isEqualTo(1);
});
}
@Test
@Description("Tests whether read tenant config request succeed if a tenant config (not read explicitly) is " +
"granted for the user")
@WithUser(authorities = { SpPermission.TENANT_CONFIGURATION })
@Description("Tests whether read tenant config request succeed if a tenant config (not read explicitly) is granted for the user")
@WithUser(authorities = { SpPermission.TENANT_CONFIGURATION }, autoCreateTenant = false)
public void successIfHasTenantConfig() throws Exception {
mvc.perform(get("/rest/v1/system/configs"))
.andExpect(result ->
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()));
.andExpect(result -> assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()));
}
}