Skip to content

Commit

Permalink
Set testaca path for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darcato committed Sep 27, 2024
1 parent c5289ca commit 5391195
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
@IamMockMvcIntegrationTest
@SpringBootTest(
classes = {IamLoginService.class, CoreControllerTestSupport.class, ScimRestUtilsMvc.class},
webEnvironment = WebEnvironment.MOCK)
webEnvironment = WebEnvironment.MOCK,
properties = {"x509.trustAnchorsDir=src/test/resources/test-ca"})
@WithMockOAuthUser(clientId = SCIM_CLIENT_ID, scopes = {SCIM_READ_SCOPE, SCIM_WRITE_SCOPE})
public class ScimUserProvisioningPatchRemoveTests extends ScimUserTestSupport {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,35 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import com.fasterxml.jackson.databind.ObjectMapper;

import it.infn.mw.iam.IamLoginService;
import it.infn.mw.iam.api.scim.model.ScimConstants;
import it.infn.mw.iam.api.scim.model.ScimUser;
import it.infn.mw.iam.api.scim.model.ScimUserPatchRequest;
import it.infn.mw.iam.api.scim.model.ScimX509Certificate;
import it.infn.mw.iam.persistence.model.IamAccount;
import it.infn.mw.iam.persistence.repository.IamAccountRepository;
import it.infn.mw.iam.test.core.CoreControllerTestSupport;
import it.infn.mw.iam.test.ext_authn.x509.X509TestSupport;
import it.infn.mw.iam.test.scim.ScimRestUtilsMvc;
import it.infn.mw.iam.test.util.WithMockOAuthUser;
import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest;
import it.infn.mw.iam.test.util.oauth.MockOAuth2Filter;

@RunWith(SpringRunner.class)
@IamMockMvcIntegrationTest
@WithMockOAuthUser(clientId = "scim-client-rw", scopes = {"scim:read", "scim:write"})
@SpringBootTest(
classes = {IamLoginService.class, CoreControllerTestSupport.class, ScimRestUtilsMvc.class},
webEnvironment = WebEnvironment.MOCK,
properties = {"x509.trustAnchorsDir=src/test/resources/test-ca"})
public class ScimX509Tests extends X509TestSupport implements ScimConstants {

public static final Logger LOG = LoggerFactory.getLogger(ScimX509Tests.class);
Expand All @@ -63,7 +72,7 @@ public class ScimX509Tests extends X509TestSupport implements ScimConstants {

@Autowired
private ObjectMapper mapper;

@Autowired
private MockOAuth2Filter mockOAuth2Filter;

Expand All @@ -74,7 +83,7 @@ public class ScimX509Tests extends X509TestSupport implements ScimConstants {
public void setup() {
mockOAuth2Filter.cleanupSecurityContext();
}

@After
public void teardown() throws Exception {
mockOAuth2Filter.cleanupSecurityContext();
Expand All @@ -85,8 +94,9 @@ public void testNoScimX509ForAccountWithoutCertificates() throws Exception {
IamAccount user = iamAccountRepo.findByUsername(TEST_USERNAME)
.orElseThrow(() -> new AssertionError("Expected test user not found"));

mvc.perform(get("/scim/Users/{id}", user.getUuid())).andExpect(status().isOk()).andExpect(
jsonPath("$.%s.certificates", INDIGO_USER_SCHEMA).doesNotExist());
mvc.perform(get("/scim/Users/{id}", user.getUuid()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.%s.certificates", INDIGO_USER_SCHEMA).doesNotExist());

}

Expand Down Expand Up @@ -305,17 +315,16 @@ public void testScimAddCertificateSuccess() throws Exception {

ScimUserPatchRequest patchRequest = ScimUserPatchRequest.builder().add(user).build();

mvc
.perform(patch("/scim/Users/{id}", testUser.getUuid())
.content(mapper.writeValueAsString(patchRequest)).contentType(SCIM_CONTENT_TYPE))
.andExpect(status().isNoContent());
mvc.perform(patch("/scim/Users/{id}", testUser.getUuid())
.content(mapper.writeValueAsString(patchRequest))
.contentType(SCIM_CONTENT_TYPE)).andExpect(status().isNoContent());

testUser = iamAccountRepo.findByCertificateSubject(TEST_0_SUBJECT)
.orElseThrow(() -> new AssertionError("Expected test user not found"));

assertThat(testUser.getUsername(), equalTo(TEST_USERNAME));
}

@Test
public void testScimAddCertificateFailureInvalidCertificate() throws Exception {

Expand All @@ -333,7 +342,8 @@ public void testScimAddCertificateFailureInvalidCertificate() throws Exception {

mvc
.perform(patch("/scim/Users/{id}", testUser.getUuid())
.content(mapper.writeValueAsString(patchRequest)).contentType(SCIM_CONTENT_TYPE))
.content(mapper.writeValueAsString(patchRequest))
.contentType(SCIM_CONTENT_TYPE))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.status").exists())
.andExpect(jsonPath("$.status").value(equalTo("400")))
Expand All @@ -360,8 +370,7 @@ public void testScimAddCertificateFailureCertificateAlreadyBound() throws Except
.build();

mvc
.perform(post("/scim/Users")
.content(mapper.writeValueAsString(user))
.perform(post("/scim/Users").content(mapper.writeValueAsString(user))
.contentType(SCIM_CONTENT_TYPE))
.andExpect(status().isCreated());

Expand All @@ -375,7 +384,8 @@ public void testScimAddCertificateFailureCertificateAlreadyBound() throws Except

mvc
.perform(patch("/scim/Users/{id}", testUser.getUuid())
.content(mapper.writeValueAsString(patchRequest)).contentType(SCIM_CONTENT_TYPE))
.content(mapper.writeValueAsString(patchRequest))
.contentType(SCIM_CONTENT_TYPE))
.andExpect(status().isConflict())
.andExpect(jsonPath("$.status").exists())
.andExpect(jsonPath("$.status").value(equalTo("409")))
Expand Down Expand Up @@ -416,10 +426,9 @@ public void testScimRemoveCertificateSuccess() throws Exception {
.remove(ScimUser.builder().addX509Certificate(cert).build())
.build();

mvc
.perform(patch("/scim/Users/{id}", account.getUuid())
.content(mapper.writeValueAsString(patchRequest)).contentType(SCIM_CONTENT_TYPE))
.andExpect(status().isNoContent());
mvc.perform(patch("/scim/Users/{id}", account.getUuid())
.content(mapper.writeValueAsString(patchRequest))
.contentType(SCIM_CONTENT_TYPE)).andExpect(status().isNoContent());

iamAccountRepo.findByCertificate(TEST_0_SUBJECT).ifPresent(a -> {
throw new AssertionError("Found unexpected account bound to '" + TEST_0_SUBJECT
Expand Down Expand Up @@ -447,9 +456,8 @@ public void testScimRemoveUnboundCertificateYeldsa204() throws Exception {
.remove(ScimUser.builder().addX509Certificate(cert).build())
.build();

mvc
.perform(patch("/scim/Users/{id}", testUser.getUuid())
.content(mapper.writeValueAsString(patchRequest)).contentType(SCIM_CONTENT_TYPE))
.andExpect(status().isNoContent());
mvc.perform(patch("/scim/Users/{id}", testUser.getUuid())
.content(mapper.writeValueAsString(patchRequest))
.contentType(SCIM_CONTENT_TYPE)).andExpect(status().isNoContent());
}
}

0 comments on commit 5391195

Please sign in to comment.