Skip to content
Snippets Groups Projects
Commit c04776a7 authored by Anastasiia Gelmut's avatar Anastasiia Gelmut
Browse files

GONRG-1537 Finalize Partition Service

-Integration tests are implemented.
parent b5b1e174
No related branches found
No related tags found
4 merge requests!47Authentication for PartitionService to work under SA(GONRG-1843),!45(GONRG-2074) GCP incorrect response,!36Partition: Audit Logs Implementation (GONRG-1607),!35Partition Service for GCP (GONRG-1706)
Showing
with 409 additions and 1 deletion
<?xml version="1.0" encoding="UTF-8"?>
<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.0.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.opengroup.osdu.partition</groupId>
<artifactId>partition-test-gcp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-gcp</artifactId>
<version>0.3.25</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu.partition</groupId>
<artifactId>partition-test-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
</dependencies>
</project>
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 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.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.GCPTestUtils;
public class TestCreatePartition extends CreatePartitionTest {
@Override
@Before
public void setup() throws Exception {
this.testUtils = new GCPTestUtils();
}
@Override
@After
public void tearDown() throws Exception {
this.testUtils = null;
}
}
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 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.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.GCPTestUtils;
public class TestDeletePartition extends DeletePartitionTest {
@Override
@Before
public void setup() throws Exception {
this.testUtils = new GCPTestUtils();
}
@Override
@After
public void tearDown() throws Exception {
this.testUtils = null;
}
}
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 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.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.GCPTestUtils;
public class TestGetPartitionById extends GetPartitionByIdApitTest {
@Override
@Before
public void setup() throws Exception {
this.testUtils = new GCPTestUtils();
}
@Override
@After
public void tearDown() throws Exception {
this.testUtils = null;
}
}
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 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.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.GCPTestUtils;
public class TestListPartitions extends ListPartitionsApitTest {
@Override
@Before
public void setup() throws Exception {
this.testUtils = new GCPTestUtils();
}
@Override
@After
public void tearDown() throws Exception {
this.testUtils = null;
}
}
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 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.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.GCPTestUtils;
public class TestUpdatePartition extends UpdatePartitionTest {
@Override
@Before
public void setup() throws Exception {
this.testUtils = new GCPTestUtils();
}
@Override
@After
public void tearDown() throws Exception {
this.testUtils = null;
}
}
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 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.partition.util;
import com.google.common.base.Strings;
public class GCPTestUtils extends TestUtils {
@Override
public String getAccessToken() throws Exception {
if (Strings.isNullOrEmpty(token)) {
String serviceAccountFile = System
.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER"));
String audience = System.getProperty("INTEGRATION_TEST_AUDIENCE",
System.getenv("INTEGRATION_TEST_AUDIENCE"));
if (Strings.isNullOrEmpty(audience)) {
audience = "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com";
}
token = new GoogleServiceAccount(serviceAccountFile).getAuthToken(audience);
}
return "Bearer " + token;
}
@Override
public String getNoAccessToken() throws Exception {
if (Strings.isNullOrEmpty(noAccessToken)) {
String serviceAccountFile = System.getProperty("NO_DATA_ACCESS_TESTER",
System.getenv("NO_DATA_ACCESS_TESTER"));
String audience = System.getProperty("INTEGRATION_TEST_AUDIENCE",
System.getenv("INTEGRATION_TEST_AUDIENCE"));
if (Strings.isNullOrEmpty(audience)) {
audience = "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com";
}
noAccessToken = new GoogleServiceAccount(serviceAccountFile).getAuthToken(audience);
}
return "Bearer " + noAccessToken;
}
}
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 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.partition.util;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class GoogleServiceAccount {
public GoogleServiceAccount(String serviceAccountEncoded) throws IOException {
this(Base64.getDecoder().decode(serviceAccountEncoded));
}
public GoogleServiceAccount(byte[] serviceAccountJson) throws IOException {
try (InputStream inputStream = new ByteArrayInputStream(serviceAccountJson)) {
this.serviceAccount = ServiceAccountCredentials.fromStream(inputStream);
}
}
final ServiceAccountCredentials serviceAccount;
public String getEmail() {
return this.serviceAccount.getClientEmail();
}
public String getAuthToken(String audience) throws IOException {
JwtBuilder jwtBuilder = Jwts.builder();
Map<String, Object> header = new HashMap<>();
header.put("type", "JWT");
header.put("alg", "RS256");
jwtBuilder.setHeader(header);
Map<String, Object> claims = new HashMap<>();
claims.put("target_audience", audience);
claims.put("exp", System.currentTimeMillis() / 1000 + 3600);
claims.put("iat", System.currentTimeMillis() / 1000);
claims.put("iss", this.getEmail());
claims.put("aud", "https://www.googleapis.com/oauth2/v4/token");
jwtBuilder.addClaims(claims);
jwtBuilder.signWith(SignatureAlgorithm.RS256, this.serviceAccount.getPrivateKey());
String jwt = jwtBuilder.compact();
HttpPost httpPost = new HttpPost("https://www.googleapis.com/oauth2/v4/token");
ArrayList<NameValuePair> postParameters = new ArrayList<>();
postParameters
.add(new BasicNameValuePair("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer"));
postParameters.add(new BasicNameValuePair("assertion", jwt));
HttpClient client = new DefaultHttpClient();
httpPost.setEntity(new UrlEncodedFormEntity(postParameters, "UTF-8"));
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
HttpResponse response = client.execute(httpPost);
String responseEntity = EntityUtils.toString(response.getEntity());
JsonObject content = new JsonParser().parse(responseEntity).getAsJsonObject();
return content.get("id_token").getAsString();
}
}
......@@ -36,7 +36,8 @@
<module>partition-test-azure</module>
<module>partition-test-aws</module>
<module>partition-test-ibm</module>
</modules>
<module>partition-test-gcp</module>
</modules>
<repositories>
<repository>
......
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