Commit ec745d7a authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch 'feature/GONRG-2074_fix_audit' into 'integration-master'

GONRG-2074 unit tests, logs.

Closes GONRG-2074

See merge request go3-nrg/platform/System/partition!38
parents bc5f384b adc0467d
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 EPAM Systems, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.opengroup.osdu.partition.logging;
import com.google.common.base.Strings;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsService;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.logging.audit.AuditPayload;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
import org.opengroup.osdu.core.common.model.entitlements.EntitlementsException;
import org.opengroup.osdu.core.common.model.entitlements.Groups;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
......@@ -23,26 +32,11 @@ public class AuditLogger {
private final JaxRsDpsLog logger;
private final IEntitlementsFactory factory;
private final DpsHeaders headers;
private AuditEvents events = null;
private AuditEvents getAuditEvents() {
if (this.events == null) {
if (Strings.isNullOrEmpty(this.headers.getUserEmail())) {
IEntitlementsService service = this.factory.create(headers);
try {
Groups groups = service.getGroups();
this.events = new AuditEvents(groups.getMemberEmail());
} catch (EntitlementsException e) {
throw new AppException(HttpStatus.UNAUTHORIZED.value(), "Authentication Failure",
e.getMessage(), e);
}
} else {
this.events = new AuditEvents(this.headers.getUserEmail());
}
this.events = new AuditEvents("partitionAccountUser");
}
return this.events;
}
......
......@@ -20,7 +20,6 @@ package org.opengroup.osdu.partition.logging;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.List;
......@@ -30,9 +29,7 @@ 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.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
@RunWith(MockitoJUnitRunner.class)
public class AuditLoggerTest {
......@@ -40,12 +37,6 @@ public class AuditLoggerTest {
@Mock
private JaxRsDpsLog log;
@Mock
private IEntitlementsFactory factory;
@Mock
private DpsHeaders headers;
@InjectMocks
private AuditLogger sut;
......@@ -53,7 +44,6 @@ public class AuditLoggerTest {
@Before
public void setup() {
when(this.headers.getUserEmail()).thenReturn("test_user@email.com");
resources = Collections.singletonList("resources");
}
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<logger name="org.opengroup.osdu" level="DEBUG"/>
<logger name="org.opengroup.osdu" level="${LOG_LEVEL}"/>
<springProfile name="local">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
......
......@@ -17,52 +17,21 @@
package org.opengroup.osdu.partition.api;
import static org.junit.Assert.assertEquals;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengroup.osdu.partition.util.GCPTestUtils;
import org.springframework.http.HttpStatus;
public class TestUpdatePartition extends UpdatePartitionTest {
@Override
@Before
public void setup() throws Exception {
public void setup() {
this.testUtils = new GCPTestUtils();
}
@Override
@Test
public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception {
createResource();
ClientResponse response = this.descriptor
.runWithCustomPayload(this.getId(), getValidBodyForUpdatePartition(),
this.testUtils.getAccessToken());
deleteResource();
assertEquals(response.getStatus(), HttpStatus.NO_CONTENT.value());
assertEquals("GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH",
response.getHeaders().getFirst("Access-Control-Allow-Methods"));
assertEquals(
"origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey",
response.getHeaders().getFirst("Access-Control-Allow-Headers"));
assertEquals("*", response.getHeaders().getFirst("Access-Control-Allow-Origin"));
assertEquals("true", response.getHeaders().getFirst("Access-Control-Allow-Credentials"));
assertEquals("default-src 'self'", response.getHeaders().getFirst("Content-Security-Policy"));
assertEquals("max-age=31536000; includeSubDomains",
response.getHeaders().getFirst("Strict-Transport-Security"));
assertEquals("0", response.getHeaders().getFirst("Expires"));
assertEquals("DENY", response.getHeaders().getFirst("X-Frame-Options"));
assertEquals("private, max-age=300", response.getHeaders().getFirst("Cache-Control"));
assertEquals("1; mode=block", response.getHeaders().getFirst("X-XSS-Protection"));
assertEquals("nosniff", response.getHeaders().getFirst("X-Content-Type-Options"));
}
@Override
@After
public void tearDown() throws Exception {
public void tearDown() {
this.testUtils = null;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment