From 0378a40364ba24c81a26c961b4cfeeabcc072f87 Mon Sep 17 00:00:00 2001 From: d-velev Date: Thu, 21 Apr 2022 12:16:41 +0300 Subject: [PATCH 1/5] Expose properties needed for a proxy connection in DestMailConfigProvider --- .../CloudPlatformDestinationFacade.java | 8 +++-- .../sap/xsk/api/destination/Destination.java | 4 +++ .../sap/xsk/mail/DestMailConfigProvider.java | 32 ++++++++++++------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/modules/api/api-xsjs/src/main/java/com/sap/xsk/api/destination/CloudPlatformDestinationFacade.java b/modules/api/api-xsjs/src/main/java/com/sap/xsk/api/destination/CloudPlatformDestinationFacade.java index 4043ab59f..3198351fb 100644 --- a/modules/api/api-xsjs/src/main/java/com/sap/xsk/api/destination/CloudPlatformDestinationFacade.java +++ b/modules/api/api-xsjs/src/main/java/com/sap/xsk/api/destination/CloudPlatformDestinationFacade.java @@ -46,9 +46,13 @@ public static Destination getDestination(String destinationName) { } }); - URI uri = URI.create((String) fetchedDestination.get("URL").get()); + if (fetchedDestination.isHttp()) { + URI uri = URI.create((String) fetchedDestination.get("URL").get()); - return new Destination(uri.getHost(), uri.getPort(), uri.getPath(), destinationProperties); + return new Destination(uri.getHost(), uri.getPort(), uri.getPath(), destinationProperties); + } else { + return new Destination(destinationProperties); + } } public static String executeRequest(String requestObject, String destinationName, String options) diff --git a/modules/api/api-xsjs/src/main/java/com/sap/xsk/api/destination/Destination.java b/modules/api/api-xsjs/src/main/java/com/sap/xsk/api/destination/Destination.java index 75fd7f203..c0ead6ad1 100644 --- a/modules/api/api-xsjs/src/main/java/com/sap/xsk/api/destination/Destination.java +++ b/modules/api/api-xsjs/src/main/java/com/sap/xsk/api/destination/Destination.java @@ -21,6 +21,10 @@ public class Destination { private String pathPrefix; private Properties properties = new Properties(); + public Destination(Properties properties) { + this.properties = properties; + } + public Destination(String host, int port, String pathPrefix, Properties properties) { this.host = host; this.port = port; diff --git a/modules/engines/engine-mail-destination/src/main/java/com/sap/xsk/mail/DestMailConfigProvider.java b/modules/engines/engine-mail-destination/src/main/java/com/sap/xsk/mail/DestMailConfigProvider.java index 9be7d7cf4..29a3aafeb 100644 --- a/modules/engines/engine-mail-destination/src/main/java/com/sap/xsk/mail/DestMailConfigProvider.java +++ b/modules/engines/engine-mail-destination/src/main/java/com/sap/xsk/mail/DestMailConfigProvider.java @@ -17,21 +17,30 @@ import org.eclipse.dirigible.commons.config.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Arrays; import java.util.List; import java.util.Properties; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class DestMailConfigProvider implements IMailConfigurationProvider { + private static final String MAIL_USER = "mail.user"; private static final String MAIL_PASSWORD = "mail.password"; private static final String MAIL_TRANSPORT_PROTOCOL = "mail.transport.protocol"; - private static final String MAIL_SMTPS_HOST = "mail.smtps.host"; - private static final String MAIL_SMTPS_PORT = "mail.smtps.port"; - private static final String MAIL_SMTPS_AUTH = "mail.smtps.auth"; - private static final String MAIL_SMTP_HOST = "mail.smtp.host"; - private static final String MAIL_SMTP_PORT = "mail.smtp.port"; - private static final String MAIL_SMTP_AUTH = "mail.smtp.auth"; - private static List MAIL_PROPERTIES = List.of(MAIL_USER, MAIL_PASSWORD, MAIL_TRANSPORT_PROTOCOL, MAIL_SMTPS_HOST, MAIL_SMTPS_PORT, - MAIL_SMTPS_AUTH, MAIL_SMTP_HOST, MAIL_SMTP_PORT, MAIL_SMTP_AUTH); + private static final String PROXY_TYPE = "ProxyType"; + private static final String HOST = "host"; + private static final String PORT = "port"; + private static final String AUTH = "auth"; + private static final String SOCKS_HOST = "socks.host"; + private static final String SOCKS_PORT = "socks.port"; + private static final String PROXY_USERNAME = "proxy.user"; + private static final String PROXY_PASSWORD = "proxy.password"; + private static final List PROTOCOL_PROPERTIES = List.of(HOST, PORT, AUTH, SOCKS_HOST, SOCKS_HOST, SOCKS_PORT, PROXY_USERNAME, + PROXY_PASSWORD); + private static final List MAIL_PROPERTIES = Stream.concat( + PROTOCOL_PROPERTIES.stream().map(p -> Arrays.asList("mail.smtp." + p, "mail.smtps." + p)) + .flatMap(List::stream), Stream.of(MAIL_USER, MAIL_PASSWORD, MAIL_TRANSPORT_PROTOCOL, PROXY_TYPE)).collect(Collectors.toList()); private static final String PROVIDER_NAME = "destination"; private static final String DESTINATION_NAME = "MAIL_SERVER_DESTINATION_NAME"; @@ -50,15 +59,16 @@ public Properties getProperties() { String destinationName = Configuration.get(DESTINATION_NAME); Properties destinationProperties = CloudPlatformDestinationFacade.getDestination(destinationName).getProperties(); for (String key : MAIL_PROPERTIES) { - if(destinationProperties.containsKey(key)) { + if (destinationProperties.containsKey(key)) { properties.put(key, destinationProperties.get(key)); } } } catch (DestinationAccessException e) { - logger.error("Cannot find destination for mail configuration. Please check if " + DESTINATION_NAME + " is set and the destination exists."); + logger.error( + "Cannot find destination for mail configuration. Please check if " + DESTINATION_NAME + " is set and the destination exists."); } - if(properties.isEmpty()) { + if (properties.isEmpty()) { logger.error("Destination object does not contain necessary mail settings!"); } return properties; From 7212f9d9d89af4ca6b6e4c261dda3ce0cd75fb01 Mon Sep 17 00:00:00 2001 From: d-velev Date: Thu, 21 Apr 2022 12:43:57 +0300 Subject: [PATCH 2/5] Fix DestinationFacade test --- .../com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java b/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java index f42bcbb38..8920adf44 100644 --- a/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java +++ b/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java @@ -92,6 +92,7 @@ public void mockAccessors(Boolean isKymaFacadeSet) { com.sap.cloud.sdk.cloudplatform.connectivity.Destination mockedDestination = Mockito.mock(com.sap.cloud.sdk.cloudplatform.connectivity.Destination.class); when(mockedDestination.get("URL")).thenReturn(Option.of(DESTINATION_URI)); + when(mockedDestination.isHttp()).thenReturn(true); HttpDestination mockedHttpDestination = Mockito.mock(HttpDestination.class); when(mockedHttpDestination.getAuthenticationType()).thenReturn(AuthenticationType.NO_AUTHENTICATION); From 57585f30eae230df7f184f557e0dc8571e60dd41 Mon Sep 17 00:00:00 2001 From: d-velev Date: Tue, 26 Apr 2022 11:58:39 +0300 Subject: [PATCH 3/5] Test changes --- .../CloudPlatformDestinationFacadeTest.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java b/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java index 8920adf44..a05f87059 100644 --- a/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java +++ b/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java @@ -24,6 +24,9 @@ import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.HttpClient; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import org.junit.After; @@ -57,8 +60,8 @@ public class CloudPlatformDestinationFacadeTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][] { - { true }, { false } + return Arrays.asList(new Object[][]{ + {true}, {false} }); } @@ -74,10 +77,6 @@ public void setup() throws IOException { @After public void close() { - - if (!isKymaFacadeSet) { - cloudPlatformAccessor.verify(() -> CloudPlatformAccessor.setCloudPlatformFacade(any())); - } destinationAccessor.close(); httpClientAccessor.close(); cloudPlatformAccessor.close(); @@ -90,9 +89,10 @@ public void mockAccessors(Boolean isKymaFacadeSet) { httpClientAccessor = Mockito.mockStatic(HttpClientAccessor.class); cloudPlatformAccessor = Mockito.mockStatic(CloudPlatformAccessor.class); - com.sap.cloud.sdk.cloudplatform.connectivity.Destination mockedDestination = Mockito.mock(com.sap.cloud.sdk.cloudplatform.connectivity.Destination.class); + com.sap.cloud.sdk.cloudplatform.connectivity.Destination mockedDestination = Mockito.mock( + com.sap.cloud.sdk.cloudplatform.connectivity.Destination.class); when(mockedDestination.get("URL")).thenReturn(Option.of(DESTINATION_URI)); - when(mockedDestination.isHttp()).thenReturn(true); + when(mockedDestination.isHttp()).thenReturn(true, false); HttpDestination mockedHttpDestination = Mockito.mock(HttpDestination.class); when(mockedHttpDestination.getAuthenticationType()).thenReturn(AuthenticationType.NO_AUTHENTICATION); @@ -101,7 +101,7 @@ public void mockAccessors(Boolean isKymaFacadeSet) { when(mockedDestination.asHttp()).thenReturn(mockedHttpDestination); destinationAccessor.when(() -> DestinationAccessor.getDestination(destinationName)) - .thenReturn(mockedDestination); + .thenReturn(mockedDestination, mockedDestination); httpClientAccessor.when(() -> HttpClientAccessor.getHttpClient(any())) .thenReturn(httpClient); @@ -133,6 +133,12 @@ public void getDestinationTest() throws Exception { assertEquals("test-destination.com", dest.getHost()); assertEquals(8080, dest.getPort()); assertEquals("/destination", dest.getPathPrefix()); + + // when .isHttp() is false + Destination dest2 = CloudPlatformDestinationFacade.getDestination(destinationName); + assertNull(dest2.getHost()); + assertEquals(0, dest2.getPort()); + assertNull(dest2.getPathPrefix()); } @Test From 9eeb32f19be186c98f2afbf26ea20e09219bd2ec Mon Sep 17 00:00:00 2001 From: d-velev Date: Tue, 26 Apr 2022 12:41:32 +0300 Subject: [PATCH 4/5] Remove redundant import --- .../com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java b/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java index a05f87059..35503fab0 100644 --- a/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java +++ b/modules/api/api-xsjs/src/test/java/com/sap/xsk/api/test/CloudPlatformDestinationFacadeTest.java @@ -25,7 +25,6 @@ import org.apache.http.StatusLine; import org.apache.http.client.HttpClient; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; From 9a40e0a3f4d82b0ef640c40e2aaad89d38b8d0ec Mon Sep 17 00:00:00 2001 From: d-velev Date: Wed, 27 Apr 2022 10:15:39 +0300 Subject: [PATCH 5/5] Bump dirigible version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f858720a8..cda4921bb 100644 --- a/pom.xml +++ b/pom.xml @@ -253,7 +253,7 @@ 11 UTF-8 - 6.2.18 + 6.2.19 sap-1