diff --git a/provider/indexer-gcp/README.md b/provider/indexer-gcp/README.md index c7593de2753b57138443b03c4fd1042dc399e4cf..63ad412af8efb28d882f73e76d0783e2a3d1d34c 100644 --- a/provider/indexer-gcp/README.md +++ b/provider/indexer-gcp/README.md @@ -141,41 +141,13 @@ $ (cd testing/indexer-test-core/ && mvn clean install) ``` ### Running E2E Tests -This section describes how to run cloud OSDU E2E tests (testing/integration-tests/indexer-test-gcp). - -You will need to have the following environment variables defined. - -| name | value | description | sensitive? | source | -| --- | --- | --- | --- | --- | -| `ELASTIC_PASSWORD` | `********` | Password for Elasticsearch | yes | output of infrastructure deployment | -| `ELASTIC_USER_NAME` | `********` | User name for Elasticsearch | yes | output of infrastructure deployment | -| `ELASTIC_HOST` | ex `elastic.domain.com` | Host Elasticsearch | yes | output of infrastructure deployment | -| `ELASTIC_PORT` | ex `9243` | Port Elasticsearch | yes | output of infrastructure deployment | -| `GCLOUD_PROJECT` | ex `opendes` | Google Cloud Project Id| no | output of infrastructure deployment | -| `INDEXER_HOST` | ex `https://os-indexer-dot-opendes.appspot.com/api/indexer/v2/` | Indexer API endpoint | no | output of infrastructure deployment | -| `ENTITLEMENTS_DOMAIN` | ex `opendes-gcp.projects.com` | OSDU R2 to run tests under | no | - | -| `INTEGRATION_TEST_AUDIENCE` | `********` | client application ID | yes | https://console.cloud.google.com/apis/credentials | -| `OTHER_RELEVANT_DATA_COUNTRIES` | ex `US` | valid legal tag with a other relevant data countries | no | - | -| `LEGAL_TAG` | ex `opendes-demo-legaltag` | valid legal tag with a other relevant data countries from `DEFAULT_OTHER_RELEVANT_DATA_COUNTRIES` | no | - | -| `DEFAULT_DATA_PARTITION_ID_TENANT1` | ex `opendes` | HTTP Header 'Data-Partition-ID' | no | - | -| `SEARCH_INTEGRATION_TESTER` | `********` | Service account for API calls. Note: this user must have entitlements configured already | yes | https://console.cloud.google.com/iam-admin/serviceaccounts | -| `SEARCH_HOST` | ex `http://localhost:8080/api/search/v2/` | Endpoint of search service | no | - | -| `STORAGE_HOST` | ex `http://os-storage-dot-opendes.appspot.com/api/storage/v2/` | Storage API endpoint | no | output of infrastructure deployment | -| `SECURITY_HTTPS_CERTIFICATE_TRUST` | ex `false` | Elastic client connection uses TrustSelfSignedStrategy(), if it is 'true' | false | output of infrastructure deployment | - -**Entitlements configuration for integration accounts** - -| INTEGRATION_TESTER | NO_DATA_ACCESS_TESTER | -| --- | --- | -| users<br/>service.entitlements.user<br/>service.search.user<br/>service.search.admin<br/>data.test1<br/>data.integration.test<br/>users@{tenant1}@{domain}.com | - -Execute following command to build code and run all the integration tests: -```bash -# Note: this assumes that the environment variables for integration tests as outlined -# above are already exported in your environment. -$ (cd testing/indexer-test-gcp/ && mvn clean test) -``` +This section describes how to run cloud OSDU E2E tests. + +### Anthos test configuration: +[Anthos service configuration ](docs/anthos/README.md) +### GCP test configuration: +[Gcp service configuration ](docs/gcp/README.md) ## Deployment diff --git a/provider/indexer-gcp/docs/anthos/README.md b/provider/indexer-gcp/docs/anthos/README.md index 880cce5011fff28c9737475189f3f96b8b6d17e3..00a46a783f1d9cbea3c9121ae2d7f7e044d34dde 100644 --- a/provider/indexer-gcp/docs/anthos/README.md +++ b/provider/indexer-gcp/docs/anthos/README.md @@ -208,4 +208,41 @@ Each Client has embedded Service Account (SA) option. Enable SAs for Clients, ma Add `partition-and-entitlements` scope to `Default Client Scopes` and generate Keys. -Give `client-id` and `client-secret` to services, which should be authorized within the platform. \ No newline at end of file +Give `client-id` and `client-secret` to services, which should be authorized within the platform. + +### Running E2E Tests + +You will need to have the following environment variables defined. + +| name | value | description | sensitive? | source | +| --- | --- | --- | --- | --- | +| `ELASTIC_PASSWORD` | `********` | Password for Elasticsearch | yes | output of infrastructure deployment | +| `ELASTIC_USER_NAME` | `********` | User name for Elasticsearch | yes | output of infrastructure deployment | +| `ELASTIC_HOST` | ex `elastic.domain.com` | Host Elasticsearch | yes | output of infrastructure deployment | +| `ELASTIC_PORT` | ex `9243` | Port Elasticsearch | yes | output of infrastructure deployment | +| `INDEXER_HOST` | ex `https://os-indexer-dot-opendes.appspot.com/api/indexer/v2/` | Indexer API endpoint | no | output of infrastructure deployment | +| `ENTITLEMENTS_DOMAIN` | ex `opendes-gcp.projects.com` | OSDU R2 to run tests under | no | - | +| `OTHER_RELEVANT_DATA_COUNTRIES` | ex `US` | valid legal tag with a other relevant data countries | no | - | +| `LEGAL_TAG` | ex `opendes-demo-legaltag` | valid legal tag with a other relevant data countries from `DEFAULT_OTHER_RELEVANT_DATA_COUNTRIES` | no | - | +| `DEFAULT_DATA_PARTITION_ID_TENANT1` | ex `opendes` | HTTP Header 'Data-Partition-ID' | no | - | +| `DEFAULT_DATA_PARTITION_ID_TENANT2` | ex `opendes` | HTTP Header 'Data-Partition-ID' | no | - | +| `SEARCH_HOST` | ex `http://localhost:8080/api/search/v2/` | Endpoint of search service | no | - | +| `STORAGE_HOST` | ex `http://os-storage-dot-opendes.appspot.com/api/storage/v2/` | Storage API endpoint | no | output of infrastructure deployment | +| `SECURITY_HTTPS_CERTIFICATE_TRUST` | ex `false` | Elastic client connection uses TrustSelfSignedStrategy(), if it is 'true' | false | output of infrastructure deployment | +| `TEST_OPENID_PROVIDER_CLIENT_ID` | `********` | Client Id for `$INTEGRATION_TESTER` | yes | -- | +| `TEST_OPENID_PROVIDER_CLIENT_SECRET` | `********` | | Client secret for `$INTEGRATION_TESTER` | -- | +| `TEST_OPENID_PROVIDER_URL` | `https://keycloak.com/auth/realms/osdu` | OpenID provider url | yes | -- | + +**Entitlements configuration for integration accounts** + +| INTEGRATION_TESTER | NO_DATA_ACCESS_TESTER | +| --- | --- | +| users<br/>users.datalake.ops<br/>service.storage.creator<br/>service.entitlements.user<br/>service.search.user<br/>service.search.admin<br/>data.test1<br/>data.integration.test<br/>users@{tenant1}@{domain}.com | + +Execute following command to build code and run all the integration tests: + +```bash +# Note: this assumes that the environment variables for integration tests as outlined +# above are already exported in your environment. +$ (cd testing/indexer-test-anthos/ && mvn clean test) +``` diff --git a/provider/indexer-gcp/docs/gcp/README.md b/provider/indexer-gcp/docs/gcp/README.md index d583f831a53e5738cdf913fb0b0669974b8f26a8..c10d82b8d7b3f694f3c05a0df52b4cd3693e6f5c 100644 --- a/provider/indexer-gcp/docs/gcp/README.md +++ b/provider/indexer-gcp/docs/gcp/README.md @@ -116,3 +116,40 @@ TBD | Required roles | | --- | | - | + +### Running E2E Tests + +You will need to have the following environment variables defined. + +| name | value | description | sensitive? | source | +| --- | --- | --- | --- | --- | +| `ELASTIC_PASSWORD` | `********` | Password for Elasticsearch | yes | output of infrastructure deployment | +| `ELASTIC_USER_NAME` | `********` | User name for Elasticsearch | yes | output of infrastructure deployment | +| `ELASTIC_HOST` | ex `elastic.domain.com` | Host Elasticsearch | yes | output of infrastructure deployment | +| `ELASTIC_PORT` | ex `9243` | Port Elasticsearch | yes | output of infrastructure deployment | +| `GCLOUD_PROJECT` | ex `opendes` | Google Cloud Project Id| no | output of infrastructure deployment | +| `INDEXER_HOST` | ex `https://os-indexer-dot-opendes.appspot.com/api/indexer/v2/` | Indexer API endpoint | no | output of infrastructure deployment | +| `ENTITLEMENTS_DOMAIN` | ex `opendes-gcp.projects.com` | OSDU R2 to run tests under | no | - | +| `INTEGRATION_TEST_AUDIENCE` | `********` | client application ID | yes | https://console.cloud.google.com/apis/credentials | +| `OTHER_RELEVANT_DATA_COUNTRIES` | ex `US` | valid legal tag with a other relevant data countries | no | - | +| `LEGAL_TAG` | ex `opendes-demo-legaltag` | valid legal tag with a other relevant data countries from `DEFAULT_OTHER_RELEVANT_DATA_COUNTRIES` | no | - | +| `DEFAULT_DATA_PARTITION_ID_TENANT1` | ex `opendes` | HTTP Header 'Data-Partition-ID' | no | - | +| `DEFAULT_DATA_PARTITION_ID_TENANT2` | ex `opendes` | HTTP Header 'Data-Partition-ID' | no | - | +| `SEARCH_INTEGRATION_TESTER` | `********` | Service account for API calls. Note: this user must have entitlements configured already | yes | https://console.cloud.google.com/iam-admin/serviceaccounts | +| `SEARCH_HOST` | ex `http://localhost:8080/api/search/v2/` | Endpoint of search service | no | - | +| `STORAGE_HOST` | ex `http://os-storage-dot-opendes.appspot.com/api/storage/v2/` | Storage API endpoint | no | output of infrastructure deployment | +| `SECURITY_HTTPS_CERTIFICATE_TRUST` | ex `false` | Elastic client connection uses TrustSelfSignedStrategy(), if it is 'true' | false | output of infrastructure deployment | + +**Entitlements configuration for integration accounts** + +| INTEGRATION_TESTER | NO_DATA_ACCESS_TESTER | +| --- | --- | +| users<br/>users.datalake.ops<br/>service.storage.creator<br/>service.entitlements.user<br/>service.search.user<br/>service.search.admin<br/>data.test1<br/>data.integration.test<br/>users@{tenant1}@{domain}.com | + +Execute following command to build code and run all the integration tests: + +```bash +# Note: this assumes that the environment variables for integration tests as outlined +# above are already exported in your environment. +$ (cd testing/indexer-test-gcp/ && mvn clean test) +``` diff --git a/testing/indexer-test-anthos/pom.xml b/testing/indexer-test-anthos/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..ac8650f3090ad99f373a77f4b934199ebd575f31 --- /dev/null +++ b/testing/indexer-test-anthos/pom.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Copyright 2020-2022 Google LLC + ~ Copyright 2020-2022 EPAM Systems, Inc + ~ + ~ 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>indexer-test</artifactId> + <groupId>org.opengroup.osdu</groupId> + <version>0.15.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>indexer-test-anthos</artifactId> + + <properties> + <maven.compiler.target>1.8</maven.compiler.target> + <maven.compiler.source>1.8</maven.compiler.source> + <cucumber.version>1.2.5</cucumber.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.opengroup.osdu.indexer</groupId> + <artifactId>indexer-test-core</artifactId> + <version>0.15.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>com.nimbusds</groupId> + <artifactId>oauth2-oidc-sdk</artifactId> + <version>9.15</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.16</version> + <scope>provided</scope> + </dependency> + <!-- Cucumber --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-java</artifactId> + <version>${cucumber.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-junit</artifactId> + <version>${cucumber.version}</version> + <scope>test</scope> + </dependency> + <!--Logging--> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-to-slf4j</artifactId> + <version>2.11.2</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.8.0-beta4</version> + </dependency> + </dependencies> + +</project> \ No newline at end of file diff --git a/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/info/RunTest.java b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/info/RunTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e4047549cbd0eecef2c284b2ed11532e02142f7d --- /dev/null +++ b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/info/RunTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020-2022 Google LLC + * Copyright 2020-2022 EPAM Systems, Inc + * + * 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.step_definitions.info; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions( + features = "classpath:features/info/Info.feature", + glue = {"classpath:org.opengroup.osdu.step_definitions.info"}, + plugin = {"pretty", "junit:target/cucumber-reports/TEST-info.xml"}) +public class RunTest { + +} \ No newline at end of file diff --git a/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/info/Steps.java b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/info/Steps.java new file mode 100644 index 0000000000000000000000000000000000000000..67ae1d3dbf5b81086ecd2c489f815d8bfcd6e424 --- /dev/null +++ b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/info/Steps.java @@ -0,0 +1,63 @@ +/* + * Copyright 2020-2022 Google LLC + * Copyright 2020-2022 EPAM Systems, Inc + * + * 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.step_definitions.info; + +import cucumber.api.Scenario; +import cucumber.api.java.Before; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; +import org.opengroup.osdu.common.info.InfoSteps; +import org.opengroup.osdu.util.AnthosHTTPClient; +import org.opengroup.osdu.util.Config; + +public class Steps extends InfoSteps { + + public Steps() { + super(new AnthosHTTPClient()); + } + + @Before + public void before(Scenario scenario) { + this.scenario = scenario; + this.httpClient = new AnthosHTTPClient(); + } + + /******************Inputs being set**************/ + + @When("^I send get request to version info endpoint") + public void i_send_get_request_to_version_info_endpoint() { + super.i_send_get_request_to_version_info_endpoint(); + } + + /******************Assert final response**************/ + + @Then("^I should get version info in response$") + public void i_should_get_version_info_in_response() { + super.i_should_get_version_info_in_response(); + } + + @Override + protected String getHttpMethod() { + return "GET"; + } + + @Override + protected String getApi() { + return Config.getIndexerBaseURL() + "info"; + } +} \ No newline at end of file diff --git a/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/record/RunTest.java b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/record/RunTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b6a3467565aadd39849257e391f962702629daa7 --- /dev/null +++ b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/record/RunTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020-2022 Google LLC + * Copyright 2020-2022 EPAM Systems, Inc + * + * 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.step_definitions.record; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions( + features = "classpath:features/indexrecord/indexRecord-schema-service.feature", + glue = {"classpath:org.opengroup.osdu.step_definitions.record"}, + plugin = {"pretty", "junit:target/cucumber-reports/TEST-indexrecord.xml"}) +public class RunTest { + +} \ No newline at end of file diff --git a/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/record/Steps.java b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/record/Steps.java new file mode 100644 index 0000000000000000000000000000000000000000..40620fbf4a626a1eb279f28fae937a55ffdc8469 --- /dev/null +++ b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/step_definitions/record/Steps.java @@ -0,0 +1,124 @@ +/* + * Copyright 2020-2022 Google LLC + * Copyright 2020-2022 EPAM Systems, Inc + * + * 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.step_definitions.record; + +import cucumber.api.DataTable; +import cucumber.api.Scenario; +import cucumber.api.java.Before; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; +import lombok.extern.java.Log; +import org.opengroup.osdu.common.SchemaServiceRecordSteps; +import org.opengroup.osdu.util.AnthosHTTPClient; +import org.opengroup.osdu.util.ElasticUtils; + +@Log +public class Steps extends SchemaServiceRecordSteps { + + public Steps() { + super(new AnthosHTTPClient(), new ElasticUtils()); + } + + @Before + public void before(Scenario scenario) { + this.scenario = scenario; + this.httpClient = new AnthosHTTPClient(); + } + + @Given("^the schema is created with the following kind$") + public void the_schema_is_created_with_the_following_kind(DataTable dataTable) { + super.the_schema_is_created_with_the_following_kind(dataTable); + } + + @When("^I ingest records with the \"(.*?)\" with \"(.*?)\" for a given \"(.*?)\"$") + public void i_ingest_records_with_the_for_a_given(String record, String dataGroup, String kind) { + super.i_ingest_records_with_the_for_a_given(record, dataGroup, kind); + } + + @When("^I create index with \"(.*?)\" for a given \"(.*?)\" and \"(.*?)\"$") + public void i_create_index_with_mapping_file_for_a_given_kind(String mappingFile, String index, String kind) throws Throwable { + super.i_create_index_with_mapping_file_for_a_given_kind(mappingFile, index, kind); + } + + @Then("^I should get the (\\d+) documents for the \"([^\"]*)\" in the Elastic Search$") + public void i_should_get_the_documents_for_the_in_the_Elastic_Search(int expectedCount, String index) throws Throwable { + super.i_should_get_the_documents_for_the_in_the_Elastic_Search(expectedCount, index); + } + + @Then("^I should not get any documents for the \"([^\"]*)\" in the Elastic Search$") + public void i_should_not_get_any_documents_for_the_index_in_the_Elastic_Search(String index) throws Throwable { + super.i_should_not_get_any_documents_for_the_index_in_the_Elastic_Search(index); + } + + @Then("^I should get the elastic \"(.*?)\" for the \"([^\"]*)\" and \"([^\"]*)\" in the Elastic Search$") + public void i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(String expectedMapping, String kind, String index) + throws Throwable { + super.i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(expectedMapping, kind, index); + } + + @Then("^I can validate indexed meta attributes for the \"([^\"]*)\" and given \"([^\"]*)\"$") + public void i_can_validate_indexed_meta_attributes(String index, String kind) throws Throwable { + super.i_can_validate_indexed_attributes(index, kind); + } + + @Then("^I should get the (\\d+) documents for the \"([^\"]*)\" in the Elastic Search with out \"(.*?)\"$") + public void iShouldGetTheNumberDocumentsForTheIndexInTheElasticSearchWithOutSkippedAttribute(int expectedCount, String index, String skippedAttributes) + throws Throwable { + super.iShouldGetTheNumberDocumentsForTheIndexInTheElasticSearchWithOutSkippedAttribute(expectedCount, index, skippedAttributes); + } + + @Then("^I should be able to search (\\d+) record with index \"([^\"]*)\" by tag \"([^\"]*)\" and value \"([^\"]*)\"$") + public void iShouldBeAbleToSearchRecordByTagKeyAndTagValue(int expectedNumber, String index, String tagKey, String tagValue) throws Throwable { + super.iShouldBeAbleToSearchRecordByTagKeyAndTagValue(index, tagKey, tagValue, expectedNumber); + } + + @Then("^I should be able search (\\d+) documents for the \"([^\"]*)\" by bounding box query with points \\((-?\\d+), (-?\\d+)\\) and \\((-?\\d+), (-?\\d+)\\) on field \"([^\"]*)\"$") + public void i_should_get_the_documents_for_the_in_the_Elastic_Search_by_geoQuery( + int expectedCount, String index, Double topLatitude, Double topLongitude, Double bottomLatitude, Double bottomLongitude, String field) + throws Throwable { + String actualName = generateActualName(index, null); + super.i_should_get_the_documents_for_the_in_the_Elastic_Search_by_geoQuery(expectedCount, actualName, topLatitude, topLongitude, bottomLatitude, + bottomLongitude, field); + } + + @Then("^I should be able search (\\d+) documents for the \"([^\"]*)\" by nested \"([^\"]*)\" and properties \\(\"([^\"]*)\", (\\d+)\\) and \\(\"([^\"]*)\", \"([^\"]*)\"\\)$") + public void i_should_get_the_documents_for_the_in_the_Elastic_Search_by_nestedQuery( + int expectedCount, String index, String path, String firstNestedProperty, String firstNestedValue, String secondNestedProperty, + String secondNestedValue) throws Throwable { + String actualName = generateActualName(index, null); + super.i_should_get_the_documents_for_the_in_the_Elastic_Search_by_nestedQuery(expectedCount, actualName, path, firstNestedProperty, firstNestedValue, + secondNestedProperty, secondNestedValue); + } + + @Then("^I should be able search (\\d+) documents for the \"([^\"]*)\" by flattened inner properties \\(\"([^\"]*)\", \"([^\"]*)\"\\)$") + public void i_should_be_able_search_documents_for_the_by_flattened_inner_properties(int expectedCount, String index, String flattenedField, + String flattenedFieldValue) throws Throwable { + String actualName = generateActualName(index, null); + super.i_should_be_able_search_documents_for_the_by_flattened_inner_properties(expectedCount, actualName, flattenedField, flattenedFieldValue); + + } + + @Then("^I should get \"([^\"]*)\" in response, without hints in schema for the \"([^\"]*)\" that present in the \"([^\"]*)\" with \"([^\"]*)\" for a given \"([^\"]*)\"$") + public void i_should_get_object_in_search_response_without_hints_in_schema(String objectInnerField, String index, String recordFile, String acl, + String kind) + throws Throwable { + String actualName = generateActualName(index, null); + super.i_should_get_object_in_search_response_without_hints_in_schema(objectInnerField, actualName, recordFile, acl, kind); + } +} \ No newline at end of file diff --git a/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/AnthosHTTPClient.java b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/AnthosHTTPClient.java new file mode 100644 index 0000000000000000000000000000000000000000..7bf1aeab02562e475333ebcb2623fbb589f70adf --- /dev/null +++ b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/AnthosHTTPClient.java @@ -0,0 +1,37 @@ +/* + * Copyright 2020-2022 Google LLC + * Copyright 2020-2022 EPAM Systems, Inc + * + * 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 lombok.ToString; +import lombok.extern.java.Log; + +@Log +@ToString +public class AnthosHTTPClient extends HTTPClient { + + private static String token = null; + private static OpenIDTokenProvider openIDTokenProvider = new OpenIDTokenProvider(); + + @Override + public synchronized String getAccessToken() { + if (token == null) { + token = "Bearer " + openIDTokenProvider.getToken(); + } + return token; + } +} \ No newline at end of file diff --git a/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/OpenIDTokenProvider.java b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/OpenIDTokenProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..829d1a8bcc5feedf02817a1e6a537a8463c66e37 --- /dev/null +++ b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/OpenIDTokenProvider.java @@ -0,0 +1,79 @@ +/* + * Copyright 2020-2022 Google LLC + * Copyright 2020-2022 EPAM Systems, Inc + * + * 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 com.nimbusds.oauth2.sdk.AuthorizationGrant; +import com.nimbusds.oauth2.sdk.ClientCredentialsGrant; +import com.nimbusds.oauth2.sdk.ParseException; +import com.nimbusds.oauth2.sdk.Scope; +import com.nimbusds.oauth2.sdk.TokenRequest; +import com.nimbusds.oauth2.sdk.TokenResponse; +import com.nimbusds.oauth2.sdk.auth.ClientAuthentication; +import com.nimbusds.oauth2.sdk.auth.ClientSecretBasic; +import com.nimbusds.oauth2.sdk.auth.Secret; +import com.nimbusds.oauth2.sdk.id.ClientID; +import com.nimbusds.openid.connect.sdk.OIDCTokenResponseParser; +import java.io.IOException; +import java.net.URI; +import java.util.Objects; +import net.minidev.json.JSONObject; +import org.opengroup.osdu.util.conf.OpenIDProviderConfig; + +public class OpenIDTokenProvider { + + private static final OpenIDProviderConfig openIDProviderConfig = OpenIDProviderConfig.Instance(); + private static final String ID_TOKEN = "id_token"; + private final AuthorizationGrant clientGrant = new ClientCredentialsGrant(); + private final URI tokenEndpointURI; + private final Scope scope; + private final ClientAuthentication clientAuthentication; + + public OpenIDTokenProvider() { + this.tokenEndpointURI = openIDProviderConfig.getProviderMetadata().getTokenEndpointURI(); + this.scope = new Scope(openIDProviderConfig.getScopes()); + this.clientAuthentication = + new ClientSecretBasic( + new ClientID(openIDProviderConfig.getClientId()), + new Secret(openIDProviderConfig.getClientSecret()) + ); + } + + public String getToken() { + try { + return requestToken(); + } catch (ParseException | IOException e) { + throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e); + } + } + + private String requestToken() throws ParseException, IOException { + TokenRequest request = new TokenRequest(this.tokenEndpointURI, this.clientAuthentication, this.clientGrant, this.scope); + TokenResponse parse = OIDCTokenResponseParser.parse(request.toHTTPRequest().send()); + + if (!parse.indicatesSuccess()) { + throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables"); + } + + JSONObject jsonObject = parse.toSuccessResponse().toJSONObject(); + String idTokenValue = jsonObject.getAsString(ID_TOKEN); + if (Objects.isNull(idTokenValue) || idTokenValue.isEmpty()) { + throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables"); + } + return idTokenValue; + } +} diff --git a/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/conf/OpenIDProviderConfig.java b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/conf/OpenIDProviderConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..44e991e1ffe43c8da7c0033f3099714fb6506cbc --- /dev/null +++ b/testing/indexer-test-anthos/src/test/java/org/opengroup/osdu/util/conf/OpenIDProviderConfig.java @@ -0,0 +1,66 @@ +/* + * Copyright 2020-2022 Google LLC + * Copyright 2020-2022 EPAM Systems, Inc + * + * 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.conf; + +import com.nimbusds.oauth2.sdk.http.HTTPRequest; +import com.nimbusds.oauth2.sdk.http.HTTPResponse; +import com.nimbusds.oauth2.sdk.id.Issuer; +import com.nimbusds.openid.connect.sdk.op.OIDCProviderConfigurationRequest; +import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata; + +public class OpenIDProviderConfig { + + private String clientId; + private String url; + private String clientSecret; + private final String[] scopes = {"openid"}; + private static final OpenIDProviderConfig openIDProviderConfig = new OpenIDProviderConfig(); + private static OIDCProviderMetadata providerMetadata; + + public static OpenIDProviderConfig Instance() { + try { + openIDProviderConfig.clientId = System.getProperty("TEST_OPENID_PROVIDER_CLIENT_ID", System.getenv("TEST_OPENID_PROVIDER_CLIENT_ID")); + openIDProviderConfig.url = System.getProperty("TEST_OPENID_PROVIDER_URL", System.getenv("TEST_OPENID_PROVIDER_URL")); + openIDProviderConfig.clientSecret = System.getProperty("TEST_OPENID_PROVIDER_CLIENT_SECRET", System.getenv("TEST_OPENID_PROVIDER_CLIENT_SECRET")); + Issuer issuer = new Issuer(openIDProviderConfig.url); + OIDCProviderConfigurationRequest request = new OIDCProviderConfigurationRequest(issuer); + HTTPRequest httpRequest = request.toHTTPRequest(); + HTTPResponse httpResponse = httpRequest.send(); + providerMetadata = OIDCProviderMetadata.parse(httpResponse.getContentAsJSONObject()); + } catch (Exception e) { + throw new RuntimeException("Malformed token provider configuration", e); + } + return openIDProviderConfig; + } + + public String getClientId() { + return clientId; + } + + public String getClientSecret() { + return clientSecret; + } + + public String[] getScopes() { + return scopes; + } + + public OIDCProviderMetadata getProviderMetadata() { + return providerMetadata; + } +} diff --git a/testing/indexer-test-anthos/src/test/java/resources/logback-test.xml b/testing/indexer-test-anthos/src/test/java/resources/logback-test.xml new file mode 100644 index 0000000000000000000000000000000000000000..22c6175d45f368b69c4006deb9ebf3ff5084579a --- /dev/null +++ b/testing/indexer-test-anthos/src/test/java/resources/logback-test.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/defaults.xml"/> + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%yellow([%thread]) %highlight(| %-5level |) %green(%d) %cyan(| %logger{15} |) %highlight(%msg) %n</pattern> + <charset>utf8</charset> + </encoder> + </appender> + <root level="INFO"> + <appender-ref ref="CONSOLE" /> + </root> +</configuration> diff --git a/testing/pom.xml b/testing/pom.xml index 047e96b2b66e33a975bdfae33bc5cb0c4210cbb6..688309f4fff2b11c6231bb105a07287b6170294e 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -39,7 +39,8 @@ <module>indexer-test-aws</module> <module>indexer-test-azure</module> <module>indexer-test-ibm</module> - </modules> + <module>indexer-test-anthos</module> + </modules> <repositories> <repository>