Skip to content
Snippets Groups Projects
Commit e3d36646 authored by Alan Braz's avatar Alan Braz
Browse files

restore from master

parent 7563af41
No related branches found
No related tags found
1 merge request!6Trusted ibm
Showing
with 22 additions and 583 deletions
# 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.
version: 0.2
phases:
# pre-build:
# commands:
# - echo Logging in to Amazon ECR...
# - aws --version
# - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
# - REPOSITORY_URI=012345678910.dkr.ecr.us-east-1.amazonaws.com/hello-world
# - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
# - IMAGE_TAG=build-$(echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}')
install:
runtime-versions:
java: openjdk8
docker: 18
commands:
- echo Entered the install phase...
- apt-get update -y
- apt-get install -y maven
- java -version
- echo $JAVA_HOME
- export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
- echo $JAVA_HOME
- mvn clean # .m2 is not created until the first Maven command
- cp ./indexer-core/maven/settings.xml /root/.m2/settings.xml # replace the default settings.xml with our custom one
- export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
- mvn -version
build:
commands:
- echo Starting 'Copying CloudFormation scripts to S3://$CFN_S3_BUCKET'
- pwd
- ls
- aws s3 cp ./provider/indexer-aws/CloudFormation "s3://$CFN_S3_BUCKET" --exclude "*" --include "*.yml" --recursive --debug
- echo Ending 'Ending CloudFormation scripts to S3://$CFN_S3_BUCKET'
# - echo os-indexer build started on `date`...
- pwd
- ls -R -la
- java -version
- echo $JAVA_HOME
- export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
- mvn -version
# - mvn test
post_build:
commands:
# - echo ...os-indexer build completed on `date`
# - echo os-indexer beginning packaging to jar...
# - mvn package
cache:
paths:
- '/root/.m2/**/*'
artifacts:
files:
- '**/*'
......@@ -136,6 +136,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......@@ -230,7 +235,7 @@
<useSystemClassLoader>false</useSystemClassLoader>
<threadCount>1</threadCount>
</configuration>
</plugin>
</plugin>
</plugins>
</build>
......
package org.opengroup.osdu.indexer.azure.util;
import java.util.Map;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
public interface IHeadersInfo {
DpsHeaders getHeaders();
String getUser();
String getPartitionId();
String getPrimaryPartitionId();
Map<String, String> getHeadersMap();
DpsHeaders getCoreServiceHeaders(Map<String, String> input);
}
......@@ -4,10 +4,10 @@
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>dev-azure-com-slb-des-ext-collaboration-os-core</id>
<username>os-core</username>
<id>os-core</id>
<username>slb-des-ext-collaboration</username>
<!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. -->
<!-- The generated token expires on or before 10/8/2019 -->
<!-- The generated token expires on or before 11/14/2019 -->
<password>${VSTS_FEED_TOKEN}</password>
</server>
</servers>
......
......@@ -25,7 +25,7 @@ cd ..
# Upload all build and deploy scripts as artifacts
cp -R ./scripts $STAGE_DIR
# Upload the build generated .jar file as an artifact
cp ./target/indexer-gcp-1.0.0.jar $STAGE_DIR
cp ./target/indexer-gcp-*-spring-boot.jar $STAGE_DIR
echo "Staging deployment artifacts to folder: $STAGE_DIR"
cp ./src/main/appengine/app.yaml $STAGE_DIR
......
......@@ -57,4 +57,4 @@ public class AttributesCache implements IAttributesCache<String,Set>, AutoClosea
public void close() {
this.cache.close();
}
}
}
\ No newline at end of file
......@@ -26,4 +26,4 @@ public class DatastoreCredentialCache extends RedisCache<String, AccessToken> {
public DatastoreCredentialCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT) {
super(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), 58 * 60, String.class, AccessToken.class);
}
}
}
\ No newline at end of file
// Copyright 2017-2019, Schlumberger
//
// 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.di;
import org.opengroup.osdu.core.gcp.logging.logger.AppEngineLoggingProvider;
import org.opengroup.osdu.core.logging.DpsLog;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@Component
@RequestScope
public class DpsLogFactory extends AbstractFactoryBean<DpsLog> {
private AppEngineLoggingProvider appEngineLoggingProvider = new AppEngineLoggingProvider();
@Override
protected DpsLog createInstance() throws Exception {
return appEngineLoggingProvider.getLogger();
}
@Override
public Class<?> getObjectType() {
return DpsLog.class;
}
}
\ No newline at end of file
......@@ -17,7 +17,6 @@ package org.opengroup.osdu.indexer.di;
import lombok.extern.java.Log;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.core.gcp.multitenancy.TenantFactory;
import org.opengroup.osdu.core.multitenancy.ITenantFactory;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
......@@ -36,4 +35,4 @@ public class TenantFactoryService extends AbstractFactoryBean<ITenantFactory> {
public Class<?> getObjectType() {
return ITenantFactory.class;
}
}
}
\ No newline at end of file
package org.opengroup.osdu.indexer.di;
import lombok.extern.java.Log;
import org.opengroup.osdu.core.api.DpsHeaders;
import org.opengroup.osdu.core.multitenancy.ITenantFactory;
import org.opengroup.osdu.core.multitenancy.TenantInfo;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import javax.inject.Inject;
@Log
@Component
@RequestScope
public class TenantInfoFactory extends AbstractFactoryBean<TenantInfo> {
@Inject
private ITenantFactory tenantFactory;
@Inject
private DpsHeaders headers;
@Override
protected TenantInfo createInstance() throws Exception {
String id = this.headers.getPartitionIdWithFallbackToAccountId();
return this.tenantFactory.getTenantInfo(id);
}
@Override
public Class<?> getObjectType() {
return TenantInfo.class;
}
}
......@@ -99,4 +99,4 @@ public class KmsClient implements IKmsClient {
.setApplicationName("CloudKMS snippets")
.build();
}
}
}
\ No newline at end of file
......@@ -29,8 +29,6 @@ import org.apache.commons.lang3.time.DateUtils;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.util.Crc32c;
import org.opengroup.osdu.indexer.cache.DatastoreCredentialCache;
import org.opengroup.osdu.core.cryptographic.Crc32c;
import org.opengroup.osdu.core.multitenancy.TenantInfo;
import java.util.Date;
......@@ -108,4 +106,4 @@ public class DatastoreCredential extends GoogleCredentials {
private String getCacheKey() {
return Crc32c.hashToBase64EncodedString(String.format("datastoreCredential:%s", this.tenant.getName()));
}
}
}
\ No newline at end of file
......@@ -21,7 +21,6 @@ import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.http.HttpTransportOptions;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.indexer.cache.DatastoreCredentialCache;
import org.opengroup.osdu.core.multitenancy.TenantInfo;
import org.springframework.stereotype.Component;
import org.threeten.bp.Duration;
......
......@@ -87,4 +87,4 @@ public class ElasticRepositoryDatastore implements IElasticRepository {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Cluster setting fetch error", "An error has occurred fetching cluster settings from the datastore.", e);
}
}
}
}
\ No newline at end of file
......@@ -140,4 +140,4 @@ public class PublisherImpl implements IPublisher {
return publisher;
}
}
}
}
\ No newline at end of file
// Copyright 2017-2019, Schlumberger
//
// 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.util;
import com.google.common.base.Strings;
import lombok.extern.java.Log;
import org.opengroup.osdu.core.api.DpsHeaders;
import org.opengroup.osdu.core.gcp.model.AppEngineHeaders;
import org.opengroup.osdu.is.core.model.SlbHeaders;
import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo;
import org.opengroup.osdu.is.core.util.Preconditions;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import javax.inject.Inject;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
@Log
@Component
@RequestScope
public class HeadersInfoGcpImpl implements IHeadersInfo {
@Inject
private DpsHeaders headersMap;
private static final HashSet<String> FORBIDDEN_FROM_LOGGING = new HashSet<>();
static {
FORBIDDEN_FROM_LOGGING.add(DpsHeaders.AUTHORIZATION);
FORBIDDEN_FROM_LOGGING.add(DpsHeaders.ON_BEHALF_OF);
}
private static final HashSet<String> FORWARDED_HEADERS = new HashSet<>();
static {
FORWARDED_HEADERS.add(AppEngineHeaders.CITY_LAT_LONG);
FORWARDED_HEADERS.add(AppEngineHeaders.COUNTRY);
FORWARDED_HEADERS.add(AppEngineHeaders.REGION);
FORWARDED_HEADERS.add(AppEngineHeaders.CITY);
FORWARDED_HEADERS.add(AppEngineHeaders.TASK_QUEUE_RETRY_COUNT);
FORWARDED_HEADERS.add(AppEngineHeaders.TASK_QUEUE_NAME);
FORWARDED_HEADERS.add(AppEngineHeaders.DATA_GROUPS);
FORWARDED_HEADERS.add(AppEngineHeaders.CLOUD_TRACE_CONTEXT);
FORWARDED_HEADERS.add(AppEngineHeaders.TRACE_ID);
FORWARDED_HEADERS.add(AppEngineHeaders.CRON_SERVICE);
FORWARDED_HEADERS.add(SlbHeaders.PRIMARY_PARTITION_ID);
}
@Override
public DpsHeaders getHeaders() {
Preconditions.checkNotNull(headersMap, "input headers cannot be null");
DpsHeaders headers = this.getCoreServiceHeaders(headersMap.getHeaders());
return headers;
}
@Override
public String getUser() {
return getHeaders().getUserEmail();
}
@Override
public String getPartitionId() {
return getHeaders().getPartitionIdWithFallbackToAccountId();
}
@Override
public String getPrimaryPartitionId() {
return getHeadersMap().get(SlbHeaders.PRIMARY_PARTITION_ID);
}
@Override
public Map<String, String> getHeadersMap() {
return getHeaders().getHeaders();
}
@Override
public DpsHeaders getCoreServiceHeaders(Map<String, String> input) {
DpsHeaders output = DpsHeaders.createFromMap(input);
input.forEach((key,value) -> {
if (FORWARDED_HEADERS.contains(key)) {
if (key.equals(AppEngineHeaders.CLOUD_TRACE_CONTEXT)) {
String traceContext = input.get(AppEngineHeaders.CLOUD_TRACE_CONTEXT);
if (!Strings.isNullOrEmpty(traceContext)) {
output.put(AppEngineHeaders.TRACE_ID, TraceIdExtractor.getTraceId(traceContext));
output.put(key, traceContext);
}
} else {
output.put(key, input.get(key));
}
}
});
return output;
}
@Override
public String toString() {
return this.getHeadersMap().entrySet().stream().filter(map -> !FORBIDDEN_FROM_LOGGING.contains(map.getKey().toLowerCase())).map(Map.Entry::toString).collect(Collectors.joining(" | "));
}
}
\ No newline at end of file
......@@ -132,4 +132,4 @@ public class CronServiceImplTest {
verify(this.indicesService, times(0)).deleteIndex(any(), any());
}
}
}
\ No newline at end of file
......@@ -166,7 +166,7 @@ public class IndexerMappingServiceTest {
doReturn(response).when(this.restHighLevelClient).updateByQuery(any(), any(RequestOptions.class));
when(response.getBulkFailures()).thenReturn(new ArrayList<Failure>());
when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient);
this.sut.updateIndexMappingForIndicesOfSameType( indices,"any field");
} catch (Exception e) {
fail("Should not throw this exception" + e.getMessage());
......@@ -200,8 +200,8 @@ public class IndexerMappingServiceTest {
doReturn(response).when(this.restHighLevelClient).updateByQuery(any(), any(RequestOptions.class));
when(response.getBulkFailures()).thenReturn(new ArrayList<Failure>());
when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient);
this.sut.updateIndexMappingForIndicesOfSameType(indices,"any field");
this.sut.updateIndexMappingForIndicesOfSameType(indices,"any field");
} catch (Exception e) {
throw e;
}
......@@ -211,7 +211,7 @@ public class IndexerMappingServiceTest {
public void should_throw_exception_if_type_of_index_is_invalid_andWeIndexfield_with_keyword() throws Exception {
try {
Set<String> indices = new HashSet<String>();
indices.add("indices 1");
indices.add("indices 1");
GetFieldMappingsResponse getFieldMappingsResponse = mock(GetFieldMappingsResponse.class);
doReturn(this.indicesClient).when(this.restHighLevelClient).indices();
when(this.indicesClient.getFieldMapping(any(), any())).thenReturn(getFieldMappingsResponse);
......
// Copyright 2017-2019, Schlumberger
//
// 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.service;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.api.DpsHeaders;
import org.opengroup.osdu.core.multitenancy.ITenantFactory;
import org.opengroup.osdu.core.multitenancy.TenantInfo;
import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo;
import org.opengroup.osdu.is.core.util.AppException;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
@RunWith(SpringRunner.class)
public class TenantInfoServiceTest {
private static final String HEADER_NAME = "ANY_HEADER";
private static final String HEADER_VALUE = "ANY_VALUE";
@Mock
private ITenantFactory tenantFactory;
@Mock
private IHeadersInfo headersInfo;
@InjectMocks
private TenantInfoServiceImpl sut;
@Mock
private TenantInfo info;
@Mock
private HttpHeaders httpHeaders;
@InjectMocks
private DpsHeaders HEADERS;
@Before
public void setup() {
HEADERS.put(HEADER_NAME, HEADER_VALUE);
}
@Ignore
@Test
public void should_return_validTenant_given_validAccountId() {
when(this.info.getName()).thenReturn("tenant1");
when(tenantFactory.getTenantInfo("tenant1")).thenReturn(info);
when(this.headersInfo.getHeaders()).thenReturn(HEADERS);
when(this.headersInfo.getPartitionId()).thenReturn("tenant1");
when(this.sut.getTenantInfo()).thenReturn(info);
assertNotNull(this.sut.getTenantInfo());
assertEquals("tenant1", this.sut.getTenantInfo().getName());
}
@Test(expected = AppException.class)
public void should_throwException_given_invalidAccountId() {
when(this.info.getName()).thenReturn("tenant2");
when(tenantFactory.getTenantInfo("tenant1")).thenReturn(null);
when(this.sut.getTenantInfo()).thenReturn(info);
assertNotNull(this.sut.getTenantInfo());
}
}
\ No newline at end of file
// Copyright 2017-2019, Schlumberger
//
// 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.util;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.api.DpsHeaders;
import org.opengroup.osdu.core.gcp.model.AppEngineHeaders;
import org.opengroup.osdu.is.core.model.SlbHeaders;
import org.opengroup.osdu.is.core.util.HeadersUtil;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.singletonList;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;
@RunWith(SpringRunner.class)
public class HeadersInfoGcpImplTest {
@Mock
private HttpHeaders httpHeaders;
@Mock
private DpsHeaders dpsHeaders;
@InjectMocks
private HeadersInfoGcpImpl sut;
@Test
public void should_convert_Cloud_Trace_when_header_contains_it() {
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put(DpsHeaders.AUTHORIZATION, "any token");
requestHeaders.put(AppEngineHeaders.CLOUD_TRACE_CONTEXT, "any trace");
DpsHeaders map = this.sut.getCoreServiceHeaders(requestHeaders);
assertEquals("any token", map.getAuthorization());
assertEquals("any trace", map.getHeaders().get(AppEngineHeaders.TRACE_ID));
}
@Test
public void should_return_header_logs_when_header_contains_email() {
MultiValueMap<String, String> requestHeaders = new LinkedMultiValueMap<>();
requestHeaders.add(DpsHeaders.AUTHORIZATION, "any token");
requestHeaders.add(DpsHeaders.ON_BEHALF_OF, "any onBehalf");
requestHeaders.add(DpsHeaders.CORRELATION_ID, "any correlationId");
requestHeaders.add(DpsHeaders.USER_EMAIL, "abc@xyz.com");
requestHeaders.add(DpsHeaders.ACCOUNT_ID, "any account");
DpsHeaders map = this.sut.getCoreServiceHeaders(requestHeaders.toSingleValueMap());
assertEquals("any token", map.getAuthorization());
DpsHeaders headers = DpsHeaders.createFromEntrySet(requestHeaders.entrySet());
assertEquals("account id: any account | on behalf: any onBehalf | user email: any onBehalf | correlation id: " +
"any correlationId", HeadersUtil.toLogMsg(headers, "any onBehalf"));
}
@Test
public void should_return_header_logs_when_jwt_decode_fails() {
MultiValueMap<String, String> requestHeaders = new LinkedMultiValueMap<>();
requestHeaders.add(DpsHeaders.AUTHORIZATION, "any token");
requestHeaders.add(DpsHeaders.ON_BEHALF_OF, "any onBehalf");
requestHeaders.add(DpsHeaders.CORRELATION_ID, "any correlationId");
requestHeaders.add(DpsHeaders.ACCOUNT_ID, "any account");
DpsHeaders map = this.sut.getCoreServiceHeaders(requestHeaders.toSingleValueMap());
assertEquals("any token", map.getAuthorization());
DpsHeaders headers = DpsHeaders.createFromEntrySet(requestHeaders.entrySet());
assertEquals("account id: any account | on behalf: any onBehalf | correlation id: any correlationId",
HeadersUtil.toLogMsg(headers, null));
}
@Test
public void should_return_header_logs_when_header_doesNot_contain_email() {
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put(DpsHeaders.AUTHORIZATION, "any token");
requestHeaders.put(DpsHeaders.ON_BEHALF_OF, "any onBehalf");
requestHeaders.put(DpsHeaders.CORRELATION_ID, "any correlationId");
requestHeaders.put(DpsHeaders.ACCOUNT_ID, "any account");
DpsHeaders map = this.sut.getCoreServiceHeaders(requestHeaders);
assertEquals("any token", map.getHeaders().get(DpsHeaders.AUTHORIZATION));
}
@Test
public void check_correct_headers() {
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put(DpsHeaders.AUTHORIZATION, "any token");
requestHeaders.put(DpsHeaders.CORRELATION_ID, "any correlationId");
requestHeaders.put(DpsHeaders.ACCOUNT_ID, "any account");
requestHeaders.put(DpsHeaders.ON_BEHALF_OF, "any onBehalf");
requestHeaders.put(DpsHeaders.USER_EMAIL, "abc@xyz.com");
requestHeaders.put(DpsHeaders.CONTENT_TYPE, "any contentType");
requestHeaders.put(AppEngineHeaders.DATA_GROUPS, "any dataGrp");
requestHeaders.put(AppEngineHeaders.CRON_SERVICE, "true");
DpsHeaders map = this.sut.getCoreServiceHeaders(requestHeaders);
assertEquals("any token", map.getAuthorization());
assertEquals("any correlationId", map.getCorrelationId());
assertEquals("abc@xyz.com", map.getUserEmail());
assertEquals("any account", map.getPartitionIdWithFallbackToAccountId());
assertEquals("any onBehalf", map.getOnBehalfOf());
assertEquals("any contentType", map.getHeaders().get(DpsHeaders.CONTENT_TYPE));
assertEquals("any dataGrp", map.getHeaders().get(AppEngineHeaders.DATA_GROUPS));
assertEquals("true", map.getHeaders().get(AppEngineHeaders.CRON_SERVICE));
}
@Test
public void should_return_null_auth_header_when_invalid_header() {
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put(DpsHeaders.AUTHORIZATION, null);
DpsHeaders map = this.sut.getCoreServiceHeaders(requestHeaders);
assertNotNull(map);
assertNull(map.getAuthorization());
}
@Ignore
@Test
public void should_addCorrelationId_when_gettingHeaders() {
MultiValueMap<String, String> requestHeaders = new LinkedMultiValueMap<>();
requestHeaders.put(DpsHeaders.USER_EMAIL, singletonList("a@b.com"));
when(httpHeaders.toSingleValueMap()).thenReturn(requestHeaders.toSingleValueMap());
assertNotNull(sut.getHeaders().getCorrelationId());
}
@Ignore
@Test
public void should_returnUser_when_requested() {
MultiValueMap<String, String> requestHeaders = new LinkedMultiValueMap<>();
requestHeaders.put(DpsHeaders.USER_EMAIL, singletonList("a@b.com"));
when(httpHeaders.toSingleValueMap()).thenReturn(requestHeaders.toSingleValueMap());
assertEquals("a@b.com", sut.getUser());
}
@Ignore
@Test
public void should_returnPrimaryAccountId_when_requested() {
MultiValueMap<String, String> requestHeaders = new LinkedMultiValueMap<>();
requestHeaders.put(SlbHeaders.PRIMARY_PARTITION_ID, singletonList("apc"));
when(httpHeaders.toSingleValueMap()).thenReturn(requestHeaders.toSingleValueMap());
assertEquals("apc", sut.getPrimaryPartitionId());
}
@Test
public void should_convert_to_string_when_map_is_correct() {
MultiValueMap<String, String> requestHeaders = new LinkedMultiValueMap<>();
requestHeaders.add("a", "a val");
requestHeaders.add("b", "b val");
requestHeaders.add(DpsHeaders.AUTHORIZATION, "blah");
when(this.httpHeaders.toSingleValueMap()).thenReturn(requestHeaders.toSingleValueMap());
assertFalse(this.sut.toString().contains("a=a val"));
assertFalse(this.sut.toString().contains("b=b val"));
}
// @Test
// public void should_convert_multivalued_map_to_hash_map_when_input_map_is_correct() {
// MultivaluedMap<String, String> requestHeaders = new MultivaluedMapImpl<String, String>();
// requestHeaders.putSingle(DpsHeaders.AUTHORIZATION, "any token");
// requestHeaders.putSingle(DpsHeaders.CORRELATION_ID, "any correlationId");
// requestHeaders.putSingle(DpsHeaders.ACCOUNT_ID, "any account");
// requestHeaders.putSingle(DpsHeaders.ON_BEHALF_OF, "any onBehalf");
// requestHeaders.putSingle(DpsHeaders.USER_EMAIL, "abc@xyz.com");
// requestHeaders.putSingle(DpsHeaders.CONTENT_TYPE, "any contentType");
// requestHeaders.putSingle(AppEngineHeaders.DATA_GROUPS, "any dataGrp");
//
// Map<String, String> map = this.sut.convertMultiToRegularMap(requestHeaders);
//
// assertEquals("any token", map.get(DpsHeaders.AUTHORIZATION));
// assertEquals("any correlationId", map.get(DpsHeaders.CORRELATION_ID));
// assertEquals("abc@xyz.com", map.get(DpsHeaders.USER_EMAIL));
// assertEquals("any account", map.get(DpsHeaders.ACCOUNT_ID));
// assertEquals("any onBehalf", map.get(DpsHeaders.ON_BEHALF_OF));
// assertEquals("any contentType", map.get(DpsHeaders.CONTENT_TYPE));
// assertEquals("any dataGrp", map.get(AppEngineHeaders.DATA_GROUPS));
// }
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment