Skip to content
Snippets Groups Projects
Commit c978c6df authored by OZG-Cloud Team's avatar OZG-Cloud Team
Browse files

OZG-3136 cleanup integration testing

parent 4957936a
Branches
Tags
No related merge requests found
Showing
with 86 additions and 50 deletions
......@@ -32,3 +32,5 @@ build/
### VS Code ###
.vscode/
application-sec.yml
......@@ -40,6 +40,11 @@
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-test</artifactId>
<scope>test</scope>
</dependency>
<!--own project -->
<dependency>
<groupId>de.itvsh.kop.eingangsadapter</groupId>
......
# Keystore passwort
Das Keystore und Passwort müssen extra hinzugefügt werden. Keystore irgendwo im Dateisystem ablegen.
Dazu eine Datei 'application-sec.yml' anlegen:
ozgcloud:
xta:
keystore:
store: file:<pfad zum keystore>
password: <geheim>
Den Dienst dann mit dem Spring-Profile 'sec' starten.
# Ceritifcade chain
lokal das Root CA in keystore laden:
sudo keytool -trustcacerts -keystore /lib/jvm/java-1.17.0-openjdk-amd64/lib/security/cacerts -storepass changeit -importcert -alias dataportRoot -file DataportRootCA02.crt
# Port forwarding
Um eine Verbindung zum Nachrichtenbroker aufbauen zu können, muss diese über den Hetzner-Server geroutet werden:
ssh -L 3000:[Hetzner-Server-IP]:443 ozg-sh.de
\ No newline at end of file
......@@ -22,8 +22,6 @@ import eu.osci.ws._2008._05.transport.ObjectFactory;
@Service
class XtaRemoteService {
private static final String URI_TEMPLATE = "https://%s/MB_XTA-WS/XTA210msgBoxPort.svc";
@Autowired
@Valid
private XtaProperties properties;
......@@ -55,7 +53,7 @@ class XtaRemoteService {
private URI getTargetUri() {
try {
return new URI(URI_TEMPLATE.formatted(properties.getServer().getName()));
return new URI(XtaRemoteServiceConfiguration.URI_TEMPLATE.formatted(properties.getServer().getName()));
} catch (URISyntaxException e) {
throw new TechnicalException("Error building target url: " + e);
}
......
......@@ -10,9 +10,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
......@@ -20,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webservices.client.WebServiceTemplateCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.ws.client.support.destination.DestinationProvider;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
......@@ -33,7 +32,7 @@ import de.itvsh.kop.eingangsadapter.common.errorhandling.TechnicalException;
@Configuration
public class XtaRemoteServiceConfiguration {
private static final String KEYSTORE_TYPE = "PKCS12";
static final String URI_TEMPLATE = "https://%s/MB_XTA-WS/XTA210msgBoxPort.svc";
@Autowired
private XtaProperties properties;
......@@ -47,9 +46,9 @@ public class XtaRemoteServiceConfiguration {
}
@Bean
@Profile("local")
WebServiceTemplateCustomizer webServiceTemplateCustomizer() {
return template -> template
.setMessageSender(messageSender());
return template -> template.setMessageSender(messageSender());
}
@Bean
......@@ -79,7 +78,7 @@ public class XtaRemoteServiceConfiguration {
DestinationProvider destinationProvider() {
return () -> {
try {
return new URI("https://localhost:3000/MB_XTA-WS/XTA210msgBoxPort.svc");
return new URI(URI_TEMPLATE.formatted(properties.getServer().getAddress()));
} catch (URISyntaxException e) {
throw new TechnicalException("Error building URI", e);
}
......@@ -94,26 +93,18 @@ public class XtaRemoteServiceConfiguration {
}
@Bean
@Profile("local")
WebServiceMessageSender messageSender() {
return initMessageSender();
}
HttpsUrlConnectionMessageSender initMessageSender() {
try {
var keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(xtaKeyStore(), properties.getKeyStore().getPassword());
var messageSender = new HttpsUrlConnectionMessageSender();
messageSender.setKeyManagers(keyManagerFactory.getKeyManagers());
messageSender.setTrustManagers(new TrustManager[] { new UnTrustworthyTrustManager() });
messageSender.setHostnameVerifier(new HostnameVerifier() {
var messageSender1 = new HttpsUrlConnectionMessageSender();
messageSender1.setKeyManagers(keyManagerFactory.getKeyManagers());
messageSender1.setTrustManagers(new TrustManager[] { new UnTrustworthyTrustManager() });
messageSender1.setHostnameVerifier((hostname, session) -> true); // NOSONAR only for test/local
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return messageSender;
return messageSender1;
} catch (Exception e) {
throw new TechnicalException("Error initializating message sender.", e);
}
......@@ -122,11 +113,8 @@ public class XtaRemoteServiceConfiguration {
@Bean
KeyStore xtaKeyStore() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
var keyStoreResource = properties.getKeyStore().getFile();
// var keysres = XtaRemoteServiceConfiguration.class.getResourceAsStream("/KOP_SH_KIEL_DEV.p12");
// assert (keysres != null);
var keyStore = KeyStore.getInstance(KEYSTORE_TYPE);
var keyStore = KeyStore.getInstance(properties.getKeyStore().getType());
try (InputStream keyStoreStream = keyStoreResource.getInputStream()) {
// try (InputStream keyStoreStream = keysres) {
keyStore.load(keyStoreStream, properties.getKeyStore().getPassword());
}
......@@ -135,16 +123,16 @@ public class XtaRemoteServiceConfiguration {
static class UnTrustworthyTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { // NOSONAR only for test/local
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { // NOSONAR only for test/local
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
return new X509Certificate[0];
}
}
}
ozgcloud:
xta:
server:
address: localhost:3000
name: LI33-0005
\ No newline at end of file
spring:
profiles:
active:
- sec
logging:
level:
ROOT: WARN
......@@ -13,11 +8,7 @@ logging:
ozgcloud:
xta:
max-list-elements: 10
server:
name: LI33-0005
address: localhost:3000
keystore:
file: classpath:KOP_SH_KIEL_DEV.p12
type: PKCS12
actions:
status-list: "http://www.osci.eu/ws/2008/05/transport/urn/messageTypes/MsgBoxStatusListRequest"
\ No newline at end of file
package de.ozgcloud.eingang.xta;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import de.itvsh.kop.eingangsadapter.Application;
@ActiveProfiles({ "local", "itcase" })
@SpringBootTest(classes = Application.class)
class XtaApplicationTest {
@Test
void startup() {
// should start without exception;
assertTrue(true);
}
}
......@@ -2,10 +2,9 @@ package de.ozgcloud.eingang.xta;
import static org.assertj.core.api.Assertions.*;
import java.net.URISyntaxException;
import jakarta.validation.Valid;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,14 +12,15 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import de.itvsh.kop.eingangsadapter.Application;
import eu.osci.ws._2008._05.transport.MsgStatusListType;
import lombok.SneakyThrows;
@ActiveProfiles({ "itcase", "local", "sec" })
@Disabled("real live test - do only activate for manual testing")
@ActiveProfiles({ "itcase", "local" })
@SpringBootTest(classes = Application.class)
class XtaRemoteServiceITCase {
@Autowired
private XtaRemoteService xtaRemoteService;
private XtaRemoteService remoteService;
@Autowired
@Valid
private XtaProperties xtaProperties;
......@@ -33,11 +33,16 @@ class XtaRemoteServiceITCase {
}
}
@Nested
class TestGetStatusList {
@SneakyThrows
@Test
void test() throws URISyntaxException {
MsgStatusListType rsp = xtaRemoteService.getStatusList();
void shouldSendRequestWithIdentifier() {
assertThat(rsp.getMessageMetaData()).isNotEmpty();
remoteService.getStatusList();
}
}
}
File deleted
File deleted
ozgcloud:
xta:
keystore:
file: classpath:xtaTestStore.p12
password: <geheim>
\ No newline at end of file
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment