Skip to content
Snippets Groups Projects
Commit 87612853 authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM) Committed by Riabokon Stanislav(EPAM)[GCP]
Browse files

int tests for anthos env (GONRG-4979)

parent fb166a41
No related branches found
No related tags found
2 merge requests!229Merge branch 'dependency-upgrade' into 'master',!187int tests for anthos env (GONRG-4979)
Showing
with 772 additions and 22 deletions
......@@ -115,27 +115,12 @@ $ (cd testing/partition-test-core/ && mvn clean install)
```
### Running E2E Tests
This section describes how to run cloud OSDU E2E tests (testing/partition-test-gcp).
This section describes how to run cloud OSDU E2E tests.
You will need to have the following environment variables defined.
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `ENVIRONMENT` | ex `dev` | | no | |
| `PARTITION_BASE_URL` | ex `http://localhost:8080/` | service base URL | yes | |
| `CLIENT_TENANT` | ex `opendes` | name of the client partition | yes | |
| `MY_TENANT` | ex `opendes` | name of the OSDU partition | yes | |
| `INTEGRATION_TESTER` | `********` | Service account for API calls. Note: this user must be `PARTITION_ADMIN_ACCOUNT` | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
| `NO_DATA_ACCESS_TESTER` | `********` | Service account base64 encoded string without data access | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
| `INTEGRATION_TEST_AUDIENCE` | `********` | client application ID | yes | https://console.cloud.google.com/apis/credentials |
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/partition-test-gcp/ && mvn clean test)
```
### Anthos test configuration:
[Anthos service configuration ](docs/anthos/README.md)
### GCP test configuration:
[Gcp service configuration ](docs/gcp/README.md)
## Deployment
Partition Service is compatible with App Engine Flexible Environment and Cloud Run.
......
......@@ -44,3 +44,27 @@ CONSTRAINT PartitionProperty_id UNIQUE (id)
CREATE INDEX PartitionProperty_dataGin ON partition."PartitionProperty" USING GIN (data);
```
### Running E2E Tests
You will need to have the following environment variables defined.
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `ENVIRONMENT` | ex `dev` | | no | |
| `PARTITION_BASE_URL` | ex `http://localhost:8080/` | service base URL | yes | |
| `CLIENT_TENANT` | ex `opendes` | name of the client partition | yes | |
| `MY_TENANT` | ex `opendes` | name of the OSDU partition | yes | |
| `TEST_OPENID_PROVIDER_CLIENT_ID` | `********` | Client Id for `$INTEGRATION_TESTER` | yes | -- |
| `TEST_OPENID_PROVIDER_CLIENT_SECRET` | `********` | | Client secret for `$INTEGRATION_TESTER` | -- |
| `TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID` | `********` | Client Id for `$NO_ACCESS_INTEGRATION_TESTER` | yes | -- |
| `TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET` | `********` | | Client secret for `$NO_ACCESS_INTEGRATION_TESTER` | -- |
| `TEST_OPENID_PROVIDER_URL` | `https://keycloak.com/auth/realms/osdu` | OpenID provider url | yes | -- |
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/partition-test-anthos/ && mvn clean test)
```
\ No newline at end of file
......@@ -35,4 +35,26 @@ TBD
| Required roles |
| --- |
| - |
\ No newline at end of file
| - |
### Running E2E Tests
You will need to have the following environment variables defined.
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `ENVIRONMENT` | ex `dev` | | no | |
| `PARTITION_BASE_URL` | ex `http://localhost:8080/` | service base URL | yes | |
| `CLIENT_TENANT` | ex `opendes` | name of the client partition | yes | |
| `MY_TENANT` | ex `opendes` | name of the OSDU partition | yes | |
| `INTEGRATION_TESTER` | `********` | Service account for API calls. Note: this user must be `PARTITION_ADMIN_ACCOUNT` | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
| `NO_DATA_ACCESS_TESTER` | `********` | Service account base64 encoded string without data access | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
| `INTEGRATION_TEST_AUDIENCE` | `********` | client application ID | yes | https://console.cloud.google.com/apis/credentials |
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/partition-test-gcp/ && mvn clean test)
```
\ No newline at end of file
<?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
~
~ https://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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-partition-testing</artifactId>
<version>0.15.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.opengroup.osdu.partition</groupId>
<artifactId>partition-test-anthos</artifactId>
<version>0.15.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu.partition</groupId>
<artifactId>partition-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>
</dependencies>
</project>
\ No newline at end of file
/*
* 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
*
* https://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.partition.api;
import static org.junit.Assert.assertEquals;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestCreatePartition extends CreatePartitionTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
@After
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
@Test
public void should_return40XResponseCode_when_makingRequest_withInvalidPayload()
throws Exception {
String invalidPayload = "{\"properties_invalid\":{}}";
ClientResponse response = descriptor.runWithCustomPayload(getId(), invalidPayload,
testUtils.getAccessToken());
assertEquals(400, response.getStatus());
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
/*
* 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
*
* https://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.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestDeletePartition extends DeletePartitionTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
@After
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
/*
* 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
*
* https://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.partition.api;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestGetPartitionById extends GetPartitionByIdApitTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
@After
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
protected void deleteResource() throws Exception {
DeletePartitionDescriptor deletePartitionDes = new DeletePartitionDescriptor();
deletePartitionDes.setPartitionId(getId());
ClientResponse response = deletePartitionDes.run(getId(), this.testUtils.getAccessToken());
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
/*
* 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
*
* https://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.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestGetVersionInfo extends GetVersionInfoApiTest {
@Before
@Override
public void setup() {
this.testUtils = new AnthosTestUtils();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
}
/*
* 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
*
* https://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.partition.api;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestListPartitions extends ListPartitionsApitTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
@After
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
protected void deleteResource() throws Exception {
DeletePartitionDescriptor deletePartitionDes = new DeletePartitionDescriptor();
deletePartitionDes.setPartitionId(getId());
ClientResponse response = deletePartitionDes.run(getId(), this.testUtils.getAccessToken());
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
/*
* 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
*
* https://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.partition.api;
import static org.junit.Assert.assertEquals;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestUpdatePartition extends UpdatePartitionTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
@After
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
protected void deleteResource() throws Exception {
DeletePartitionDescriptor deletePartitionDes = new DeletePartitionDescriptor();
deletePartitionDes.setPartitionId(getId());
ClientResponse response = deletePartitionDes.run(getId(), this.testUtils.getAccessToken());
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
/*
* 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
*
* https://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.partition.api.util;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.junit.Assert.assertThat;
import com.sun.jersey.api.client.ClientResponse;
import org.hamcrest.core.Is;
import org.opengroup.osdu.partition.util.RestDescriptor;
import org.opengroup.osdu.partition.util.TestUtils;
public class AnthosAuthorizationTestUtil {
private RestDescriptor descriptor;
private TestUtils testUtils;
public AnthosAuthorizationTestUtil(RestDescriptor descriptor, TestUtils testUtils) {
this.descriptor = descriptor;
this.testUtils = testUtils;
}
public void should_return401or403_when_noAccessToken(String partitionId) throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(partitionId, testUtils.getNoAccessToken());
assertThat(error(response.getEntity(String.class)), response.getStatus(), anyOf(Is.is(401), Is.is(403)));
}
public void should_return401or403_when_accessingWithCredentialsWithoutPermission(String partitionId) throws Exception {
ClientResponse response = descriptor.run(partitionId, testUtils.getNoAccessToken());
assertThat(error(response.getEntity(String.class)), response.getStatus(), anyOf(Is.is(401), Is.is(403)));
}
public void should_return401or403_when_makingHttpRequestWithoutToken(String partitionId) throws Exception {
ClientResponse response = descriptor.run(partitionId, "");
assertThat(error(response.getEntity(String.class)), response.getStatus(), anyOf(Is.is(401), Is.is(403)));
}
protected String error(String body) {
return String.format("%s: %s %s %s", descriptor.getHttpMethod(), descriptor.getPath(), descriptor.getQuery(), body);
}
}
/*
* 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
*
* https://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.partition.util;
public class AnthosTestUtils extends TestUtils {
private final OpenIDTokenProvider tokenProvider = new OpenIDTokenProvider();
@Override
public String getAccessToken() {
return "Bearer " + tokenProvider.getToken();
}
@Override
public String getNoAccessToken() {
return "Bearer " + tokenProvider.getNoAccessToken();
}
}
/*
* 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
*
* https://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.partition.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.partition.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;
private final ClientAuthentication noAccessClientAuthentication;
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())
);
this.noAccessClientAuthentication =
new ClientSecretBasic(
new ClientID(openIDProviderConfig.getNoAccessClientId()),
new Secret(openIDProviderConfig.getNoAccessClientSecret())
);
}
public String getToken() {
try {
TokenRequest request = new TokenRequest(this.tokenEndpointURI, this.clientAuthentication, this.clientGrant, this.scope);
return requestToken(request);
} catch (ParseException | IOException e) {
throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e);
}
}
public String getNoAccessToken() {
try {
TokenRequest request = new TokenRequest(this.tokenEndpointURI, this.noAccessClientAuthentication, this.clientGrant, this.scope);
return requestToken(request);
} catch (ParseException | IOException e) {
throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e);
}
}
private String requestToken(TokenRequest tokenRequest) throws ParseException, IOException {
TokenResponse parse = OIDCTokenResponseParser.parse(tokenRequest.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;
}
}
/*
* 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
*
* https://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.partition.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 clientSecret;
private String noAccessClientId;
private String noAccessClientSecret;
private String url;
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.clientSecret = System.getProperty("TEST_OPENID_PROVIDER_CLIENT_SECRET", System.getenv("TEST_OPENID_PROVIDER_CLIENT_SECRET"));
openIDProviderConfig.noAccessClientId =
System.getProperty("TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID", System.getenv("TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID"));
openIDProviderConfig.noAccessClientSecret =
System.getProperty("TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET", System.getenv("TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET"));
openIDProviderConfig.url = System.getProperty("TEST_OPENID_PROVIDER_URL", System.getenv("TEST_OPENID_PROVIDER_URL"));
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 getNoAccessClientId() {
return noAccessClientId;
}
public String getNoAccessClientSecret() {
return noAccessClientSecret;
}
public String[] getScopes() {
return scopes;
}
public OIDCProviderMetadata getProviderMetadata() {
return providerMetadata;
}
}
<?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
~
~ https://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.
-->
<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>
......@@ -34,7 +34,8 @@
<module>partition-test-azure</module>
<module>partition-test-aws</module>
<module>partition-test-ibm</module>
<module>partition-test-gcp</module>
<module>partition-test-gcp</module>
<module>partition-test-anthos</module>
</modules>
<repositories>
......
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