Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 5430139e authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

fix gitlab failed plans

parent 8aa8acb2
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ import org.springframework.web.context.WebApplicationContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
......@@ -131,6 +132,11 @@ public class MockMvcUtils {
return mapper.readValue(asByteArray, UserRO.class);
}
public static <T> T getObjectFromResponse(MvcResult result, Class<T> clazz)
throws IOException {
return mapper.readValue(result.getResponse().getContentAsByteArray(), clazz);
}
public static MockMvc initializeMockMvc(WebApplicationContext webAppContext) {
MockMvc mvc = MockMvcBuilders.webAppContextSetup(webAppContext)
.apply(SecurityMockMvcConfigurers.springSecurity())
......
......@@ -33,8 +33,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import static eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils.getLoggedUserData;
import static eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils.loginWithSystemAdmin;
import static eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils.*;
import static eu.europa.ec.edelivery.smp.ui.ResourceConstants.CONTEXT_PATH_INTERNAL_KEYSTORE;
import static org.junit.Assert.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
......@@ -97,7 +96,6 @@ public class KeystoreResourceIntegrationTest {
}
@Test
@Ignore("Fix on gitlab!")
public void uploadKeystoreFailed() throws Exception {
// given when
// login
......@@ -105,20 +103,17 @@ public class KeystoreResourceIntegrationTest {
UserRO userRO = getLoggedUserData(mvc, session);
MvcResult result = mvc.perform(post(PATH + "/" + userRO.getUserId() + "/upload/JKS/test123")
.session(session)
.with(csrf())
.content("invalid keystore")).
.with(csrf())).
andExpect(status().isOk()).andReturn();
//then
ObjectMapper mapper = getObjectMapper();
KeystoreImportResult res = mapper.readValue(result.getResponse().getContentAsString(), KeystoreImportResult.class);
KeystoreImportResult res = getObjectFromResponse(result, KeystoreImportResult.class);
assertNotNull(res);
assertEquals("java.io.IOException occurred while reading the keystore: Invalid keystore format", res.getErrorMessage());
}
@Test
@Ignore("Fix on gitlab!")
public void uploadKeystoreInvalidPassword() throws Exception {
// login
MockHttpSession session = loginWithSystemAdmin(mvc);
......@@ -131,9 +126,7 @@ public class KeystoreResourceIntegrationTest {
.andExpect(status().isOk()).andReturn();
//then
ObjectMapper mapper = getObjectMapper();
KeystoreImportResult res = mapper.readValue(result.getResponse().getContentAsString(), KeystoreImportResult.class);
KeystoreImportResult res = getObjectFromResponse(result, KeystoreImportResult.class);
assertNotNull(res);
assertEquals("java.io.IOException occurred while reading the keystore: Keystore was tampered with, or password was incorrect", res.getErrorMessage());
}
......@@ -152,8 +145,7 @@ public class KeystoreResourceIntegrationTest {
.andExpect(status().isOk()).andReturn();
//then
ObjectMapper mapper = getObjectMapper();
KeystoreImportResult res = mapper.readValue(result.getResponse().getContentAsString(), KeystoreImportResult.class);
KeystoreImportResult res = getObjectFromResponse(result, KeystoreImportResult.class);
assertNotNull(res);
assertNull(res.getErrorMessage());
......@@ -173,9 +165,8 @@ public class KeystoreResourceIntegrationTest {
.with(csrf()))
.andExpect(status().isOk()).andReturn();
//them
ObjectMapper mapper = getObjectMapper();
CertificateRO res = mapper.readValue(result.getResponse().getContentAsString(), CertificateRO.class);
//then
CertificateRO res = getObjectFromResponse(result, CertificateRO.class);
assertNotNull(res);
assertNull(res.getActionMessage());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment