From a505dd0b15110a8b9d3104717484996f940e3cac Mon Sep 17 00:00:00 2001 From: David Diederich <d.diederich@opengroup.org> Date: Mon, 8 Jun 2020 16:15:19 -0400 Subject: [PATCH] Add IBM Integration Tests to the pipeline Squashed commits from trusted-ibm to avoid clutter in the repository --- .fossa.yml | 4 + .gitlab-ci.yml | 6 + NOTICE | 30 +++- provider/indexer-ibm/pom.xml | 24 +-- .../src/main/resources/application.properties | 4 +- .../org/opengroup/osdu/util/ElasticUtils.java | 2 +- testing/indexer-test-ibm/pom.xml | 65 +------- .../step_definitions/index/record/Steps.java | 3 +- .../opengroup/osdu/util/ElasticUtilsIBM.java | 106 ------------- .../opengroup/osdu/util/IBMHTTPClient.java | 8 +- .../opengroup/osdu/util/IdentityUtilIBM.java | 32 ---- .../opengroup/osdu/util/KeyCloakProvider.java | 144 ------------------ testing/pom.xml | 1 + 13 files changed, 69 insertions(+), 360 deletions(-) delete mode 100644 testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/ElasticUtilsIBM.java delete mode 100644 testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/IdentityUtilIBM.java delete mode 100644 testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/KeyCloakProvider.java diff --git a/.fossa.yml b/.fossa.yml index 185a8a978..005b66097 100644 --- a/.fossa.yml +++ b/.fossa.yml @@ -28,3 +28,7 @@ analyze: type: mvn target: provider/indexer-gcp/pom.xml path: . + - name: indexer-ibm + type: mvn + target: provider/indexer-ibm/pom.xml + path: . diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 89cdc6c7a..d54920bd0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,6 +14,9 @@ variables: GCP_DOMAIN: cloud.slb-ds.com GCP_STORAGE_URL: https://osdu-indexer-dot-opendes.appspot.com/api/storage/v2/ + IBM_BUILD_SUBDIR: provider/indexer-ibm + IBM_INT_TEST_SUBDIR: testing/indexer-test-ibm + AZURE_SERVICE: indexer AZURE_BUILD_SUBDIR: provider/indexer-azure AZURE_TEST_SUBDIR: testing/indexer-test-azure @@ -34,6 +37,9 @@ include: - project: "osdu/platform/ci-cd-pipelines" file: "cloud-providers/aws.yml" + - project: "osdu/platform/ci-cd-pipelines" + file: "cloud-providers/ibm.yml" + - project: "osdu/platform/ci-cd-pipelines" file: "publishing/pages.yml" diff --git a/NOTICE b/NOTICE index 78ffe18c3..a32b13e46 100644 --- a/NOTICE +++ b/NOTICE @@ -11,6 +11,7 @@ The following software have components provided under the terms of this license: - Cobertura code coverage (from http://cobertura.sourceforge.net) - Plexus :: Default Container (from ) - Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils) +- StAX (from http://stax.codehaus.org/) - oro (from ) ======================================================================== @@ -18,6 +19,8 @@ Apache-2.0 ======================================================================== The following software have components provided under the terms of this license: +- AMQP 1.0 JMS Spring Boot AutoConfiguration (from https://repo1.maven.org/maven2/org/amqphub/spring/amqp-10-jms-spring-boot-autoconfigure) +- AMQP 1.0 JMS Spring Boot Starter (from https://repo1.maven.org/maven2/org/amqphub/spring/amqp-10-jms-spring-boot-starter) - ASM Analysis (from ) - ASM Commons (from ) - ASM Core (from ) @@ -171,6 +174,7 @@ The following software have components provided under the terms of this license: - Apache Commons Text (from http://commons.apache.org/proper/commons-text/) - Apache Commons Validator (from http://commons.apache.org/proper/commons-validator/) - Apache Commons Validator (from http://commons.apache.org/proper/commons-validator/) +- Apache Geronimo JMS Spec 2.0 (from http://geronimo.apache.org/maven/${siteId}/${version}) - Apache HttpAsyncClient (from http://hc.apache.org/httpcomponents-asyncclient) - Apache HttpClient (from http://hc.apache.org/httpcomponents-client) - Apache HttpCore (from http://hc.apache.org/httpcomponents-core-ga) @@ -203,6 +207,7 @@ The following software have components provided under the terms of this license: - Commons Digester (from http://commons.apache.org/digester/) - Commons Digester (from http://commons.apache.org/digester/) - Commons IO (from http://commons.apache.org/io/) +- Commons IO (from http://commons.apache.org/io/) - Commons Lang (from http://commons.apache.org/lang/) - Converter: Jackson (from ) - Data Mapper for Jackson (from http://jackson.codehaus.org) @@ -270,6 +275,7 @@ The following software have components provided under the terms of this license: - Java Servlet API (from http://servlet-spec.java.net) - Java UUID Generator (from http://wiki.fasterxml.com/JugHome) - Javassist (from http://www.javassist.org/) +- Javassist (from http://www.javassist.org/) - Jetty Server (from ) - Jetty Utilities (from ) - Joda-Time (from http://www.joda.org/joda-time/) @@ -311,9 +317,9 @@ The following software have components provided under the terms of this license: - Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Application Insights Logback Appender (from https://github.com/Microsoft/ApplicationInsights-Java) -- Mockito (from http://www.mockito.org) - Mockito (from http://mockito.org) - Mockito (from http://mockito.org) +- Mockito (from http://www.mockito.org) - Mojo's Maven plugin for Cobertura (from http://mojo.codehaus.org/cobertura-maven-plugin/) - Netty Reactive Streams Implementation (from ) - Netty/Buffer (from http://netty.io/) @@ -337,8 +343,11 @@ The following software have components provided under the terms of this license: - OAuth2 for Spring Security (from ) - Objenesis (from http://objenesis.org) - OkHttp (from ) +- OkHttp (from ) - OkHttp Logging Interceptor (from ) - OkHttp URLConnection (from ) +- OkHttp URLConnection (from ) +- Okio (from ) - Okio (from ) - OpenCensus (from https://github.com/census-instrumentation/opencensus-java) - OpenCensus (from https://github.com/census-instrumentation/opencensus-java) @@ -352,9 +361,11 @@ The following software have components provided under the terms of this license: - Plexus Velocity Component (from ) - PowerMock (from http://www.powermock.org) - Protocol Buffer extensions to the Google HTTP Client Library for Java. (from ) +- QpidJMS Client (from ) - Reactive Streams Netty driver (from https://github.com/reactor/reactor-netty) - Retrofit (from ) - Servlet Specification 2.5 API (from ) +- Simple XML (from http://simple.sourceforge.net) - SnakeYAML (from http://www.snakeyaml.org) - Spatial4J (from http://www.locationtech.org/projects/locationtech.spatial4j) - Spring AOP (from https://github.com/spring-projects/spring-framework) @@ -383,6 +394,8 @@ The following software have components provided under the terms of this license: - Spring Core (from https://github.com/spring-projects/spring-framework) - Spring Data Core (from ) - Spring Expression Language (SpEL) (from https://github.com/spring-projects/spring-framework) +- Spring JMS (from https://github.com/spring-projects/spring-framework) +- Spring Messaging (from https://github.com/spring-projects/spring-framework) - Spring Plugin - Core (from ) - Spring Plugin - Metadata Extension (from ) - Spring Security JWT Library (from http://github.com/spring-projects/spring-security-oauth) @@ -390,6 +403,8 @@ The following software have components provided under the terms of this license: - Spring Transaction (from https://github.com/spring-projects/spring-framework) - Spring Web (from https://github.com/spring-projects/spring-framework) - Spring Web MVC (from https://github.com/spring-projects/spring-framework) +- StAX (from http://stax.codehaus.org/) +- StAX API (from http://stax.codehaus.org/) - T-Digest (from https://github.com/tdunning/t-digest) - Woodstox (from https://github.com/FasterXML/woodstox) - Xerces2-j (from https://xerces.apache.org/xerces2-j/) @@ -419,6 +434,8 @@ The following software have components provided under the terms of this license: - ion-java (from https://github.com/amznlabs/ion-java/) - jackson-databind (from http://github.com/FasterXML/jackson) - jackson-databind (from http://github.com/FasterXML/jackson) +- java-cloudant (from https://cloudant.com) +- java-cloudant (from https://cloudant.com) - javatuples (from http://www.javatuples.org) - javax.inject (from http://code.google.com/p/atinject/) - javax.ws.rs-api (from http://jax-rs-spec.java.net) @@ -438,6 +455,7 @@ The following software have components provided under the terms of this license: - lettuce (from http://github.com/mp911de/lettuce/wiki) - micrometer-core (from https://github.com/micrometer-metrics/micrometer) - micrometer-registry-azure-monitor (from https://github.com/micrometer-metrics/micrometer) +- minio (from https://github.com/minio/minio-java) - org.xmlunit:xmlunit-core (from http://www.xmlunit.org/) - oro (from ) - parent-join (from https://github.com/elastic/elasticsearch) @@ -451,6 +469,7 @@ The following software have components provided under the terms of this license: - powermock-reflect (from ) - proto-google-cloud-datastore-v1 (from https://github.com/googleapis/api-client-staging) - proton-j (from ) +- proton-j (from ) - rank-eval (from https://github.com/elastic/elasticsearch) - rest (from https://github.com/elastic/elasticsearch) - rest-high-level (from https://github.com/elastic/elasticsearch) @@ -462,6 +481,7 @@ The following software have components provided under the terms of this license: - spring-security-oauth2-client (from http://spring.io/spring-security) - spring-security-oauth2-core (from http://spring.io/spring-security) - spring-security-oauth2-jose (from http://spring.io/spring-security) +- spring-security-oauth2-resource-server (from http://spring.io/spring-security) - spring-security-test (from http://spring.io/spring-security) - spring-security-web (from http://spring.io/spring-security) - springfox-core (from https://github.com/springfox/springfox) @@ -495,6 +515,7 @@ The following software have components provided under the terms of this license: - Lucene Common Analyzers (from ) - Plexus :: Default Container (from ) - Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils) +- StAX (from http://stax.codehaus.org/) - jersey-ext-bean-validation (from ) - jersey-spring4 (from ) - oro (from ) @@ -564,6 +585,7 @@ CC-BY-3.0 ======================================================================== The following software have components provided under the terms of this license: +- "Java Concurrency in Practice" book annotations (from http://jcip.net/) - FindBugs-jsr305 (from http://findbugs.sourceforge.net/) ======================================================================== @@ -765,6 +787,7 @@ The following software have components provided under the terms of this license: - Java Native Access (from https://github.com/java-native-access/jna) - Java Native Access Platform (from https://github.com/java-native-access/jna) - Javassist (from http://www.javassist.org/) +- Javassist (from http://www.javassist.org/) - Logback Classic Module (from ) - Logback Core Module (from ) - Microsoft Application Insights Java SDK Core (from https://github.com/Microsoft/ApplicationInsights-Java) @@ -772,6 +795,7 @@ The following software have components provided under the terms of this license: - Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Application Insights Logback Appender (from https://github.com/Microsoft/ApplicationInsights-Java) +- SpotBugs Annotations (from https://spotbugs.github.io/) - java-getopt (from ) ======================================================================== @@ -781,7 +805,9 @@ The following software have components provided under the terms of this license: - Java Native Access (from https://github.com/java-native-access/jna) - Java Native Access Platform (from https://github.com/java-native-access/jna) +- Javassist (from http://www.javassist.org/) - SnakeYAML (from http://www.snakeyaml.org) +- SpotBugs Annotations (from https://spotbugs.github.io/) ======================================================================== LGPL-3.0-only @@ -853,12 +879,14 @@ The following software have components provided under the terms of this license: - Cobertura code coverage (from http://cobertura.sourceforge.net) - Javassist (from http://www.javassist.org/) +- Javassist (from http://www.javassist.org/) ======================================================================== MPL-2.0 ======================================================================== The following software have components provided under the terms of this license: +- Javassist (from http://www.javassist.org/) - Javassist (from http://www.javassist.org/) ======================================================================== diff --git a/provider/indexer-ibm/pom.xml b/provider/indexer-ibm/pom.xml index 09f442947..f2dab825e 100644 --- a/provider/indexer-ibm/pom.xml +++ b/provider/indexer-ibm/pom.xml @@ -32,6 +32,19 @@ <description>Indexer Service IBM</description> <packaging>jar</packaging> + <profiles> + <profile> + <id>local</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <properties> + <build.profile.id>local</build.profile.id> + <profileActive>local</profileActive> + </properties> + </profile> + </profiles> + <dependencies> <!-- OSDU core service dependencies --> @@ -44,7 +57,7 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>os-core-lib-ibm</artifactId> - <version>0.0.13-SNAPSHOT</version> + <version>0.0.14-SNAPSHOT</version> </dependency> <dependency> @@ -69,7 +82,6 @@ <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId> - <version>2.2.0.RELEASE</version> </dependency> <dependency> @@ -108,7 +120,6 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.12</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 --> @@ -132,12 +143,6 @@ <version>3.0.0</version> <scope>test</scope> </dependency> - <!-- <dependency> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - <version>2.7</version> - <scope>test</scope> - </dependency> --> </dependencies> @@ -180,7 +185,6 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> - <version>2.4.2</version> <configuration> <useSystemClassLoader>false</useSystemClassLoader> <threadCount>1</threadCount> diff --git a/provider/indexer-ibm/src/main/resources/application.properties b/provider/indexer-ibm/src/main/resources/application.properties index 242a77dae..9a7a16cc4 100644 --- a/provider/indexer-ibm/src/main/resources/application.properties +++ b/provider/indexer-ibm/src/main/resources/application.properties @@ -43,7 +43,9 @@ ibm.tenant.db.url=${ibm.db.url} ibm.tenant.db.user=${ibm.db.user} ibm.tenant.db.password=${ibm.db.password} -ibm.rabbitmq.uri=REPLACE_ME +amqphub.amqp10jms.remote-url=REPLACE_ME +amqphub.amqp10jms.username=admin +amqphub.amqp10jms.password=admin ibm.keycloak.endpoint_url=keycloak-host.com ibm.keycloak.realm=OSDU diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/ElasticUtils.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/ElasticUtils.java index 230f44d2e..18a138d0b 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/ElasticUtils.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/ElasticUtils.java @@ -260,7 +260,7 @@ public class ElasticUtils { private RestHighLevelClient createClient(String username, String password, String host) { RestHighLevelClient restHighLevelClient; - int port = Config.PORT; + int port = Config.getPort(); try { String rawString = String.format("%s:%s", username, password); diff --git a/testing/indexer-test-ibm/pom.xml b/testing/indexer-test-ibm/pom.xml index 4ff1ccc6d..014a4ec83 100644 --- a/testing/indexer-test-ibm/pom.xml +++ b/testing/indexer-test-ibm/pom.xml @@ -34,6 +34,12 @@ <artifactId>indexer-test-core</artifactId> <version>0.0.2-SNAPSHOT</version> </dependency> + + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>os-core-lib-ibm</artifactId> + <version>0.0.14-SNAPSHOT</version> + </dependency> <!-- Cucumber --> <dependency> @@ -146,63 +152,4 @@ </snapshotRepository> </distributionManagement> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.22.2</version> - <executions> - <execution> - <phase>integration-test</phase> - <goals> - <goal>test</goal> - </goals> - <configuration> - <excludes> - <exclude>none</exclude> - </excludes> - <includes> - <include>**/index</include> - </includes> - </configuration> - </execution> - </executions> - <configuration> - <trimStackTrace>false</trimStackTrace> - <systemPropertyVariables> - - <KEYCLOAK_URL>keycloak-osdu-r2.osduadev-a1c3eaf78a86806e299f5f3f207556f0-0000.us-south.containers.appdomain.cloud</KEYCLOAK_URL> - <KEYCLOAK_REALM>OSDU</KEYCLOAK_REALM> - <KEYCLOAK_CLIENT_ID>osdu-login</KEYCLOAK_CLIENT_ID> - <AUTH_USER_ACCESS>osdu-user</AUTH_USER_ACCESS> - <AUTH_USER_ACCESS_PASSWORD>CHANGE_ME</AUTH_USER_ACCESS_PASSWORD> - - <ENTITLEMENTS_DOMAIN>ibm.com</ENTITLEMENTS_DOMAIN> - <OTHER_RELEVANT_DATA_COUNTRIES>US</OTHER_RELEVANT_DATA_COUNTRIES> - <!-- must be a valid, existing tag --> - <LEGAL_TAG>opendes-public-usa-dataset</LEGAL_TAG> - - <!-- tenant1 MUSTG be opendes to work --> - <DEFAULT_DATA_PARTITION_ID_TENANT1>opendes</DEFAULT_DATA_PARTITION_ID_TENANT1> - <DEFAULT_DATA_PARTITION_ID_TENANT2>tenant2</DEFAULT_DATA_PARTITION_ID_TENANT2> - - <!-- test against OpenShift --> - <STORAGE_HOST>https://storage.osdu-r2-dev-a1c3eaf78a86806e299f5f3f207556f0-0000.us-south.containers.appdomain.cloud/api/storage/v2/</STORAGE_HOST> - - <!-- test locally --> - <!-- - <STORAGE_HOST>http://localhost:8082/api/storage/v2/</STORAGE_HOST> - --> - <ELASTIC_HOST>CHANGE_ME.us-south.containers.appdomain.cloud</ELASTIC_HOST> - <ELASTIC_USER_NAME>CHANGE_ME</ELASTIC_USER_NAME> - <ELASTIC_PASSWORD>CHANGE_ME</ELASTIC_PASSWORD> - <ELASTIC_PORT>443</ELASTIC_PORT> - - - </systemPropertyVariables> - </configuration> - </plugin> - </plugins> - </build> </project> diff --git a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java b/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java index 126934d41..518b2b6f9 100644 --- a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java +++ b/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java @@ -1,7 +1,6 @@ package org.opengroup.osdu.step_definitions.index.record; import org.opengroup.osdu.common.RecordSteps; -import org.opengroup.osdu.util.ElasticUtilsIBM; import org.opengroup.osdu.util.IBMHTTPClient; import cucumber.api.DataTable; @@ -16,7 +15,7 @@ import lombok.extern.java.Log; public class Steps extends RecordSteps { public Steps() { - super(new IBMHTTPClient(), new ElasticUtilsIBM()); + super(new IBMHTTPClient()); } @Before diff --git a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/ElasticUtilsIBM.java b/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/ElasticUtilsIBM.java deleted file mode 100644 index 5174b7c93..000000000 --- a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/ElasticUtilsIBM.java +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2020 IBM Corp. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.util; - -import java.security.SecureRandom; -import java.security.cert.X509Certificate; -import java.util.Base64; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - -import org.apache.http.Header; -import org.apache.http.HttpHost; -import org.apache.http.conn.ssl.SSLSocketFactory; -import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; -import org.apache.http.message.BasicHeader; -import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestClientBuilder; -import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback; -import org.elasticsearch.client.RestHighLevelClient; - -import lombok.extern.java.Log; - -/** - * All util methods to use elastic apis for tests - * It should be used only in the Setup or TearDown phase of the test - */ -@Log -public class ElasticUtilsIBM extends ElasticUtils { - - private static final int REST_CLIENT_CONNECT_TIMEOUT = 5000; - private static final int REST_CLIENT_SOCKET_TIMEOUT = 60000; - private static final int REST_CLIENT_RETRY_TIMEOUT = 60000; - - public ElasticUtilsIBM() { - super(); - } - - protected RestHighLevelClient createClient(String username, String password, String host) { - - RestHighLevelClient restHighLevelClient; - int port = Config.getPort(); - try { - String rawString = String.format("%s:%s", username, password); - RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, "https")); - builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(REST_CLIENT_CONNECT_TIMEOUT) - .setSocketTimeout(REST_CLIENT_SOCKET_TIMEOUT)); - builder.setMaxRetryTimeoutMillis(REST_CLIENT_RETRY_TIMEOUT); - - Header[] defaultHeaders = new Header[]{ - new BasicHeader("client.transport.nodes_sampler_interval", "30s"), - new BasicHeader("client.transport.ping_timeout", "30s"), - new BasicHeader("client.transport.sniff", "false"), - new BasicHeader("request.headers.X-Found-Cluster", Config.getElasticHost()), - new BasicHeader("cluster.name", Config.getElasticHost()), - new BasicHeader("xpack.security.transport.ssl.enabled", Boolean.toString(true)), - new BasicHeader("Authorization", String.format("Basic %s", Base64.getEncoder().encodeToString(rawString.getBytes()))), - }; - - - SSLContext sslContext = SSLContext.getInstance("SSL"); - // set up a TrustManager that trusts everything - sslContext.init(null, new TrustManager[]{new X509TrustManager() { - public X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted(X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted(X509Certificate[] certs, String authType) { - } - }}, new SecureRandom()); - - builder.setHttpClientConfigCallback(new HttpClientConfigCallback() { - - public HttpAsyncClientBuilder customizeHttpClient( - HttpAsyncClientBuilder httpClientBuilder) { - return httpClientBuilder - .setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) - .setSSLContext(sslContext); - } - }) - .setDefaultHeaders(defaultHeaders); - - restHighLevelClient = new RestHighLevelClient(builder); - - } catch (Exception e) { - throw new AssertionError("Setup elastic error"); - } - return restHighLevelClient; - } -} \ No newline at end of file diff --git a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/IBMHTTPClient.java b/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/IBMHTTPClient.java index c313c3833..843a7e8a1 100644 --- a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/IBMHTTPClient.java +++ b/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/IBMHTTPClient.java @@ -14,12 +14,12 @@ package org.opengroup.osdu.util; -import lombok.ToString; -import lombok.extern.java.Log; +import org.opengroup.osdu.core.ibm.util.IdentityClient; import com.google.common.base.Strings; -@Log +import lombok.ToString; + @ToString public class IBMHTTPClient extends HTTPClient { private static String token = null; @@ -28,7 +28,7 @@ public class IBMHTTPClient extends HTTPClient { public synchronized String getAccessToken() { if(Strings.isNullOrEmpty(token)) { try { - token = "Bearer " + IdentityUtilIBM.getAccessToken(); + token = "Bearer " + IdentityClient.getTokenForUserWithAccess(); } catch (Exception e) { e.printStackTrace(); } diff --git a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/IdentityUtilIBM.java b/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/IdentityUtilIBM.java deleted file mode 100644 index 1f2fdb06f..000000000 --- a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/IdentityUtilIBM.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2020 IBM Corp. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.util; - -import java.io.IOException; - -public class IdentityUtilIBM { - - public static String getAccessToken(){ - try { - String user = System.getProperty("AUTH_USER_ACCESS"); - String pass = System.getProperty("AUTH_USER_ACCESS_PASSWORD"); - return KeyCloakProvider.getToken(user, pass); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - -} diff --git a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/KeyCloakProvider.java b/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/KeyCloakProvider.java deleted file mode 100644 index d890d9a99..000000000 --- a/testing/indexer-test-ibm/src/test/java/org/opengroup/osdu/util/KeyCloakProvider.java +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2020 IBM Corp. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.util; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLEncoder; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.X509Certificate; -import java.util.HashMap; -import java.util.Map; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -public class KeyCloakProvider { - - private static String url; - private static String realm; - private static String client_id; - private static String grant_type = "password"; - - static { - disableSslVerification(); - url = System.getProperty("KEYCLOAK_URL"); - realm = System.getProperty("KEYCLOAK_REALM"); - client_id = System.getProperty("KEYCLOAK_CLIENT_ID"); - } - - private static void disableSslVerification() { - try - { - // Create a trust manager that does not validate certificate chains - TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - public void checkClientTrusted(X509Certificate[] certs, String authType) { - } - public void checkServerTrusted(X509Certificate[] certs, String authType) { - } - } - }; - - // Install the all-trusting trust manager - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, new java.security.SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - - // Create all-trusting host name verifier - HostnameVerifier allHostsValid = new HostnameVerifier() { - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - - // Install the all-trusting host verifier - HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } - } - - - public static String getToken(String user, String pwd) throws IOException { - String token_endpoint = String.format("https://%s/auth/realms/%s/protocol/openid-connect/token", url, realm); - URL url = new URL(token_endpoint); - HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - - Map<String, String> parameters = new HashMap<>(); - parameters.put("grant_type", grant_type); - parameters.put("client_id", client_id); - parameters.put("username", user); - parameters.put("password", pwd); - - con.setDoOutput(true); - DataOutputStream out = new DataOutputStream(con.getOutputStream()); - out.writeBytes(getParamsString(parameters)); - out.flush(); - out.close(); - - BufferedReader in = new BufferedReader( - new InputStreamReader(con.getInputStream())); - String inputLine; - StringBuffer content = new StringBuffer(); - while ((inputLine = in.readLine()) != null) { - content.append(inputLine); - } - in.close(); - - con.disconnect(); - - Gson gson = new Gson(); - JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class); - String token = jobj.get("access_token").getAsString(); - return token; - } - - private static String getParamsString(Map<String, String> params) - throws UnsupportedEncodingException { - StringBuilder result = new StringBuilder(); - - for (Map.Entry<String, String> entry : params.entrySet()) { - result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); - result.append("="); - result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); - result.append("&"); - } - - String resultString = result.toString(); - return resultString.length() > 0 - ? resultString.substring(0, resultString.length() - 1) - : resultString; - } - -} diff --git a/testing/pom.xml b/testing/pom.xml index 1bac11ece..14d9179b9 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -36,6 +36,7 @@ <module>indexer-test-aws</module> <module>indexer-test-azure</module> <module>indexer-test-gcp</module> + <module>indexer-test-ibm</module> </modules> <repositories> -- GitLab