diff --git a/NOTICE b/NOTICE index aa6f4d168da4fd1d3dacddcae517b0bcaac426ad..4ec97306e711fa2d8869080194534ab775f3d830 100644 --- a/NOTICE +++ b/NOTICE @@ -335,8 +335,10 @@ The following software have components provided under the terms of this license: - Apache Groovy (from http://groovy-lang.org, http://groovy.codehaus.org/, https://groovy-lang.org) - Apache HTTP transport v2 for the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-apache-v2) - Apache HttpAsyncClient (from http://hc.apache.org/httpcomponents-asyncclient) -- Apache HttpClient (from http://hc.apache.org/httpcomponents-client, http://hc.apache.org/httpcomponents-client-ga) +- Apache HttpClient (from http://hc.apache.org/httpcomponents-client, http://hc.apache.org/httpcomponents-client-ga, https://repo1.maven.org/maven2/org/apache/httpcomponents/client5/httpclient5) - Apache HttpClient Cache (from http://hc.apache.org/httpcomponents-client, http://hc.apache.org/httpcomponents-client-ga) +- Apache HttpComponents Core HTTP/1.1 (from https://repo1.maven.org/maven2/org/apache/httpcomponents/core5/httpcore5) +- Apache HttpComponents Core HTTP/2 (from https://repo1.maven.org/maven2/org/apache/httpcomponents/core5/httpcore5-h2) - Apache HttpCore (from http://hc.apache.org/httpcomponents-core-ga, http://hc.apache.org/httpcomponents-core-ga/, http://hc.apache.org/httpcomponents-core/) - Apache HttpCore NIO (from http://hc.apache.org/httpcomponents-core-ga, http://hc.apache.org/httpcomponents-core/) - Apache Log4j API (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api) @@ -499,7 +501,7 @@ The following software have components provided under the terms of this license: - Microsoft Azure Java Core Library (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure Netty HTTP Client Library (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure SDK for SQL API of Azure Cosmos DB Service (from https://github.com/Azure/azure-sdk-for-java) -- Mockito (from http://mockito.org, http://www.mockito.org, https://github.com/mockito/mockito) +- Mockito (from http://mockito.org, https://github.com/mockito/mockito) - Mojo's Maven plugin for Cobertura (from http://mojo.codehaus.org/cobertura-maven-plugin/) - MongoDB Driver (from https://www.mongodb.com/) - MongoDB Java Driver (from http://mongodb.org/, http://www.mongodb.org, https://www.mongodb.com/) @@ -757,7 +759,6 @@ The following software have components provided under the terms of this license: - Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java) -- Mockito (from http://mockito.org, http://www.mockito.org, https://github.com/mockito/mockito) - Netty/Codec/HTTP (from https://repo1.maven.org/maven2/io/netty/netty-codec-http) - Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils, https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils) - Protocol Buffer Java API (from http://code.google.com/p/protobuf, https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java) @@ -1168,7 +1169,7 @@ The following software have components provided under the terms of this license: - Microsoft Azure client library for KeyVault Secrets (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure common module for Storage (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure internal Avro module for Storage (from https://github.com/Azure/azure-sdk-for-java) -- Mockito (from http://mockito.org, http://www.mockito.org, https://github.com/mockito/mockito) +- Mockito (from http://mockito.org, https://github.com/mockito/mockito) - MongoDB Java Driver (from http://mongodb.org/, http://www.mongodb.org, https://www.mongodb.com/) - Netty/Codec/HTTP (from https://repo1.maven.org/maven2/io/netty/netty-codec-http) - Netty/Common (from https://repo1.maven.org/maven2/io/netty/netty-common) @@ -1193,6 +1194,7 @@ The following software have components provided under the terms of this license: - jersey-media-json-jackson (from https://repo1.maven.org/maven2/org/glassfish/jersey/media/jersey-media-json-jackson) - jersey-spring5 (from https://repo1.maven.org/maven2/org/glassfish/jersey/ext/jersey-spring5) - micrometer-core (from https://github.com/micrometer-metrics/micrometer) +- mockito-inline (from http://mockito.org, https://github.com/mockito/mockito) - mockito-junit-jupiter (from https://github.com/mockito/mockito) - msal4j (from https://github.com/AzureAD/microsoft-authentication-library-for-java) - msal4j-persistence-extension (from https://github.com/AzureAD/microsoft-authentication-extensions-for-java) diff --git a/provider/indexer-aws/lombok.config b/provider/indexer-aws/lombok.config new file mode 100644 index 0000000000000000000000000000000000000000..a23edb413fc5d2e329b180ce25ef307f0c408874 --- /dev/null +++ b/provider/indexer-aws/lombok.config @@ -0,0 +1,2 @@ +config.stopBubbling = true +lombok.addLombokGeneratedAnnotation = true \ No newline at end of file diff --git a/provider/indexer-aws/pom.xml b/provider/indexer-aws/pom.xml index 2937c1a34849c70ec8a7dfb21f837e344bb7a4b7..f7d666c9e239fa3b3138afbbf9e3f70da264c45f 100644 --- a/provider/indexer-aws/pom.xml +++ b/provider/indexer-aws/pom.xml @@ -35,6 +35,7 @@ <jackson-databind.version>2.13.2.2</jackson-databind.version> <jackson.version>2.13.2</jackson.version> <spring-webmvc.version>5.3.22</spring-webmvc.version> + <mockito.version>3.11.2</mockito.version> </properties> <dependencyManagement> @@ -71,7 +72,7 @@ <dependency> <groupId>org.opengroup.osdu.core.aws</groupId> <artifactId>os-core-lib-aws</artifactId> - <version>0.21.0</version> + <version>0.24.0-SNAPSHOT</version> </dependency> <!-- AWS managed packages --> @@ -160,16 +161,36 @@ <version>4.13.2</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <version>1.10.19</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </exclusion> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>${mockito.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-inline</artifactId> + <version>4.2.0</version> + <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> @@ -208,6 +229,7 @@ <argLine> @{argLine} --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/javax.net.ssl=ALL-UNNAMED </argLine> </configuration> </plugin> diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImpl.java index 63b65bac319cfb8ae9f93bb3bd73d1646a2c087f..8ba83cfc4cc242bf9eab18333e7e8ca62683f21a 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImpl.java @@ -18,11 +18,11 @@ import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCac import org.springframework.stereotype.Component; @Component -public class ElasticCredentialsCacheImpl implements IElasticCredentialsCache { +public class ElasticCredentialsCacheImpl implements IElasticCredentialsCache<Object, Object> { @Override public void put(Object o, Object o2) { - + //Do nothing currently } @Override @@ -32,11 +32,11 @@ public class ElasticCredentialsCacheImpl implements IElasticCredentialsCache { @Override public void delete(Object o) { - + //Do nothing currently } @Override public void clearAll() { - + //Do nothing currently } } 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 fc33e78a6275a8a4ef707b586021e8be9b86a40e..f6684e1333911da0195b97273129a18e9ae5ce6b 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 @@ -33,45 +33,42 @@ public class IndexCacheImpl implements IIndexCache<String, Boolean>, AutoCloseab private ICache<String, Boolean> cache; private Boolean local; @Value("${aws.elasticache.cluster.endpoint}") - String REDIS_SEARCH_HOST; + String redisSearchHost; @Value("${aws.elasticache.cluster.port}") - String REDIS_SEARCH_PORT; + String redisSearchPort; @Value("${aws.elasticache.cluster.key}") - String REDIS_SEARCH_KEY; + String redisSearchKey; @Value("${aws.elasticache.cluster.index.expiration}") - String INDEX_CACHE_EXPIRATION; + String indexCacheExpiration; public IndexCacheImpl() throws K8sParameterNotFoundException, JsonProcessingException { int expTimeSeconds = 60 * 60; K8sLocalParameterProvider provider = new K8sLocalParameterProvider(); - if (provider.getLocalMode()){ + local = provider.getLocalMode(); + if (local.booleanValue()){ if (Boolean.parseBoolean(System.getenv("DISABLE_CACHE"))){ cache = new DummyCache<>(); }else{ - cache = new VmCache<String,Boolean>(expTimeSeconds, 10); + cache = new VmCache<>(expTimeSeconds, 10); } }else { - String host = provider.getParameterAsStringOrDefault("CACHE_CLUSTER_ENDPOINT", REDIS_SEARCH_HOST); - int port = Integer.parseInt(provider.getParameterAsStringOrDefault("CACHE_CLUSTER_PORT", REDIS_SEARCH_PORT)); + String host = provider.getParameterAsStringOrDefault("CACHE_CLUSTER_ENDPOINT", redisSearchHost); + int port = Integer.parseInt(provider.getParameterAsStringOrDefault("CACHE_CLUSTER_PORT", redisSearchPort)); Map<String, String > credential =provider.getCredentialsAsMap("CACHE_CLUSTER_KEY"); String password; if (credential !=null){ password = credential.get("token"); }else{ - password = REDIS_SEARCH_KEY; + password = redisSearchKey; } - cache = new RedisCache<String, Boolean>(host, port, password, expTimeSeconds, String.class,Boolean.class); + cache = new RedisCache<>(host, port, password, expTimeSeconds, String.class,Boolean.class); } - local = cache instanceof AutoCloseable; } @Override public void close() throws Exception { - if (local){ - - }else{ + if (!local.booleanValue()){ ((AutoCloseable)this.cache).close(); } - } @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 27a1f3792a25a47a331117a85e52f55a62510efd..040407bf39f1ea8fd87e1556e96b12c2cf80a45d 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 @@ -30,43 +30,43 @@ import java.util.Map; @Component public class SchemaCacheImpl implements ISchemaCache<String, String>, AutoCloseable { @Value("${aws.elasticache.cluster.endpoint}") - String REDIS_SEARCH_HOST; + String redisSearchHost; @Value("${aws.elasticache.cluster.port}") - String REDIS_SEARCH_PORT; + String redisSearchPort; @Value("${aws.elasticache.cluster.key}") - String REDIS_SEARCH_KEY; + String redisSearchKey; @Value("${aws.elasticache.cluster.schema.expiration}") - String SCHEMA_CACHE_EXPIRATION; + String schemaCacheExpiration; private ICache<String, String> cache; private Boolean local = false; public SchemaCacheImpl() throws K8sParameterNotFoundException, JsonProcessingException { int expTimeSeconds = 60 * 60; K8sLocalParameterProvider provider = new K8sLocalParameterProvider(); - if (provider.getLocalMode()){ + local = provider.getLocalMode(); + if (local.booleanValue()){ if (Boolean.parseBoolean(System.getenv("DISABLE_CACHE"))){ cache = new DummyCache<>(); }else{ - cache = new VmCache<String,String>(expTimeSeconds, 10); + cache = new VmCache<>(expTimeSeconds, 10); } }else { - String host = provider.getParameterAsStringOrDefault("CACHE_CLUSTER_ENDPOINT", REDIS_SEARCH_HOST); - int port = Integer.parseInt(provider.getParameterAsStringOrDefault("CACHE_CLUSTER_PORT", REDIS_SEARCH_PORT)); + String host = provider.getParameterAsStringOrDefault("CACHE_CLUSTER_ENDPOINT", redisSearchHost); + int port = Integer.parseInt(provider.getParameterAsStringOrDefault("CACHE_CLUSTER_PORT", redisSearchPort)); Map<String, String > credential =provider.getCredentialsAsMap("CACHE_CLUSTER_KEY"); String password; if (credential !=null){ password = credential.get("token"); }else{ - password = REDIS_SEARCH_KEY; + password = redisSearchKey; } 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 + if (this.local.booleanValue()){ + // 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/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactory.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactory.java index dd7cbd1efa355aebf59aab8b148371afa29f8569..1c092c71ef6d5c1d3540a9f5a908086f7c3b3a81 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactory.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactory.java @@ -32,10 +32,10 @@ import org.springframework.web.context.annotation.RequestScope; public class EntitlementsClientFactory extends AbstractFactoryBean<IEntitlementsFactory> { @Value("${AUTHORIZE_API}") - private String AUTHORIZE_API; + private String authorizeApi; @Value("${AUTHORIZE_API_KEY:}") - private String AUTHORIZE_API_KEY; + private String authorizeApiKey; @Autowired private HttpResponseBodyMapper mapper; @@ -45,8 +45,8 @@ public class EntitlementsClientFactory extends AbstractFactoryBean<IEntitlements return new EntitlementsFactory(EntitlementsAPIConfig .builder() - .rootUrl(AUTHORIZE_API) - .apiKey(AUTHORIZE_API_KEY) + .rootUrl(authorizeApiKey) + .apiKey(authorizeApiKey) .build(), mapper); } diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/publish/PublisherImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/publish/PublisherImpl.java index fb81abbbbb8100094869e1d442b91d3bb6533ae5..c19b22b1718fc4eb262d748a084338ec6a20e58c 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/publish/PublisherImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/publish/PublisherImpl.java @@ -14,7 +14,6 @@ package org.opengroup.osdu.indexer.aws.publish; -import com.amazonaws.services.sns.model.MessageAttributeValue; import com.amazonaws.services.sns.model.PublishRequest; import com.amazonaws.services.sns.AmazonSNS; @@ -22,14 +21,13 @@ import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig; import org.opengroup.osdu.core.aws.sns.PublishRequestBuilder; +import org.opengroup.osdu.core.common.model.indexer.RecordStatus; import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; import org.opengroup.osdu.core.common.model.indexer.JobStatus; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; import javax.inject.Inject; -import java.util.HashMap; -import java.util.Map; @Component public class PublisherImpl implements IPublisher { @@ -40,6 +38,9 @@ public class PublisherImpl implements IPublisher { @Value("${aws.region}") private String amazonSNSRegion; + @Value("${OSDU_TOPIC}") + private String osduIndexerTopic; + @Inject public void init() throws K8sParameterNotFoundException { AmazonSNSConfig snsConfig = new AmazonSNSConfig(amazonSNSRegion); @@ -50,20 +51,10 @@ public class PublisherImpl implements IPublisher { public void publishStatusChangedTagsToTopic(DpsHeaders headers, JobStatus indexerBatchStatus) throws Exception { - // Attributes - Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); - messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() - .withDataType("String") - .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); - messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() - .withDataType("String") - .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); - headers.addCorrelationIdIfMissing(); - messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() - .withDataType("String") - .withStringValue(headers.getCorrelationId())); + PublishRequestBuilder<RecordStatus> publishRequestBuilder = new PublishRequestBuilder<>(); + publishRequestBuilder.setGeneralParametersFromHeaders(headers); - PublishRequest publishRequest = new PublishRequestBuilder().generatePublishRequest("data", indexerBatchStatus.getStatusesList(), messageAttributes, amazonSNSTopic); + PublishRequest publishRequest = publishRequestBuilder.generatePublishRequest(osduIndexerTopic, amazonSNSTopic, indexerBatchStatus.getStatusesList()); snsClient.publish(publishRequest); } diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/security/BasicAuthSecurityConfig.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/security/BasicAuthSecurityConfig.java index 6585ebc959b9fb878de01658d042c53bae1271e6..652f06f5d1bd8866c1d8ac14a465d17429efbc53 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/security/BasicAuthSecurityConfig.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/security/BasicAuthSecurityConfig.java @@ -14,17 +14,21 @@ package org.opengroup.osdu.indexer.aws.security; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.SecurityFilterChain; @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) -public class BasicAuthSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { +@Configuration +public class BasicAuthSecurityConfig { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.httpBasic().disable() .csrf().disable(); //disable default authN. AuthN handled by endpoints proxy + return http.build(); } } diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAws.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAws.java index 52943cebc267e8c03ffd6ab68e89948d28027c09..98c524854e644f678795cae59e08972d3420294d 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAws.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAws.java @@ -44,13 +44,13 @@ public class ElasticClientHandlerAws extends ElasticClientHandler { private static final int REST_CLIENT_CONNECT_TIMEOUT = 60000; private static final int REST_CLIENT_SOCKET_TIMEOUT = 60000; - private static final int REST_CLIENT_RETRY_TIMEOUT = 60000; @Value("${aws.es.certificate.disableTrust:false}") // @Value("#{new Boolean('${aws.es.certificate.disableTrust:false}')}") private Boolean disableSslCertificateTrust; public ElasticClientHandlerAws() { + //DO nothing here, just a class constructor } @Override @@ -61,7 +61,7 @@ public class ElasticClientHandlerAws extends ElasticClientHandler { .setConnectTimeout(REST_CLIENT_CONNECT_TIMEOUT) .setSocketTimeout(REST_CLIENT_SOCKET_TIMEOUT)); - if(isLocalHost(host) || disableSslCertificateTrust) { + if(isLocalHost(host) || disableSslCertificateTrust.booleanValue()) { SSLContext sslContext; try { diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManager.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManager.java index c2a9af091ababbe359394cc1256eeb3071f2bfae..8d3a104fea2251ca6968ab367bc66a2823f2f6fd 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManager.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManager.java @@ -34,42 +34,42 @@ class UnsafeX509ExtendedTrustManager extends X509ExtendedTrustManager { @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String authType) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug(CLIENT_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectDN()); + LOGGER.debug(CLIENT_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectX500Principal()); } } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String authType, Socket socket) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug(CLIENT_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectDN()); + LOGGER.debug(CLIENT_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectX500Principal()); } } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String authType, SSLEngine sslEngine) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug(CLIENT_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectDN()); + LOGGER.debug(CLIENT_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectX500Principal()); } } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String authType) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug(SERVER_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectDN()); + LOGGER.debug(SERVER_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectX500Principal()); } } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String authType, Socket socket) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug(SERVER_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectDN()); + LOGGER.debug(SERVER_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectX500Principal()); } } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String authType, SSLEngine sslEngine) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug(SERVER_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectDN()); + LOGGER.debug(SERVER_CERTIFICATE_LOG_MESSAGE, x509Certificates[0].getSubjectX500Principal()); } } diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthToken.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthToken.java index f562dd260aa0eab16bc24dfc3902d2363af82a65..a3406802bc0d1103e418ac32e06a482aef636c40 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthToken.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthToken.java @@ -34,8 +34,8 @@ import java.util.Map; @Component public class AwsServiceAccountAuthToken { - private String client_credentials_secret; - private String client_credentials_clientid; + private String clientCredentialsSecret; + private String clientCredentialsClientId; private String tokenUrl; private String oauthCustomScope; private String token= null; @@ -45,8 +45,8 @@ public class AwsServiceAccountAuthToken { private void init() { K8sLocalParameterProvider provider = new K8sLocalParameterProvider(); try { - this.client_credentials_clientid = provider.getParameterAsString("CLIENT_CREDENTIALS_ID"); - this.client_credentials_secret = provider.getCredentialsAsMap("CLIENT_CREDENTIALS_SECRET").get("client_credentials_client_secret"); + this.clientCredentialsClientId = provider.getParameterAsString("CLIENT_CREDENTIALS_ID"); + this.clientCredentialsSecret = provider.getCredentialsAsMap("CLIENT_CREDENTIALS_SECRET").get("client_credentials_client_secret"); this.tokenUrl = provider.getParameterAsString("OAUTH_TOKEN_URI"); this.oauthCustomScope = provider.getParameterAsString("OAUTH_CUSTOM_SCOPE"); } catch (K8sParameterNotFoundException | JsonProcessingException e) { @@ -57,8 +57,8 @@ public class AwsServiceAccountAuthToken { public String getAuthToken() throws AppException { if (expiredToken()){ Map<String,String> headers = new HashMap<>(); - String authorizationHeaderContents=getEncodedAuthorization(this.client_credentials_clientid,this.client_credentials_secret); - headers.put("Authorization","Basic "+authorizationHeaderContents); + String authorizationHeaderContents=getEncodedAuthorization(this.clientCredentialsClientId, this.clientCredentialsSecret); + headers.put("Authorization","Basic "+ authorizationHeaderContents); headers.put("Content-Type", "application/x-www-form-urlencoded"); IHttpClient httpClient = new HttpClient(); diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAws.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAws.java index 3f96435d7bcff6ad54ecdd27d0eb11c826b080cb..de86fa2584a0e9f6581455528d2c383854788b81 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAws.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAws.java @@ -37,6 +37,8 @@ import java.util.Map; @Component public class IndexerQueueTaskBuilderAws extends IndexerQueueTaskBuilder { + private static final String TYPE_STRING = "String"; + private static final String RETRY_STRING = "retry"; private static final int INITIAL_RETRY_DELAY_SECONDS = 5; private static final int MAX_RETRY_DELAY_SECONDS = 900; // 15 minutes (900 seconds) is the hard limit SQS sets of message delays @@ -44,7 +46,6 @@ public class IndexerQueueTaskBuilderAws extends IndexerQueueTaskBuilder { private String storageQueue; private String dlq; - private final String retryString = "retry"; private Gson gson; @@ -74,23 +75,23 @@ public class IndexerQueueTaskBuilderAws extends IndexerQueueTaskBuilder { public void createReIndexTask(String payload,DpsHeaders headers) { Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); headers.addCorrelationIdIfMissing(); messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getCorrelationId())); messageAttributes.put(DpsHeaders.USER_EMAIL, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getUserEmail())); messageAttributes.put(DpsHeaders.AUTHORIZATION, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getAuthorization())); messageAttributes.put("ReIndexCursor", new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue("True")); SendMessageRequest sendMessageRequest = new SendMessageRequest() .withQueueUrl(storageQueue) @@ -106,28 +107,28 @@ public class IndexerQueueTaskBuilderAws extends IndexerQueueTaskBuilder { private void createTask(String payload, DpsHeaders headers) { Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); headers.addCorrelationIdIfMissing(); messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getCorrelationId())); messageAttributes.put(DpsHeaders.USER_EMAIL, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getUserEmail())); messageAttributes.put(DpsHeaders.AUTHORIZATION, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(headers.getAuthorization())); RecordChangedMessages message = gson.fromJson(payload, RecordChangedMessages.class); int retryCount; int retryDelay; - if (message.getAttributes().containsKey(retryString)) { - retryCount = Integer.parseInt(message.getAttributes().get(retryString)); + if (message.getAttributes().containsKey(RETRY_STRING)) { + retryCount = Integer.parseInt(message.getAttributes().get(RETRY_STRING)); retryCount++; retryDelay = Math.min(getWaitTimeExp(retryCount), MAX_RETRY_DELAY_SECONDS); } else { @@ -140,14 +141,14 @@ public class IndexerQueueTaskBuilderAws extends IndexerQueueTaskBuilder { System.out.println("Delay (in seconds) before next retry: " + retryDelay); // Append the retry count to the message attributes - messageAttributes.put(retryString, new MessageAttributeValue() - .withDataType("String") + messageAttributes.put(RETRY_STRING, new MessageAttributeValue() + .withDataType(TYPE_STRING) .withStringValue(String.valueOf(retryCount)) ); // Append the ancestry kinds used to prevent circular chasing if(message.getAttributes().containsKey(Constants.ANCESTRY_KINDS)) { messageAttributes.put(Constants.ANCESTRY_KINDS, new MessageAttributeValue() - .withDataType("String") + .withDataType(TYPE_STRING) .withStringValue(message.getAttributes().get(Constants.ANCESTRY_KINDS))); } @@ -158,7 +159,7 @@ public class IndexerQueueTaskBuilderAws extends IndexerQueueTaskBuilder { sendMessageRequest = new SendMessageRequest() .withQueueUrl(storageQueue) .withMessageBody(message.getData()) - .withDelaySeconds(new Integer(retryDelay)) + .withDelaySeconds(Integer.valueOf(retryDelay)) .withMessageAttributes(messageAttributes); }else{ sendMessageRequest = new SendMessageRequest() diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImpl.java index d352c5a7c03dd8864a5d6a18bfa5e782a6b4856e..c756f8c536dd0e8227e2c84653ad438eccdb5422 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImpl.java @@ -56,8 +56,7 @@ public class RequestInfoImpl implements IRequestInfo { // throw to prevent null reference exception below throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid Headers", "Headers Map DpsHeaders is null"); } - DpsHeaders headers = this.getCoreServiceHeaders(headersMap.getHeaders()); - return headers; + return this.getCoreServiceHeaders(headersMap.getHeaders()); } /** @@ -94,9 +93,7 @@ public class RequestInfoImpl implements IRequestInfo { private DpsHeaders getCoreServiceHeaders(Map<String, String> input) { Preconditions.checkNotNull(input, "input headers cannot be null"); - DpsHeaders output = DpsHeaders.createFromMap(input); - - return output; + return DpsHeaders.createFromMap(input); } @Override diff --git a/provider/indexer-aws/src/main/resources/application.properties b/provider/indexer-aws/src/main/resources/application.properties index a0d1a419f6a6aa71128963495390ae748e7e9649..677c2536cde4d22eabf9794270c092ede9f7697d 100644 --- a/provider/indexer-aws/src/main/resources/application.properties +++ b/provider/indexer-aws/src/main/resources/application.properties @@ -35,6 +35,9 @@ STORAGE_QUERY_KINDS_HOST=${STORAGE_BASE_URL}/api/storage/v2/query/kinds STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=${STORAGE_BASE_URL}/api/storage/v2/query/records:batch STORAGE_RECORDS_BATCH_SIZE=20 INDEXER_QUEUE_HOST="" + +OSDU_TOPIC=${OSDU_INDEXER_TOPIC:indexer-status-changed} + ## AWS ElastiCache configuration aws.elasticache.cluster.endpoint=${CACHE_CLUSTER_ENDPOINT:null} aws.elasticache.cluster.port=${CACHE_CLUSTER_PORT:null} diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImplTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9ccb038e6626b3a3e3375faafd629f0f7ad55cb9 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImplTest.java @@ -0,0 +1,32 @@ +// 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.junit.Test; +import org.junit.Assert; +import org.springframework.boot.test.context.SpringBootTest; +import org.opengroup.osdu.indexer.aws.IndexerAwsApplication; + +@SpringBootTest(classes = {IndexerAwsApplication.class}) +public class ElasticCredentialsCacheImplTest { + + private ElasticCredentialsCacheImpl cache = new ElasticCredentialsCacheImpl(); + + @Test + public void get_should_return_null() throws Exception { + Assert.assertNull(cache.get(new Object())); + } + +} 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 0000000000000000000000000000000000000000..5a354cfb802ec11fed8cdf70599d9650212330f7 --- /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 0000000000000000000000000000000000000000..61e3e73c7a02da8978db9663598ffd8ed3a6eed5 --- /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/di/EntitlementsClientFactoryTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactoryTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b42e362843f835731cd9ac47359c8c16f7bbf3c6 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactoryTest.java @@ -0,0 +1,48 @@ +// 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.di; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; +import org.opengroup.osdu.core.common.http.json.HttpResponseBodyMapper; +import static org.junit.jupiter.api.Assertions.*; + +@RunWith(MockitoJUnitRunner.class) +public class EntitlementsClientFactoryTest { + + @InjectMocks + private EntitlementsClientFactory factory; + + @Mock + private HttpResponseBodyMapper mapper; + + @Test + public void createInstance_shouldReturn_notNull_EntitlementFactory() throws Exception{ + IEntitlementsFactory entitlementFactory = factory.createInstance(); + assertNotNull(entitlementFactory); + } + + @Test + public void getObjectType_shouldReturn_IEntitlementFactoryClass() { + Class<?> responseClass = factory.getObjectType(); + assertEquals(responseClass, IEntitlementsFactory.class); + } +} diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/di/TenantInfoServiceTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/di/TenantInfoServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f5c251ec6ffa4d4852ebcfe295da9ce909737593 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/di/TenantInfoServiceTest.java @@ -0,0 +1,58 @@ +// 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.di; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; +import java.util.ArrayList; +import java.util.List; +import static org.junit.jupiter.api.Assertions.*; + +@RunWith(MockitoJUnitRunner.class) +public class TenantInfoServiceTest { + + @Mock + private ITenantFactory tenantFactory; + + @Mock + private DpsHeaders headers; + + @InjectMocks + TenantInfoService service; + + @Test + public void shouldReturnSetValue_when_getTenantInfo_isCalled() { + TenantInfo expectedTenantInfo = new TenantInfo(); + Mockito.when(headers.getPartitionId()).thenReturn("opendes"); + Mockito.when(tenantFactory.getTenantInfo("opendes")).thenReturn(expectedTenantInfo); + TenantInfo tenantInfo = service.getTenantInfo(); + assertEquals(expectedTenantInfo, tenantInfo); + } + + @Test + public void shouldReturnSetList_when_getAllTenantInfos_isCalled() { + List<TenantInfo> expectedTenantInfoArrayList = new ArrayList<>(); + Mockito.when(tenantFactory.listTenantInfo()).thenReturn(expectedTenantInfoArrayList); + List<TenantInfo> tenantInfoArrayList = service.getAllTenantInfos(); + assertEquals(expectedTenantInfoArrayList, tenantInfoArrayList); + } +} 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 0000000000000000000000000000000000000000..c89cbb150983ce5bae6c5aec96344c766df24644 --- /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/publish/PublisherImplTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/publish/PublisherImplTest.java index 79ef1356aa94e2462eeb189578589a7bfbbfd69b..6a85fb6215f2635e49b33c39fcb76dbd59f48a25 100644 --- a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/publish/PublisherImplTest.java +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/publish/PublisherImplTest.java @@ -18,37 +18,42 @@ import com.amazonaws.services.sns.AmazonSNS; import com.amazonaws.services.sns.model.MessageAttributeValue; import com.amazonaws.services.sns.model.PublishRequest; import com.amazonaws.services.sns.model.PublishResult; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.MockedConstruction; import org.mockito.Mockito; import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig; import org.opengroup.osdu.core.aws.sns.PublishRequestBuilder; +import org.opengroup.osdu.core.common.model.indexer.RecordStatus; +import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; import org.opengroup.osdu.indexer.aws.IndexerAwsApplication; import org.opengroup.osdu.core.common.model.indexer.JobStatus; import org.springframework.boot.test.context.SpringBootTest; import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; import java.util.HashMap; import java.util.Map; -import static org.mockito.Mockito.mock; - @RunWith(MockitoJUnitRunner.class) @SpringBootTest(classes = {IndexerAwsApplication.class}) public class PublisherImplTest { + private final String indexer_sns_topic_arn = "indexer_sns_topic_arn"; + @InjectMocks private PublisherImpl publisher = new PublisherImpl(); @Mock AmazonSNS snsClient; - public void setUp() { - snsClient = mock(AmazonSNS.class); - } - @Test public void publishStatusChangedTagsToTopic() throws Exception { // Arrange @@ -57,23 +62,49 @@ public class PublisherImplTest { Mockito.when(snsClient.publish(Mockito.any(PublishRequest.class))) .thenReturn(Mockito.any(PublishResult.class)); - Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); - messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() - .withDataType("String") - .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); - messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() - .withDataType("String") - .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); - headers.addCorrelationIdIfMissing(); - messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() - .withDataType("String") - .withStringValue(headers.getCorrelationId())); - - PublishRequest publishRequest = new PublishRequestBuilder().generatePublishRequest("data", jobStatus.getStatusesList(), messageAttributes,null); + PublishRequestBuilder<RecordStatus> publishRequestBuilder = new PublishRequestBuilder<>(); + publishRequestBuilder.setGeneralParametersFromHeaders(headers); + + PublishRequest publishRequest = publishRequestBuilder.generatePublishRequest(null, null, jobStatus.getStatusesList()); // Act publisher.publishStatusChangedTagsToTopic(headers, jobStatus); // Assert Mockito.verify(snsClient, Mockito.times(1)).publish(Mockito.eq(publishRequest)); } + + + @Test + public void go_through_init_DLQ() throws Exception { + + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mock, context) -> { + when(mock.getParameterAsString(eq("INDEXER_SNS_TOPIC_ARN"))).thenReturn(indexer_sns_topic_arn); + })) { + + try (MockedConstruction<AmazonSNSConfig> sns = Mockito.mockConstruction(AmazonSNSConfig.class, (mock1, context) -> { + when(mock1.AmazonSNS()).thenReturn(snsClient); + })) { + + publisher.init(); + JobStatus jobStatus = new JobStatus(); + + // Arrange + DpsHeaders headers = new DpsHeaders(); + + PublishRequestBuilder<RecordStatus> publishRequestBuilder = new PublishRequestBuilder<>(); + publishRequestBuilder.setGeneralParametersFromHeaders(headers); + + PublishRequest publishRequest = publishRequestBuilder.generatePublishRequest(null, indexer_sns_topic_arn, jobStatus.getStatusesList()); + // Act + publisher.publishStatusChangedTagsToTopic(headers, jobStatus); + + // Assert + Mockito.verify(snsClient, Mockito.times(1)).publish(Mockito.eq(publishRequest)); + + } + + } + + } + } diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAwsTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAwsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..104d016f9873b68ea1b4df7995172351d3801807 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAwsTest.java @@ -0,0 +1,57 @@ +// 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.Assert; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.boot.test.context.SpringBootTest; + +import org.opengroup.osdu.indexer.aws.IndexerAwsApplication; +import org.elasticsearch.client.RestClientBuilder; + +import javax.net.ssl.SSLContext; + + +@RunWith(MockitoJUnitRunner.class) +@SpringBootTest(classes = {IndexerAwsApplication.class}) +public class ElasticClientHandlerAwsTest { + + @InjectMocks + private ElasticClientHandlerAws handler = new ElasticClientHandlerAws(); + + @Mock + SSLContext sslContext; + + @Test + public void createClientBuilder() throws Exception { + + // Act + RestClientBuilder builder = handler.createClientBuilder("localhost", "Bearer", 6469, "protocolScheme", "tls"); + RestClientBuilder updatedBuilder = builder.setPathPrefix("Prefix"); + // Assert + String cleanPathPrefix = builder.cleanPathPrefix("Prefix"); + + Assert.assertEquals("/Prefix", cleanPathPrefix); + Assert.assertEquals(builder, updatedBuilder); + + } + +} + 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 0000000000000000000000000000000000000000..b250dda665f35b0475372a7ca5ab84217b910089 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/service/UnsafeX509ExtendedTrustManagerTest.java @@ -0,0 +1,201 @@ +// 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 org.mockito.junit.MockitoJUnitRunner; + +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 javax.security.auth.x500.X500Principal; + +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 X500Principal getSubjectX500Principal() { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..3bc34c6b4155ccd952f2a4c88291684ddd47fe1a --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/AwsServiceAccountAuthTokenTest.java @@ -0,0 +1,159 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.aws.util; + +import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream; +import org.junit.Test; +import org.mockito.MockedConstruction; +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 static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.PrintStream; + + +public class AwsServiceAccountAuthTokenTest { + + private AwsServiceAccountAuthToken authorizer; + + private String body_300expire = "{ \"expires_in\" : \"300\", \"access_token\" : \"abcd\", \"data\" : \"data\", \"attributes\" : { \"attribute\" : \"attribute\" } }"; + private String body_0expire = "{ \"expires_in\" : \"0\", \"access_token\" : \"abcd\", \"data\" : \"data\", \"attributes\" : { \"attribute\" : \"attribute\" } }"; + private String body_invalid = "{ \"expires_in\" : }"; + + @Test + public void getAuthTokenTest_null_token_no_code() throws Exception { + + try (MockedConstruction<HttpClient> httpClient = Mockito.mockConstruction(HttpClient.class, (mock, context) -> { + when(mock.send(any(HttpRequest.class))).thenReturn(new HttpResponse()); + })) { + + this.authorizer = new AwsServiceAccountAuthToken(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stream)); + assertNull(this.authorizer.getAuthToken()); + String allWrittenLines = new String(stream.toByteArray()); + stream.flush(); + assertTrue(allWrittenLines.contains("Could not parse AccessToken result")); + stream.close(); + } + + } + + + @Test + public void getAuthTokenTest_succeed_code() throws Exception { + + HttpResponse response = new HttpResponse(null, body_300expire, "contentType", 200, null, null, 0); + + try (MockedConstruction<HttpClient> httpClient = Mockito.mockConstruction(HttpClient.class, (mock, context) -> { + when(mock.send(any(HttpRequest.class))).thenReturn(response); + })) { + + this.authorizer = new AwsServiceAccountAuthToken(); + assertEquals("abcd", this.authorizer.getAuthToken()); + } + + } + + @Test + public void getAuthTokenTest_no_succeed_code() throws Exception { + + HttpResponse response = new HttpResponse(null, body_300expire, "contentType", 400, null, null, 0); + + try (MockedConstruction<HttpClient> httpClient = Mockito.mockConstruction(HttpClient.class, (mock, context) -> { + when(mock.send(any(HttpRequest.class))).thenReturn(response); + })) { + + this.authorizer = new AwsServiceAccountAuthToken(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stream)); + assertNull(this.authorizer.getAuthToken()); + String allWrittenLines = new String(stream.toByteArray()); + stream.flush(); + assertTrue(allWrittenLines.contains("Could not parse AccessToken result")); + stream.close(); + } + + } + + @Test + public void getAuthTokenTest_token_not_expire() throws Exception { + + HttpResponse response = new HttpResponse(null, body_300expire, "contentType", 200, null, null, 0); + + try (MockedConstruction<HttpClient> httpClient = Mockito.mockConstruction(HttpClient.class, (mock, context) -> { + when(mock.send(any(HttpRequest.class))).thenReturn(response); + })) { + + this.authorizer = new AwsServiceAccountAuthToken(); + String firstToken = this.authorizer.getAuthToken(); + assertEquals("abcd", this.authorizer.getAuthToken()); + assertSame(firstToken, this.authorizer.getAuthToken()); + + } + + } + + @Test + public void getAuthTokenTest_token_expire() throws Exception { + + HttpResponse response = new HttpResponse(null, body_0expire, "contentType", 200, null, null, 0); + + try (MockedConstruction<HttpClient> httpClient = Mockito.mockConstruction(HttpClient.class, (mock, context) -> { + when(mock.send(any(HttpRequest.class))).thenReturn(response); + })) { + + this.authorizer = new AwsServiceAccountAuthToken(); + String firstToken = this.authorizer.getAuthToken(); + assertEquals("abcd", this.authorizer.getAuthToken()); + assertNotSame(firstToken, this.authorizer.getAuthToken()); + + } + + } + + @Test + public void getAuthTokenTest_invalid_body() throws Exception { + + HttpResponse response = new HttpResponse(null, body_invalid, "contentType", 200, null, null, 0); + + try (MockedConstruction<HttpClient> httpClient = Mockito.mockConstruction(HttpClient.class, (mock, context) -> { + when(mock.send(any(HttpRequest.class))).thenReturn(response); + })) { + + this.authorizer = new AwsServiceAccountAuthToken(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stream)); + assertNull(this.authorizer.getAuthToken()); + String allWrittenLines = new String(stream.toByteArray()); + stream.flush(); + assertTrue(allWrittenLines.contains("Could not parse AccessToken result")); + stream.close(); + + } + + } + +} diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAwsTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAwsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..577028042be700fe82a7fc3c9a3778e993adf404 --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAwsTest.java @@ -0,0 +1,356 @@ +// 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.util; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockedConstruction; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.aws.sqs.AmazonSQSConfig; +import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; +import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.indexer.model.Constants; +import com.google.gson.Gson; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +import com.amazonaws.services.sqs.AmazonSQS; +import com.amazonaws.services.sqs.model.MessageAttributeValue; +import com.amazonaws.services.sqs.model.SendMessageRequest; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class IndexerQueueTaskBuilderAwsTest { + + private String payload = "{ \"messageId\" : \"messageId\", \"publishTime\" : \"publishTime\", \"data\" : \"data\", \"attributes\" : { \"attribute\" : \"attribute\" } }"; + private String payload_ancestry_kinds = "{ \"messageId\" : \"messageId\", \"publishTime\" : \"publishTime\", \"data\" : \"data\", \"attributes\" : { \"attribute\" : \"attribute\", \"ancestry_kinds\" : \"ancestry_kinds\" } }"; + private String payload_retry = "{ \"messageId\" : \"messageId\", \"publishTime\" : \"publishTime\", \"data\" : \"data\", \"attributes\" : { \"attribute\" : \"attribute\" , \"retry\" : \"11\" } }"; + private static final int INITIAL_RETRY_DELAY_SECONDS = 5; + private final String retryString = "retry"; + private final Long countDownMillis = 123456L; + private final String storage_sqs_url = "storage_sqs_url"; + private final String deadletter_queue_sqs_url = "deadletter_queue_sqs_url"; + + @InjectMocks + IndexerQueueTaskBuilderAws builder; + + @Mock + AmazonSQS sqsClient; + + @Mock + Gson gson; + + @Test + public void createWorkerTaskTest_with_out_retryString() throws K8sParameterNotFoundException{ + + Gson realGson = new Gson(); + + DpsHeaders headers = new DpsHeaders(); + + Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); + messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + headers.addCorrelationIdIfMissing(); + messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getCorrelationId())); + messageAttributes.put(DpsHeaders.USER_EMAIL, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getUserEmail())); + messageAttributes.put(DpsHeaders.AUTHORIZATION, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getAuthorization())); + messageAttributes.put(retryString, new MessageAttributeValue() + .withDataType("String") + .withStringValue(String.valueOf(1))); + + RecordChangedMessages message = realGson.fromJson(payload, RecordChangedMessages.class); + + when(gson.fromJson(payload, RecordChangedMessages.class)).thenReturn(message); + + SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(null).withMessageBody(message.getData()).withDelaySeconds(new Integer(INITIAL_RETRY_DELAY_SECONDS)).withMessageAttributes(messageAttributes); + + builder.createWorkerTask(payload, headers); + + builder.createWorkerTask(payload, countDownMillis, headers); + + Mockito.verify(sqsClient, times(2)).sendMessage(Mockito.eq(sendMessageRequest)); + + } + + @Test + public void createWorkerTaskTest_with_retryString() throws K8sParameterNotFoundException{ + + Gson realGson = new Gson(); + + DpsHeaders headers = new DpsHeaders(); + + Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); + messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + headers.addCorrelationIdIfMissing(); + messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getCorrelationId())); + messageAttributes.put(DpsHeaders.USER_EMAIL, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getUserEmail())); + messageAttributes.put(DpsHeaders.AUTHORIZATION, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getAuthorization())); + messageAttributes.put(retryString, new MessageAttributeValue() + .withDataType("String") + .withStringValue(String.valueOf(1))); + + RecordChangedMessages message = realGson.fromJson(payload_retry, RecordChangedMessages.class); + + when(gson.fromJson(payload, RecordChangedMessages.class)).thenReturn(message); + + SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(null).withMessageBody(message.getData()); + + builder.createWorkerTask(payload, headers); + + builder.createWorkerTask(payload, countDownMillis, headers); + + Mockito.verify(sqsClient, times(2)).sendMessage(Mockito.eq(sendMessageRequest)); + + } + + @Test + public void createWorkerTaskTest_with_ancestry_kinds() throws K8sParameterNotFoundException{ + + Gson realGson = new Gson(); + + DpsHeaders headers = new DpsHeaders(); + + RecordChangedMessages message = realGson.fromJson(payload_ancestry_kinds, RecordChangedMessages.class); + + Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); + messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + headers.addCorrelationIdIfMissing(); + messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getCorrelationId())); + messageAttributes.put(DpsHeaders.USER_EMAIL, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getUserEmail())); + messageAttributes.put(DpsHeaders.AUTHORIZATION, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getAuthorization())); + messageAttributes.put(retryString, new MessageAttributeValue() + .withDataType("String") + .withStringValue(String.valueOf(1))); + messageAttributes.put(Constants.ANCESTRY_KINDS, new MessageAttributeValue() + .withDataType("String") + .withStringValue(message.getAttributes().get(Constants.ANCESTRY_KINDS))); + + + + when(gson.fromJson(payload, RecordChangedMessages.class)).thenReturn(message); + + SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(null).withMessageBody(message.getData()).withDelaySeconds(new Integer(INITIAL_RETRY_DELAY_SECONDS)).withMessageAttributes(messageAttributes); + + builder.createWorkerTask(payload, headers); + + builder.createWorkerTask(payload, countDownMillis, headers); + + Mockito.verify(sqsClient, times(2)).sendMessage(Mockito.eq(sendMessageRequest)); + + } + + @Test + public void createReIndexTaskTest() throws K8sParameterNotFoundException{ + + DpsHeaders headers = new DpsHeaders(); + + Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); + messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + headers.addCorrelationIdIfMissing(); + messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getCorrelationId())); + messageAttributes.put(DpsHeaders.USER_EMAIL, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getUserEmail())); + messageAttributes.put(DpsHeaders.AUTHORIZATION, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getAuthorization())); + messageAttributes.put("ReIndexCursor", new MessageAttributeValue() + .withDataType("String") + .withStringValue("True")); + + SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(null).withMessageBody(payload).withMessageAttributes(messageAttributes); + + builder.createReIndexTask(payload, headers); + + builder.createReIndexTask(payload, countDownMillis, headers); + + Mockito.verify(sqsClient, times(2)).sendMessage(Mockito.eq(sendMessageRequest)); + + } + + @Test + public void getWaitTimeExpTest() throws K8sParameterNotFoundException{ + + int zero_wait_time = IndexerQueueTaskBuilderAws.getWaitTimeExp(0); + + assertEquals(0, zero_wait_time); + + int non_zero_wait_time = IndexerQueueTaskBuilderAws.getWaitTimeExp(4); + + assertEquals(64, non_zero_wait_time); + } + + @Test + public void go_through_init_StorageQueue() throws Exception { + + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mock, context) -> { + when(mock.getParameterAsString(eq("STORAGE_SQS_URL"))).thenReturn(storage_sqs_url); + when(mock.getParameterAsString("INDEXER_DEADLETTER_QUEUE_SQS_URL")).thenReturn(deadletter_queue_sqs_url); + })) { + + try (MockedConstruction<AmazonSQSConfig> config = Mockito.mockConstruction(AmazonSQSConfig.class, (mock1, context) -> { + when(mock1.AmazonSQS()).thenReturn(sqsClient); + })) { + + builder.init(); + + Gson realGson = new Gson(); + + DpsHeaders headers = new DpsHeaders(); + + Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); + messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + headers.addCorrelationIdIfMissing(); + messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getCorrelationId())); + messageAttributes.put(DpsHeaders.USER_EMAIL, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getUserEmail())); + messageAttributes.put(DpsHeaders.AUTHORIZATION, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getAuthorization())); + messageAttributes.put(retryString, new MessageAttributeValue() + .withDataType("String") + .withStringValue(String.valueOf(1))); + + RecordChangedMessages message = realGson.fromJson(payload, RecordChangedMessages.class); + + SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(storage_sqs_url).withMessageBody(message.getData()).withDelaySeconds(new Integer(INITIAL_RETRY_DELAY_SECONDS)).withMessageAttributes(messageAttributes); + + builder.createWorkerTask(payload, headers); + + builder.createWorkerTask(payload, countDownMillis, headers); + + Mockito.verify(sqsClient, times(2)).sendMessage(Mockito.eq(sendMessageRequest)); + + } + } + + } + + @Test + public void go_through_init_DLQ() throws Exception { + + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mock, context) -> { + when(mock.getParameterAsString(eq("STORAGE_SQS_URL"))).thenReturn(storage_sqs_url); + when(mock.getParameterAsString("INDEXER_DEADLETTER_QUEUE_SQS_URL")).thenReturn(deadletter_queue_sqs_url); + })) { + + try (MockedConstruction<AmazonSQSConfig> config = Mockito.mockConstruction(AmazonSQSConfig.class, (mock1, context) -> { + when(mock1.AmazonSQS()).thenReturn(sqsClient); + })) { + + builder.init(); + + Gson realGson = new Gson(); + + DpsHeaders headers = new DpsHeaders(); + + Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); + messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + messageAttributes.put(DpsHeaders.DATA_PARTITION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getPartitionIdWithFallbackToAccountId())); + headers.addCorrelationIdIfMissing(); + messageAttributes.put(DpsHeaders.CORRELATION_ID, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getCorrelationId())); + messageAttributes.put(DpsHeaders.USER_EMAIL, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getUserEmail())); + messageAttributes.put(DpsHeaders.AUTHORIZATION, new MessageAttributeValue() + .withDataType("String") + .withStringValue(headers.getAuthorization())); + messageAttributes.put(retryString, new MessageAttributeValue() + .withDataType("String") + .withStringValue(String.valueOf(1))); + + RecordChangedMessages message = realGson.fromJson(payload_retry, RecordChangedMessages.class); + + SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(deadletter_queue_sqs_url).withMessageBody(message.getData()); + + builder.createWorkerTask(payload_retry, headers); + + builder.createWorkerTask(payload_retry, countDownMillis, headers); + + Mockito.verify(sqsClient, times(2)).sendMessage(Mockito.eq(sendMessageRequest)); + + + } + + } + + } + +} diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImplTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1c33fccd68bc4b0c492797a0ccb81b71b097e2bd --- /dev/null +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImplTest.java @@ -0,0 +1,111 @@ +// 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.util; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; + + +import java.util.HashMap; +import java.util.Map; +import org.mockito.MockitoAnnotations; +import org.mockito.internal.matchers.apachecommons.ReflectionEquals; +import org.mockito.runners.MockitoJUnitRunner; +import static org.opengroup.osdu.core.common.model.http.DpsHeaders.AUTHORIZATION; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +@RunWith(MockitoJUnitRunner.class) +public class RequestInfoImplTest { + + @InjectMocks + private RequestInfoImpl request_info; + + @Mock + private DpsHeaders headersMap; + + @Mock + private AwsServiceAccountAuthToken awsServiceAccountAuthToken; + + @Before + public void setup(){ + headersMap = mock(DpsHeaders.class); + awsServiceAccountAuthToken = mock(AwsServiceAccountAuthToken.class); + MockitoAnnotations.initMocks(this); + } + + @Test(expected = AppException.class) + public void getHeaders_null_headersMap(){ + RequestInfoImpl request_info_nullheader = new RequestInfoImpl(); + + request_info_nullheader.getHeaders(); + } + + @Test + public void getHeaders_not_null_headersMap(){ + + Map<String, String> map = new HashMap<String,String>(); + + DpsHeaders expected = DpsHeaders.createFromMap(map); + + DpsHeaders headers = request_info.getHeaders(); + + assertTrue(new ReflectionEquals(expected).matches(headers)); + } + + @Test + public void getPartitionId_test(){ + + String result = request_info.getPartitionId(); + + assertNull(result); + } + + @Test + public void getHeadersMapWithDwdAuthZ_test(){ + + Map<String, String> expected = new HashMap<String, String>(); + expected.put("content-type","application/json"); + + Map<String, String> result = request_info.getHeadersMapWithDwdAuthZ(); + + assertTrue(new ReflectionEquals(expected).matches(result)); + } + + @Test + public void isCronRequest_test(){ + assertFalse(request_info.isCronRequest()); + } + + @Test + public void isTaskQueueRequest_test(){ + assertFalse(request_info.isTaskQueueRequest()); + } + + @Test + public void getHeadersWithDwdAuthZ_test() { + + DpsHeaders result = request_info.getHeadersWithDwdAuthZ(); + + assertTrue(result.getHeaders().containsKey(AUTHORIZATION)); + } +}