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

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

Enable unit tests

parent 8d0dd798
No related branches found
No related tags found
No related merge requests found
Showing
with 32 additions and 34 deletions
......@@ -48,6 +48,9 @@ public class DBUserToUserROConverter implements Converter<DBUser, UserRO> {
if (!credentials.isEmpty()) {
// expected only one username/password
DBCredential credential = credentials.get(0);
target.setPasswordExpired(credential.getExpireOn() == null || OffsetDateTime.now().isAfter(credential.getExpireOn()));
target.setPasswordUpdatedOn(credential.getChangedOn());
target.setPasswordExpireOn(credential.getExpireOn());
target.setPasswordExpired(isCredentialExpired(credential));
......
package eu.europa.ec.edelivery.smp.conversion;
import eu.europa.ec.edelivery.smp.data.dao.CredentialDao;
import eu.europa.ec.edelivery.smp.data.enums.CredentialTargetType;
import eu.europa.ec.edelivery.smp.data.enums.CredentialType;
import eu.europa.ec.edelivery.smp.data.model.user.DBCertificate;
import eu.europa.ec.edelivery.smp.data.model.user.DBCredential;
......@@ -18,6 +19,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.convert.ConversionService;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -28,7 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(MockitoJUnitRunner.class)
@Ignore
public class DBUserToUserROConverterTest {
private DBUser source;
......@@ -53,6 +54,10 @@ public class DBUserToUserROConverterTest {
@Test
public void returnsThePasswordAsExpiredWhenConvertingAnExistingUserThatHasAPasswordThatHasBeenRecentlyReset() {
givenAnExistingUserHavingAPasswordThatHasJustBeenReset();
List<DBCredential> credentialList = source.getUserCredentials();
Mockito.doReturn(credentialList).when(credentialDao).findUserCredentialForByUserIdTypeAndTarget(Mockito.any(),
Mockito.any(CredentialType.class),
Mockito.any(CredentialTargetType.class));
whenConvertingTheExistingUser();
......@@ -72,7 +77,10 @@ public class DBUserToUserROConverterTest {
@Test
public void returnsThePasswordAsExpiredWhenConvertingAnExistingUserThatHasAPasswordChangedMoreThanThreeMonthsAgo() {
givenAnExistingUserHavingAPasswordThatChangedMoreThanThreeMonthsAgo();
List<DBCredential> credentialList = source.getUserCredentials();
Mockito.doReturn(credentialList).when(credentialDao).findUserCredentialForByUserIdTypeAndTarget(Mockito.any(),
Mockito.any(CredentialType.class),
Mockito.any(CredentialTargetType.class));
whenConvertingTheExistingUser();
thenThePasswordIsMarkedAsExpired("The passwords should be marked as expired when converting users having password they have changed more than 3 months ago");
......@@ -97,22 +105,22 @@ public class DBUserToUserROConverterTest {
private void givenAnExistingUser(String password, OffsetDateTime passwordChange, DBCertificate certificate) {
source = new DBUser();
/*
Optional<DBCredential> optUserPassCred = source.getCredentials().stream().filter(credential -> credential.getCredentialType() == CredentialType.USERNAME_PASSWORD).findFirst();
Optional<DBCredential> optCertCred = source.getCredentials().stream().filter(credential -> credential.getCredentialType() == CredentialType.CERTIFICATE).findFirst();
Optional<DBCredential> optUserPassCred = source.getUserCredentials().stream().filter(credential -> credential.getCredentialType() == CredentialType.USERNAME_PASSWORD).findFirst();
Optional<DBCredential> optCertCred = source.getUserCredentials().stream().filter(credential -> credential.getCredentialType() == CredentialType.CERTIFICATE).findFirst();
if (StringUtils.isNotBlank(password)) {
DBCredential credential =optUserPassCred.orElse(new DBCredential());
if (credential.getUser()==null){
credential.setUser(source);
credential.setCredentialType(CredentialType.USERNAME_PASSWORD);
source.addCredentials(credential);
source.getUserCredentials().add(credential);
}
credential.setValue(password);
credential.setChangedOn(passwordChange);
credential.setExpireOn(passwordChange != null ? passwordChange.plusMonths(3) : null);
} else if (optUserPassCred.isPresent()) {
source.removeCredentials(optUserPassCred.get());
source.getUserCredentials().remove(optUserPassCred.get());
}
if (certificate!=null) {
......@@ -120,7 +128,7 @@ public class DBUserToUserROConverterTest {
if (credential.getUser()==null){
credential.setUser(source);
credential.setCredentialType(CredentialType.CERTIFICATE);
source.addCredentials(credential);
source.getUserCredentials().add(credential);
}
credential.setCertificate(certificate);
credential.setValue(certificate.getCertificateId());
......@@ -128,10 +136,10 @@ public class DBUserToUserROConverterTest {
credential.setExpireOn(certificate.getValidTo());
credential.setExpireOn(certificate.getValidFrom());
} else if (optCertCred.isPresent()) {
source.removeCredentials(optCertCred.get());
source.getUserCredentials().remove(optCertCred.get());
}
*/
}
private void whenConvertingTheExistingUser() {
......
......@@ -31,12 +31,10 @@ import java.util.Collections;
@Component
public class SMPAuthenticationProvider implements AuthenticationProvider {
private static final SMPLogger LOG = SMPLoggerFactory.getLogger(SMPAuthenticationProvider.class);
final CredentialService credentialService;
@Autowired
public SMPAuthenticationProvider(CredentialService credentialService) {
......
......@@ -61,7 +61,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@TestPropertySource(properties = {
"smp.automation.authentication.external.tls.clientCert.enabled=true",
})
@Ignore
public class SecurityConfigurationClientCertTest {
//Jul++9+23:59:00+2019+GMT"
......
......@@ -31,8 +31,8 @@ import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.web.context.WebApplicationContext;
import java.io.IOException;
......@@ -47,7 +47,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
/**
* Created by gutowpa on 20/02/2017.
*/
@Ignore
@RunWith(SpringRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = {SmpTestWebAppConfig.class})
......@@ -65,7 +64,7 @@ public class SecurityConfigurationTest {
public static final String CLIENT_CERT_VALID_HEADER_UPPER_SN = "sno=BB66&subject=C=BE,O=org,CN=common name&validfrom=Dec 6 17:41:42 2016 GMT&validto=Jul 9 23:59:00 2050 GMT&issuer=C=x,O=y,CN=z";
public static final String TEST_USERNAME_CLIENT_CERT = "CN=common name,O=org,C=BE:000000000000bb66";
public static final String CLIENT_CERT_VALID_HEADER_DB_UPPER_SN = "sno=BB66&subject=CN=common name UPPER database SN,O=org,C=BE&validfrom=Dec 6 17:41:42 2016 GMT&validto=Jul 9 23:59:00 2050 GMT&issuer=C=x,O=y,CN=z";
public static final String TEST_USERNAME_CLIENT_CERT__DB_UPPER_SN = "CN=common name UPPER database SN,O=org,C=BE:000000000000bb66";
public static final String TEST_USERNAME_CLIENT_CERT_DB_UPPER_SN = "CN=common name UPPER database SN,O=org,C=BE:000000000000bb66";
public static final String CLIENT_CERT_NOT_AUTHORIZED_HEADER = "sno=bb61&subject=C=BE,O=org,CN=common name not exists&validfrom=Dec 6 17:41:42 2016 GMT&validto=Jul 9 23:59:00 2050 GMT&issuer=C=x,O=y,CN=z";
@Autowired
......@@ -167,6 +166,7 @@ public class SecurityConfigurationTest {
}
@Test
@Ignore
public void validClientCertHeaderAuthorizedBeforeValidBasicAuthTest() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER);
......@@ -179,6 +179,7 @@ public class SecurityConfigurationTest {
}
@Test
@Ignore
public void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestUpper() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER_UPPER_SN);
......@@ -192,6 +193,7 @@ public class SecurityConfigurationTest {
@Test
@Ignore
public void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestDBUpperSN() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER_DB_UPPER_SN);
......@@ -200,10 +202,11 @@ public class SecurityConfigurationTest {
.with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD))
.with(csrf()))
.andExpect(status().isOk())
.andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT__DB_UPPER_SN))).toString();
.andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT_DB_UPPER_SN))).toString();
}
@Test
@Ignore
public void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestUpperDBUpperSN() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER_DB_UPPER_SN);
......@@ -212,7 +215,7 @@ public class SecurityConfigurationTest {
.with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD))
.with(csrf()))
.andExpect(status().isOk())
.andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT__DB_UPPER_SN)));
.andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT_DB_UPPER_SN)));
}
......
......@@ -72,7 +72,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
"classpath:/cleanup-database.sql",
"classpath:/webapp_integration_test_data.sql"},
executionPhase = BEFORE_TEST_METHOD)
@Ignore
public class SignatureValidatorTest {
protected Path resourceDirectory = Paths.get("src", "test", "resources", "keystores");
......@@ -142,13 +141,9 @@ public class SignatureValidatorTest {
private void commonTest(String serviceGroupId, Principal principal, String filePathToLoad, String signedByCustomizedSignatureFilePath, String defaultSignatureFilePath) throws Throwable {
//given
String documentTypeId = encode("ehealth-resid-qns::urn::epsos##services:extended:epsos::107", "UTF-8");
//String documentTypeId = Identifiers.asString(new DocumentIdentifier(encode("ehealth-resid-qns::urn::epsos##services:extended:epsos::107", "UTF-8"), "ehealth-resid-qns"));
//ServiceMetadataInterface serviceMetadataInterface = new ServiceMetadataInterface();
PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(principal, "N/A");
authentication.setDetails(principal);
SecurityContextHolder.getContext().setAuthentication(authentication);
//serviceMetadataInterface.setHeaders(new DefaultHttpHeader());
//Sign w/ Customized Signature
Document docPutRequest = SignatureUtil.loadDocument(filePathToLoad);
......@@ -159,7 +154,6 @@ public class SignatureValidatorTest {
//When
//Save ServiceMetadata
//serviceMetadataInterface.saveServiceRegistration(serviceGroupId, documentTypeId, signedByCustomizedSignature);
mvc.perform(put(uri).header("Domain", "domain")
.with(ADMIN_CREDENTIALS)
.contentType(APPLICATION_XML_VALUE)
......@@ -167,7 +161,6 @@ public class SignatureValidatorTest {
.andExpect(status().is2xxSuccessful());
//Retrieve saved ServiceMetadata
//Document response = serviceMetadataInterface.getServiceRegistration(serviceGroupId, documentTypeId);
String responseStr = mvc.perform(get(uri))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
......
......@@ -44,7 +44,6 @@ public class SMPAuthenticationProviderTest {
// response time for existing and non existing user should be "approx. equal"
@Test
@Ignore
public void authenticateByAccessTokenResponseTime() {
/*
UsernamePasswordAuthenticationToken userToken = new UsernamePasswordAuthenticationToken("User", "User");
......
......@@ -16,7 +16,6 @@ package eu.europa.ec.edelivery.smp.controllers;
import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig;
import eu.europa.ec.edelivery.smp.test.testutils.X509CertificateTestUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -57,8 +56,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@Sql(scripts = {"classpath:/cleanup-database.sql",
"classpath:/webapp_integration_test_data.sql"},
executionPhase = BEFORE_TEST_METHOD)
@Ignore
public class ServiceGroupControllerSingleDomainTest {
public class ResourceControllerSingleDomainTest {
private static final String IDENTIFIER_SCHEME = "ehealth-participantid-qns";
private static final String PARTICIPANT_ID = "urn:poland:ncpb";
......@@ -74,8 +72,7 @@ public class ServiceGroupControllerSingleDomainTest {
private static final String HTTP_HEADER_KEY_SERVICE_GROUP_OWNER = "ServiceGroup-Owner";
private static final String OTHER_OWNER_NAME = "CN=EHEALTH_SMP_TEST_BRAZIL,O=European Commission,C=BE:48b681ee8e0dcc08";
private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("pat_smp_admin", "test123");
private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("pat_smp_admin", "123456");
@Autowired
private WebApplicationContext webAppContext;
......@@ -130,7 +127,7 @@ public class ServiceGroupControllerSingleDomainTest {
public void existingServiceMetadataCanBeRetrievedByEverybodyNoDomain() throws Exception {
String xmlSG = getSampleServiceGroupBody(IDENTIFIER_SCHEME, PARTICIPANT_ID);
String xmlMD = generateServiceMetadata(PARTICIPANT_ID, IDENTIFIER_SCHEME, DOCUMENT_ID, IDENTIFIER_SCHEME, "test");
String xmlMD = generateServiceMetadata(PARTICIPANT_ID, IDENTIFIER_SCHEME, DOCUMENT_ID, DOCUMENT_SCHEME, "test");
// crate service group
mvc.perform(put(URL_PATH)
.with(ADMIN_CREDENTIALS)
......
......@@ -250,7 +250,6 @@ public class ResourceControllerTest {
}
@Test
@Ignore
public void getExistingServiceMetadataWithReverseProxyPort() throws Exception {
//given
String participantId = UUID.randomUUID().toString();
......@@ -320,7 +319,6 @@ public class ResourceControllerTest {
}
@Test
@Ignore
public void getExistingServiceMetadataWithReverseProxyPortInHost() throws Exception {
//given
String participantId = UUID.randomUUID().toString();
......
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