From adc0467db68e4f3719fe5b8ba42a83d22e8bd4a2 Mon Sep 17 00:00:00 2001
From: Stanislav Riabokon <Stanislav_Riabokon@epam.com>
Date: Sun, 28 Mar 2021 11:02:35 +0400
Subject: [PATCH] Fixed unit tests, logs.

---
 .../osdu/partition/logging/AuditLogger.java   | 42 ++++++++-----------
 .../partition/logging/AuditLoggerTest.java    | 10 -----
 .../src/main/resources/logback.xml            |  2 +-
 .../partition/api/TestUpdatePartition.java    | 35 +---------------
 4 files changed, 21 insertions(+), 68 deletions(-)

diff --git a/partition-core/src/main/java/org/opengroup/osdu/partition/logging/AuditLogger.java b/partition-core/src/main/java/org/opengroup/osdu/partition/logging/AuditLogger.java
index 031486864..959272553 100644
--- a/partition-core/src/main/java/org/opengroup/osdu/partition/logging/AuditLogger.java
+++ b/partition-core/src/main/java/org/opengroup/osdu/partition/logging/AuditLogger.java
@@ -1,18 +1,27 @@
+/*
+  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;
   }
diff --git a/partition-core/src/test/java/org/opengroup/osdu/partition/logging/AuditLoggerTest.java b/partition-core/src/test/java/org/opengroup/osdu/partition/logging/AuditLoggerTest.java
index ecdd12cd2..827c7c9a3 100644
--- a/partition-core/src/test/java/org/opengroup/osdu/partition/logging/AuditLoggerTest.java
+++ b/partition-core/src/test/java/org/opengroup/osdu/partition/logging/AuditLoggerTest.java
@@ -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");
   }
 
diff --git a/provider/partition-gcp/src/main/resources/logback.xml b/provider/partition-gcp/src/main/resources/logback.xml
index d6a5ae8b0..a67f87124 100644
--- a/provider/partition-gcp/src/main/resources/logback.xml
+++ b/provider/partition-gcp/src/main/resources/logback.xml
@@ -1,7 +1,7 @@
 <?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>
diff --git a/testing/partition-test-gcp/src/test/java/org/opengroup/osdu/partition/api/TestUpdatePartition.java b/testing/partition-test-gcp/src/test/java/org/opengroup/osdu/partition/api/TestUpdatePartition.java
index 1b674deb3..35aec46a0 100644
--- a/testing/partition-test-gcp/src/test/java/org/opengroup/osdu/partition/api/TestUpdatePartition.java
+++ b/testing/partition-test-gcp/src/test/java/org/opengroup/osdu/partition/api/TestUpdatePartition.java
@@ -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;
   }
 }
-- 
GitLab