From bcacf25f80a2039c4b725cad69c8b8212a85248d Mon Sep 17 00:00:00 2001 From: Bruce <jtyself-dev3> Date: Fri, 25 Aug 2023 15:59:52 +0000 Subject: [PATCH] Increase Test coverage to 82% commit 57009245 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 24 2023 17:51:54 GMT-0500 (Central Daylight Time) Merge branch 'unit-test1' into unit-test3 commit 873db1b7 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 24 2023 17:09:40 GMT-0500 (Central Daylight Time) Remove unwanted lines commit 26ab6365 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 24 2023 17:07:45 GMT-0500 (Central Daylight Time) Add more tests commit 1ad4caf8 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 24 2023 15:55:32 GMT-0500 (Central Daylight Time) Remove not used lines commit bd681935 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 24 2023 15:34:46 GMT-0500 (Central Daylight Time) Add more tests commit 802db683 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 24 2023 14:44:54 GMT-0500 (Central Daylight Time) More test cases, and fix local issues commit e9cb3ed2 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 24 2023 14:30:41 GMT-0500 (Central Daylight Time) Add Unit tests and fix local issues commit 2c570c96 Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 19:49:08 GMT-0500 (Central Daylight Time) Add more tests commit 2fa75ae6 Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 18:45:06 GMT-0500 (Central Daylight Time) Add tests commit a319af22 Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 16:52:47 GMT-0500 (Central Daylight Time) Add more tests commit 96da5b43 Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 16:22:42 GMT-0500 (Central Daylight Time) remove unnecessary lines commit 4117922a Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 16:02:53 GMT-0500 (Central Daylight Time) Remove unnecessary file commit b2f5cb9f Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 15:38:22 GMT-0500 (Central Daylight Time) Fix exceptions commit c4491db6 Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 15:21:40 GMT-0500 (Central Daylight Time) Add tests commit 65fa0fc6 Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 15:17:46 GMT-0500 (Central Daylight Time) Add more tests commit eaa8fa9b Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 12:06:31 GMT-0500 (Central Daylight Time) Add more tests commit 32142ff2 Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 11:41:54 GMT-0500 (Central Daylight Time) Add more tests commit 0894d1da Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 10:49:30 GMT-0500 (Central Daylight Time) Add more tests commit 5aafa5f1 Author: Bruce <jtyself@amazon.com> Date: Wed Aug 23 2023 10:24:08 GMT-0500 (Central Daylight Time) add tests commit 48a74a75 Author: Bruce <jtyself@amazon.com> Date: Fri Aug 18 2023 16:13:44 GMT-0500 (Central Daylight Time) Add more tests commit 61863de6 Author: Bruce <jtyself@amazon.com> Date: Fri Aug 18 2023 15:09:19 GMT-0500 (Central Daylight Time) Add more tests commit 963f194a Author: Bruce <jtyself@amazon.com> Date: Fri Aug 18 2023 14:44:19 GMT-0500 (Central Daylight Time) Add test cases commit 0bf18891 Author: Bruce <jtyself@amazon.com> Date: Fri Aug 18 2023 01:05:06 GMT-0500 (Central Daylight Time) Add copyright commit 7726b997 Author: Bruce <jtyself@amazon.com> Date: Fri Aug 18 2023 00:47:34 GMT-0500 (Central Daylight Time) Add test cases, and use newer version of mockito commit bcfb6fd7 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 17 2023 17:38:07 GMT-0500 (Central Daylight Time) use lombok commit c98b5b65 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 17 2023 13:08:48 GMT-0500 (Central Daylight Time) Enable ssl open commit 21c9e0e1 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 17 2023 12:58:02 GMT-0500 (Central Daylight Time) Elastic client handler test commit 030fb7a0 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 17 2023 12:47:26 GMT-0500 (Central Daylight Time) put back jacoco commit 36a9c095 Author: Bruce <jtyself@amazon.com> Date: Thu Aug 17 2023 12:39:28 GMT-0500 (Central Daylight Time) remove jacoco --- .../indexer/aws/cache/IndexCacheImpl.java | 4 +- .../indexer/aws/cache/SchemaCacheImpl.java | 6 +- .../indexer/aws/cache/IndexCacheImplTest.java | 114 ++++++++++ .../aws/cache/SchemaCacheImplTest.java | 115 +++++++++++ .../ElasticRepositoryImplTest.java | 81 ++++++++ .../UnsafeX509ExtendedTrustManagerTest.java | 194 ++++++++++++++++++ .../util/AwsServiceAccountAuthTokenTest.java | 1 - 7 files changed, 509 insertions(+), 6 deletions(-) create mode 100644 provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImplTest.java create mode 100644 provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImplTest.java create mode 100644 provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/persistence/ElasticRepositoryImplTest.java create mode 100644 provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManagerTest.java diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImpl.java index fc33e78a6..e0ea8092b 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImpl.java @@ -43,7 +43,8 @@ public class IndexCacheImpl implements IIndexCache<String, Boolean>, AutoCloseab public IndexCacheImpl() throws K8sParameterNotFoundException, JsonProcessingException { int expTimeSeconds = 60 * 60; K8sLocalParameterProvider provider = new K8sLocalParameterProvider(); - if (provider.getLocalMode()){ + local = provider.getLocalMode(); + if (local){ if (Boolean.parseBoolean(System.getenv("DISABLE_CACHE"))){ cache = new DummyCache<>(); }else{ @@ -61,7 +62,6 @@ public class IndexCacheImpl implements IIndexCache<String, Boolean>, AutoCloseab } cache = new RedisCache<String, Boolean>(host, port, password, expTimeSeconds, String.class,Boolean.class); } - local = cache instanceof AutoCloseable; } @Override diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImpl.java index 27a1f3792..c615cc0c5 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImpl.java @@ -42,7 +42,8 @@ public class SchemaCacheImpl implements ISchemaCache<String, String>, AutoClosea public SchemaCacheImpl() throws K8sParameterNotFoundException, JsonProcessingException { int expTimeSeconds = 60 * 60; K8sLocalParameterProvider provider = new K8sLocalParameterProvider(); - if (provider.getLocalMode()){ + local = provider.getLocalMode(); + if (local){ if (Boolean.parseBoolean(System.getenv("DISABLE_CACHE"))){ cache = new DummyCache<>(); }else{ @@ -60,13 +61,12 @@ public class SchemaCacheImpl implements ISchemaCache<String, String>, AutoClosea } cache = new RedisCache<>(host, port, password, expTimeSeconds, String.class, String.class); } - local = cache instanceof AutoCloseable; } @Override public void close() throws Exception { if (this.local){ - // do nothing, this is using local dummy cache + // do nothing, this is using local dummy cache or vm cache }else { // cast to redis cache so it can be closed ((AutoCloseable)this.cache).close(); diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImplTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImplTest.java new file mode 100644 index 000000000..5a354cfb8 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImplTest.java @@ -0,0 +1,114 @@ +// Copyright © Amazon Web Services +// +// 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.indexer.aws.cache; + +import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.mockito.MockedConstruction; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +@RunWith(MockitoJUnitRunner.class) +public class IndexCacheImplTest { + + + private final String s = "s"; + private final boolean o = true; + private final String password = "password"; + private final String endpoint = "CACHE_CLUSTER_ENDPOINT"; + private final String port = "6369"; + + @Test + public void local_VmCache_test() throws Exception{ + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(true); + })) { + IndexCacheImpl cacheImpl = new IndexCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + assertNull(cacheImpl.get(s)); + cacheImpl.clearAll(); + cacheImpl.close(); + } + } + + @Test + public void non_local_Null_Credential_RedisCache_test() throws Exception{ + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(false); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_ENDPOINT"), any())).thenReturn(endpoint); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_PORT"), any())).thenReturn(port); + when(mockProvider.getCredentialsAsMap(eq("CACHE_CLUSTER_KEY"))).thenReturn(null); + })) { + try (MockedConstruction<RedisCache> cache = Mockito.mockConstruction(RedisCache.class, (mockCache, context) -> { + doNothing().when(mockCache).put(s,o); + when(mockCache.get(s)).thenReturn(o); + doNothing().when(mockCache).delete(s); + doNothing().when(mockCache).clearAll(); + doNothing().when(mockCache).close(); + })) { + IndexCacheImpl cacheImpl = new IndexCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + cacheImpl.clearAll(); + cacheImpl.close(); + } + } + } + + @Test + public void non_Local_notNull_Credential_RedisCache_test() throws Exception{ + + Map<String, String> map = new HashMap<String, String>(); + map.put("token", password); + + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(false); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_ENDPOINT"), any())).thenReturn(endpoint); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_PORT"), any())).thenReturn(port); + when(mockProvider.getCredentialsAsMap(eq("CACHE_CLUSTER_KEY"))).thenReturn(map); + })) { + try (MockedConstruction<RedisCache> cache = Mockito.mockConstruction(RedisCache.class, (mockCache, context) -> { + doNothing().when(mockCache).put(s,o); + when(mockCache.get(s)).thenReturn(o); + doNothing().when(mockCache).delete(s); + doNothing().when(mockCache).clearAll(); + doNothing().when(mockCache).close(); + })) { + IndexCacheImpl cacheImpl = new IndexCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + cacheImpl.clearAll(); + cacheImpl.close(); + } + } + } + +} diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImplTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImplTest.java new file mode 100644 index 000000000..61e3e73c7 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImplTest.java @@ -0,0 +1,115 @@ +// Copyright © Amazon Web Services +// +// 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.indexer.aws.cache; + +import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.mockito.MockedConstruction; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +@RunWith(MockitoJUnitRunner.class) +public class SchemaCacheImplTest { + + + private final String s = "s"; + private final String o = "o"; + private final String password = "password"; + private final String endpoint = "CACHE_CLUSTER_ENDPOINT"; + private final String port = "6369"; + + + @Test + public void local_VmCache_test() throws Exception{ + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(true); + })) { + SchemaCacheImpl cacheImpl = new SchemaCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + assertNull(cacheImpl.get(s)); + cacheImpl.clearAll(); + cacheImpl.close(); + } + } + + @Test + public void non_local_Null_Credential_RedisCache_test() throws Exception{ + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(false); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_ENDPOINT"), any())).thenReturn(endpoint); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_PORT"), any())).thenReturn(port); + when(mockProvider.getCredentialsAsMap(eq("CACHE_CLUSTER_KEY"))).thenReturn(null); + })) { + try (MockedConstruction<RedisCache> cache = Mockito.mockConstruction(RedisCache.class, (mockCache, context) -> { + doNothing().when(mockCache).put(s,o); + when(mockCache.get(s)).thenReturn(o); + doNothing().when(mockCache).delete(s); + doNothing().when(mockCache).clearAll(); + doNothing().when(mockCache).close(); + })) { + SchemaCacheImpl cacheImpl = new SchemaCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + cacheImpl.clearAll(); + cacheImpl.close(); + } + } + } + + @Test + public void non_Local_notNull_Credential_RedisCache_test() throws Exception{ + + Map<String, String> map = new HashMap<String, String>(); + map.put("token", password); + + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(false); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_ENDPOINT"), any())).thenReturn(endpoint); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_PORT"), any())).thenReturn(port); + when(mockProvider.getCredentialsAsMap(eq("CACHE_CLUSTER_KEY"))).thenReturn(map); + })) { + try (MockedConstruction<RedisCache> cache = Mockito.mockConstruction(RedisCache.class, (mockCache, context) -> { + doNothing().when(mockCache).put(s,o); + when(mockCache.get(s)).thenReturn(o); + doNothing().when(mockCache).delete(s); + doNothing().when(mockCache).clearAll(); + doNothing().when(mockCache).close(); + })) { + SchemaCacheImpl cacheImpl = new SchemaCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + cacheImpl.clearAll(); + cacheImpl.close(); + } + } + } + +} diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/persistence/ElasticRepositoryImplTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/persistence/ElasticRepositoryImplTest.java new file mode 100644 index 000000000..c89cbb150 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/persistence/ElasticRepositoryImplTest.java @@ -0,0 +1,81 @@ +// Copyright © Amazon Web Services +// +// 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.indexer.aws.persistence; + + +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockedConstruction; +import org.mockito.Mockito; +import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +@RunWith(SpringJUnit4ClassRunner.class) +public class ElasticRepositoryImplTest { + + private final String s = "s"; + private final String o = "o"; + private final String username = "username"; + private final String password = "password"; + private final String host = "host"; + private final String port = "6369"; + + + @Test + public void getElasticClusterSettings_Null_User_Test() { + + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(false); + when(mockProvider.getParameterAsStringOrDefault(eq("ELASTICSEARCH_HOST"), any())).thenReturn(host); + when(mockProvider.getParameterAsStringOrDefault(eq("ELASTICSEARCH_PORT"), any())).thenReturn(port); + when(mockProvider.getCredentialsAsMap(eq("ELASTICSEARCH_CREDENTIALS"))).thenReturn(null); + })) { + ElasticRepositoryImpl elasticImpl = new ElasticRepositoryImpl(); + + assertNotNull(elasticImpl.getElasticClusterSettings(new TenantInfo())); + + } + + } + @Test + public void getElasticClusterSettings_not_Null_User_Test() { + + Map<String, String> map = new HashMap<String, String>(); + map.put("username", username); + map.put("password", password); + + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(false); + when(mockProvider.getParameterAsStringOrDefault(eq("ELASTICSEARCH_HOST"), any())).thenReturn(host); + when(mockProvider.getParameterAsStringOrDefault(eq("ELASTICSEARCH_PORT"), any())).thenReturn(port); + when(mockProvider.getCredentialsAsMap(eq("ELASTICSEARCH_CREDENTIALS"))).thenReturn(map); + })) { + ElasticRepositoryImpl elasticImpl = new ElasticRepositoryImpl(); + elasticImpl.isHttps = true; + assertNotNull(elasticImpl.getElasticClusterSettings(new TenantInfo())); + + } + + } +} diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManagerTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManagerTest.java new file mode 100644 index 000000000..865fc17d0 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManagerTest.java @@ -0,0 +1,194 @@ +// Copyright © Amazon Web Services +// +// 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.indexer.aws.service; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.X509Certificate; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.opengroup.osdu.indexer.aws.IndexerAwsApplication; +import java.net.Socket; + +@RunWith(MockitoJUnitRunner.class) +@SpringBootTest(classes = {IndexerAwsApplication.class}) +public class UnsafeX509ExtendedTrustManagerTest { + + + @Test + public void createClientBuilder() throws Exception { + + X509Certificate[] certificates = new X509Certificate[1]; + + certificates[0] = new Certificate(); + + UnsafeX509ExtendedTrustManager manager = UnsafeX509ExtendedTrustManager.INSTANCE; + + manager.checkClientTrusted(certificates, "auth"); + manager.checkClientTrusted(certificates, "auth", new Socket()); + manager.checkServerTrusted(certificates, "auth"); + manager.checkServerTrusted(certificates, "auth", new Socket()); + + } + +} + +class Certificate extends X509Certificate{ + + @Override + public boolean hasUnsupportedCriticalExtension() { + return true; + } + + @Override + public Set<String> getCriticalExtensionOIDs() { + return new HashSet<String>(); + } + + @Override + public Set<String> getNonCriticalExtensionOIDs() { + return new HashSet<String>(); + } + + @Override + public byte[] getExtensionValue(String oid) { + return new byte[0]; + } + + @Override + public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException { + } + + @Override + public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException { + } + + @Override + public int getVersion() { + return 0; + } + + @Override + public BigInteger getSerialNumber() { + return new BigInteger("0"); + } + + @Override + public Principal getIssuerDN() { + return null; + } + + @Override + public Principal getSubjectDN() { + return null; + } + + @Override + public Date getNotBefore() { + return null; + } + + @Override + public Date getNotAfter() { + return null; + } + + @Override + public byte[] getTBSCertificate() throws CertificateEncodingException { + return null; + } + + @Override + public byte[] getSignature() { + return null; + } + + @Override + public String getSigAlgName() { + return ""; + } + + @Override + public String getSigAlgOID() { + return ""; + } + + @Override + public byte[] getSigAlgParams() { + return null; + } + + @Override + public boolean[] getIssuerUniqueID() { + return null; + } + + @Override + public boolean[] getSubjectUniqueID() { + return null; + } + + @Override + public boolean[] getKeyUsage() { + return null; + } + + @Override + public int getBasicConstraints() { + return 0; + } + + @Override + public byte[] getEncoded() throws CertificateEncodingException { + return null; + } + + @Override + public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + } + + @Override + public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, SignatureException { + } + + @Override + public String toString() { + return ""; + } + + @Override + public PublicKey getPublicKey() { + return null; + } + +} \ No newline at end of file diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthTokenTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthTokenTest.java index 3dcafab9d..cc60dfc77 100644 --- a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthTokenTest.java +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthTokenTest.java @@ -21,7 +21,6 @@ import org.mockito.Mockito; import org.opengroup.osdu.core.common.http.HttpClient; import org.opengroup.osdu.core.common.http.HttpRequest; import org.opengroup.osdu.core.common.http.HttpResponse; -import org.springframework.stereotype.Component; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -- GitLab