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

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

Fix sql migration scrip for mysql

UI disable domain item if is not configured properly
parent b117059c
No related branches found
No related tags found
No related merge requests found
......@@ -15,12 +15,6 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration(classes = {SmlConnector.class, SmlIntegrationConfiguration.class,
SecurityUtilsServices.class, UIKeystoreService.class,
ConversionTestConfig.class, PropertiesSingleDomainTestConfig.class})
@Configuration
@TestPropertySource(properties = {
"bdmsl.integration.enabled=true"})
public class SmlConnectorTestBase {
protected static final ParticipantIdentifierType PARTICIPANT_ID = new ParticipantIdentifierType("sample:value", "sample:scheme");
protected static final DBDomain DEFAULT_DOMAIN;
......@@ -37,10 +31,4 @@ public class SmlConnectorTestBase {
protected static final String ERROR_PI_ALREADY_EXISTS = "[ERR-106] The participant identifier 'sample:value' does already exist for the scheme sample:scheme";
protected static final String ERROR_PI_NO_EXISTS = "[ERR-100] The participant identifier 'sample:value' doesn't exist for the scheme sample:scheme";
@Autowired
protected SmlConnector smlConnector;
@Autowired
SmlIntegrationConfiguration mockSml;
}
......@@ -17,13 +17,21 @@ import eu.europa.ec.bdmsl.ws.soap.BadRequestFault;
import eu.europa.ec.bdmsl.ws.soap.InternalErrorFault;
import eu.europa.ec.bdmsl.ws.soap.NotFoundFault;
import eu.europa.ec.bdmsl.ws.soap.UnauthorizedFault;
import eu.europa.ec.edelivery.smp.config.ConversionTestConfig;
import eu.europa.ec.edelivery.smp.config.PropertiesSingleDomainTestConfig;
import eu.europa.ec.edelivery.smp.config.SmlIntegrationConfiguration;
import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
import eu.europa.ec.edelivery.smp.services.SecurityUtilsServices;
import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
......@@ -35,11 +43,21 @@ import static org.mockito.Mockito.verify;
* since 4.1.
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {SmlConnector.class, SmlIntegrationConfiguration.class,
SecurityUtilsServices.class, UIKeystoreService.class,
ConversionTestConfig.class, PropertiesSingleDomainTestConfig.class})
@TestPropertySource(properties = {
"bdmsl.integration.enabled=true"})
public class SmlConnectorTestDomain extends SmlConnectorTestBase {
@Rule
public ExpectedException expectedExeption = ExpectedException.none();
@Autowired
protected SmlConnector smlConnector;
@Autowired
SmlIntegrationConfiguration mockSml;
@Before
public void setup() {
mockSml.reset();
......
......@@ -17,13 +17,21 @@ import eu.europa.ec.bdmsl.ws.soap.BadRequestFault;
import eu.europa.ec.bdmsl.ws.soap.InternalErrorFault;
import eu.europa.ec.bdmsl.ws.soap.NotFoundFault;
import eu.europa.ec.bdmsl.ws.soap.UnauthorizedFault;
import eu.europa.ec.edelivery.smp.config.ConversionTestConfig;
import eu.europa.ec.edelivery.smp.config.PropertiesSingleDomainTestConfig;
import eu.europa.ec.edelivery.smp.config.SmlIntegrationConfiguration;
import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
import eu.europa.ec.edelivery.smp.services.SecurityUtilsServices;
import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
......@@ -35,11 +43,21 @@ import static org.mockito.Mockito.verify;
* since 4.1.
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {SmlConnector.class, SmlIntegrationConfiguration.class,
SecurityUtilsServices.class, UIKeystoreService.class,
ConversionTestConfig.class, PropertiesSingleDomainTestConfig.class})
@TestPropertySource(properties = {
"bdmsl.integration.enabled=true"})
public class SmlConnectorTestParticipant extends SmlConnectorTestBase {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Autowired
protected SmlConnector smlConnector;
@Autowired
SmlIntegrationConfiguration mockSml;
@Before
public void setup() {
mockSml.reset();
......
......@@ -68,24 +68,8 @@ public class KeystoreResource {
LOG.info(keyStore.aliases().nextElement());
uiKeystoreService.importKeys(keyStore, password);
} catch (KeyStoreException e) {
String msg = "KeyStoreException occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
} catch (CertificateException e) {
String msg = "CertificateException occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
} catch (NoSuchAlgorithmException e) {
String msg = "NoSuchAlgorithmException occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
} catch (IOException e) {
String msg = "IOException occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
} catch (UnrecoverableKeyException e) {
String msg = "UnrecoverableKeyException occurred while importing new keys the keystore: " + e.getMessage();
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException | UnrecoverableKeyException e) {
String msg = e.getClass().getName() +" occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
}
......@@ -103,20 +87,8 @@ public class KeystoreResource {
try {
uiKeystoreService.deleteKey(alias);
} catch (KeyStoreException e) {
String msg = "KeyStoreException occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
} catch (CertificateException e) {
String msg = "CertificateException occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
} catch (NoSuchAlgorithmException e) {
String msg = "NoSuchAlgorithmException occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
} catch (IOException e) {
String msg = "IOException occurred while reading the keystore: " + e.getMessage();
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e) {
String msg = e.getClass().getName() +" occurred while reading the keystore: " + e.getMessage();
LOG.error(msg, e);
keystoreImportResult.setErrorMessage(msg);
}
......
......@@ -13,12 +13,15 @@
package eu.europa.ec.edelivery.smp.config;
import org.apache.commons.io.FileUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
......@@ -36,9 +39,15 @@ public class PropertiesTestConfig {
private final static String SIGNING_KEYSTORE_PATH = Thread.currentThread().getContextClassLoader().getResource("service_integration_signatures_single_domain.jks").getFile();
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
Path resourceDirectory = Paths.get("src", "test", "resources", "keystores");
String path = resourceDirectory.toFile().getAbsolutePath();
Path targetDirectory = Paths.get("target", "keystores");
FileUtils.copyDirectory(resourceDirectory.toFile(), targetDirectory.toFile());
String path = targetDirectory.toFile().getAbsolutePath();
PropertySourcesPlaceholderConfigurer propertiesConfig = new PropertySourcesPlaceholderConfigurer();
......
......@@ -41,6 +41,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
......@@ -128,7 +129,7 @@ public class KeystoreResourceTest {
KeystoreImportResult res = mapper.readValue(result.getResponse().getContentAsString(), KeystoreImportResult.class);
assertNotNull(res);
assertEquals("IOException occurred while reading the keystore: Invalid keystore format", res.getErrorMessage());
assertEquals("java.io.IOException occurred while reading the keystore: Invalid keystore format", res.getErrorMessage());
}
@Test
......@@ -145,7 +146,7 @@ public class KeystoreResourceTest {
KeystoreImportResult res = mapper.readValue(result.getResponse().getContentAsString(), KeystoreImportResult.class);
assertNotNull(res);
assertEquals("IOException occurred while reading the keystore: Keystore was tampered with, or password was incorrect", res.getErrorMessage());
assertEquals("java.io.IOException occurred while reading the keystore: Keystore was tampered with, or password was incorrect", res.getErrorMessage());
}
@Test
......@@ -167,6 +168,23 @@ public class KeystoreResourceTest {
assertEquals(countStart+1, uiKeystoreService.getKeystoreEntriesList().size());
}
@Test
public void deleteKeystoreEntryOK() throws Exception {
int countStart = uiKeystoreService.getKeystoreEntriesList().size();
// given when
MvcResult result = mvc.perform(delete(PATH+"/3/delete/second_domain_alias")
.with(SYSTEM_CREDENTIALS)
.content(Files.readAllBytes(resourceDirectory)) )
.andExpect(status().isOk()).andReturn();
//them
ObjectMapper mapper = new ObjectMapper();
KeystoreImportResult res = mapper.readValue(result.getResponse().getContentAsString(), KeystoreImportResult.class);
assertNotNull(res);
assertNull(res.getErrorMessage());
assertEquals(countStart-1, uiKeystoreService.getKeystoreEntriesList().size());
}
}
\ No newline at end of file
No preview for this file type
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