You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/11/05 20:48:45 UTC

[GitHub] [ozone] GeorgeJahad opened a new pull request #2810: HDDS-5778. Client side unit tests

GeorgeJahad opened a new pull request #2810:
URL: https://github.com/apache/ozone/pull/2810


   ## What changes were proposed in this pull request?
   
   Adding a test for new ugi filter.  This code was written entirely by [Neil Joshi](https://github.com/neils-dev)
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-5778
   
   ## How was this patch tested?
   
   ```
   cd hadoop-ozone/s3gateway
   mvn -Dtest=TestUgiFilter test
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai merged pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
adoroszlai merged pull request #2810:
URL: https://github.com/apache/ozone/pull/2810


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on a change in pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
adoroszlai commented on a change in pull request #2810:
URL: https://github.com/apache/ozone/pull/2810#discussion_r744975493



##########
File path: hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestUgiFilter.java
##########
@@ -0,0 +1,171 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.apache.hadoop.ozone.s3;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import java.time.LocalDate;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Collections;
+import java.io.IOException;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.s3.signature.*;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+
+import org.apache.hadoop.io.Text;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.apache.hadoop.ozone.s3.signature.SignatureProcessor.DATE_FORMATTER;
+
+/**
+ * Test class for @{@link UgiFilter}.
+ */
+public class TestUgiFilter {
+
+  private OzoneConfiguration conf;
+  private String s3HttpAddr;
+  private Text omService;
+  private String curDate;
+  private Map<String, String> headers;
+  private Map<String, String[]> parameters;
+
+  private static final String HOST_HEADER = "Host";
+  private static final String ENCODE_HEADER = "Accept-Encoding";
+  private static final String USER_AGENT_HEADER = "User-Agent";
+  private static final String DATE_HEADER = "X-Amz-Date";
+  private static final String ENCRYPT_TYPE_HEADER = "X-Amz-Content-SHA256";
+  private static final String AUTHORIZATION_HEADER = "Authorization";
+  private static final String LENGTH_HEADER = "Content-Length";
+
+  @Before
+  public void setup() {
+    conf = new OzoneConfiguration();
+    s3HttpAddr = "localhost:9878";
+    conf.set(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY, s3HttpAddr);
+    s3HttpAddr = s3HttpAddr.substring(0, s3HttpAddr.lastIndexOf(":"));
+    conf.set(S3GatewayConfigKeys.OZONE_S3G_DOMAIN_NAME, s3HttpAddr);
+    omService = new Text("127.0.0.1:9862");
+    LocalDate now = LocalDate.now();
+    curDate = DATE_FORMATTER.format(now);
+
+    headers = new HashMap<>();
+    parameters = new HashMap<>();
+
+    headers.put(HOST_HEADER, "localhost:9878");
+    headers.put(ENCODE_HEADER, "identity");
+    headers.put(USER_AGENT_HEADER, "aws-cli/2.1.29 "+
+        "Python/3.8.8 Linux/4.15.0-144-generic "+
+        "exe/x86_64.ubuntu.18 prompt/off "+
+        "command/s3api.create-bucket");
+    headers.put(DATE_HEADER, "20210616T195044Z");
+    headers.put(ENCRYPT_TYPE_HEADER,
+        "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+    headers.put(AUTHORIZATION_HEADER, "AWS4-HMAC-SHA256 "+
+        "Credential=AKIAIIIE56NH5ZHKLTWQ/20210616/us-east-1/s3/aws4_request, "+
+        "SignedHeaders=host;x-amz-content-sha256;x-amz-date, "+
+        "Signature=c29b4c46e825d5df56cdde12a61adfa65560a54"+
+        "7c8973b9809621086727a2f2e");
+    headers.put(LENGTH_HEADER, "0");
+
+  }
+
+  @Test
+  public void testUgiFilterDoFilter() throws IOException, ServletException {
+    UgiFilter filter = new UgiFilter();
+    filter.setOzoneConfiguration(this.conf);
+    filter.setOmService(this.omService);
+
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+    FilterChain filterChain = Mockito.mock(FilterChain.class);
+    FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
+
+    // correct date in autherization header for AuthorizationV4QueryParser
+    // date validator
+    headers.put(AUTHORIZATION_HEADER, headers.
+        get(AUTHORIZATION_HEADER).replace("20210616", curDate));
+    Enumeration<String> headerNames = Collections.enumeration(headers.keySet());
+
+    Mockito.when(request.getScheme()).thenReturn("http");
+    Mockito.when(request.getMethod()).thenReturn("PUT");
+    Mockito.when(request.getPathInfo()).thenReturn("/bucket1");
+    Mockito.when(request.getHeaderNames()).thenReturn(headerNames);
+    Mockito.when(request.getHeader(HOST_HEADER)).thenReturn(
+        headers.get(HOST_HEADER));
+    Mockito.when(request.getHeader(ENCODE_HEADER)).thenReturn(
+        headers.get(ENCODE_HEADER));
+    Mockito.when(request.getHeader(USER_AGENT_HEADER)).thenReturn(
+        headers.get(USER_AGENT_HEADER));
+    Mockito.when(request.getHeader(DATE_HEADER)).thenReturn(
+        headers.get(DATE_HEADER));
+    Mockito.when(request.getHeader(ENCRYPT_TYPE_HEADER)).thenReturn(
+        headers.get(ENCRYPT_TYPE_HEADER));
+    Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn(
+        headers.get(AUTHORIZATION_HEADER));
+    Mockito.when(request.getHeader(LENGTH_HEADER)).thenReturn(
+        headers.get(LENGTH_HEADER));
+    Mockito.when(request.getParameterMap()).thenReturn(parameters);
+
+    filter.init(filterConfig);
+    filter.doFilter(request, response, filterChain);
+    filter.destroy();
+  }

Review comment:
       Can you please help me understand what is being asserted here?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on a change in pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
adoroszlai commented on a change in pull request #2810:
URL: https://github.com/apache/ozone/pull/2810#discussion_r745439164



##########
File path: hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestUgiFilter.java
##########
@@ -0,0 +1,171 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.apache.hadoop.ozone.s3;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import java.time.LocalDate;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Collections;
+import java.io.IOException;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.s3.signature.*;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+
+import org.apache.hadoop.io.Text;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.apache.hadoop.ozone.s3.signature.SignatureProcessor.DATE_FORMATTER;
+
+/**
+ * Test class for @{@link UgiFilter}.
+ */
+public class TestUgiFilter {
+
+  private OzoneConfiguration conf;
+  private String s3HttpAddr;
+  private Text omService;
+  private String curDate;
+  private Map<String, String> headers;
+  private Map<String, String[]> parameters;
+
+  private static final String HOST_HEADER = "Host";
+  private static final String ENCODE_HEADER = "Accept-Encoding";
+  private static final String USER_AGENT_HEADER = "User-Agent";
+  private static final String DATE_HEADER = "X-Amz-Date";
+  private static final String ENCRYPT_TYPE_HEADER = "X-Amz-Content-SHA256";
+  private static final String AUTHORIZATION_HEADER = "Authorization";
+  private static final String LENGTH_HEADER = "Content-Length";
+
+  @Before
+  public void setup() {
+    conf = new OzoneConfiguration();
+    s3HttpAddr = "localhost:9878";
+    conf.set(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY, s3HttpAddr);
+    s3HttpAddr = s3HttpAddr.substring(0, s3HttpAddr.lastIndexOf(":"));
+    conf.set(S3GatewayConfigKeys.OZONE_S3G_DOMAIN_NAME, s3HttpAddr);
+    omService = new Text("127.0.0.1:9862");
+    LocalDate now = LocalDate.now();
+    curDate = DATE_FORMATTER.format(now);
+
+    headers = new HashMap<>();
+    parameters = new HashMap<>();
+
+    headers.put(HOST_HEADER, "localhost:9878");
+    headers.put(ENCODE_HEADER, "identity");
+    headers.put(USER_AGENT_HEADER, "aws-cli/2.1.29 "+
+        "Python/3.8.8 Linux/4.15.0-144-generic "+
+        "exe/x86_64.ubuntu.18 prompt/off "+
+        "command/s3api.create-bucket");
+    headers.put(DATE_HEADER, "20210616T195044Z");
+    headers.put(ENCRYPT_TYPE_HEADER,
+        "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+    headers.put(AUTHORIZATION_HEADER, "AWS4-HMAC-SHA256 "+
+        "Credential=AKIAIIIE56NH5ZHKLTWQ/20210616/us-east-1/s3/aws4_request, "+
+        "SignedHeaders=host;x-amz-content-sha256;x-amz-date, "+
+        "Signature=c29b4c46e825d5df56cdde12a61adfa65560a54"+
+        "7c8973b9809621086727a2f2e");
+    headers.put(LENGTH_HEADER, "0");
+
+  }
+
+  @Test
+  public void testUgiFilterDoFilter() throws IOException, ServletException {
+    UgiFilter filter = new UgiFilter();
+    filter.setOzoneConfiguration(this.conf);
+    filter.setOmService(this.omService);
+
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+    FilterChain filterChain = Mockito.mock(FilterChain.class);
+    FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
+
+    // correct date in autherization header for AuthorizationV4QueryParser
+    // date validator
+    headers.put(AUTHORIZATION_HEADER, headers.
+        get(AUTHORIZATION_HEADER).replace("20210616", curDate));
+    Enumeration<String> headerNames = Collections.enumeration(headers.keySet());
+
+    Mockito.when(request.getScheme()).thenReturn("http");
+    Mockito.when(request.getMethod()).thenReturn("PUT");
+    Mockito.when(request.getPathInfo()).thenReturn("/bucket1");
+    Mockito.when(request.getHeaderNames()).thenReturn(headerNames);
+    Mockito.when(request.getHeader(HOST_HEADER)).thenReturn(
+        headers.get(HOST_HEADER));
+    Mockito.when(request.getHeader(ENCODE_HEADER)).thenReturn(
+        headers.get(ENCODE_HEADER));
+    Mockito.when(request.getHeader(USER_AGENT_HEADER)).thenReturn(
+        headers.get(USER_AGENT_HEADER));
+    Mockito.when(request.getHeader(DATE_HEADER)).thenReturn(
+        headers.get(DATE_HEADER));
+    Mockito.when(request.getHeader(ENCRYPT_TYPE_HEADER)).thenReturn(
+        headers.get(ENCRYPT_TYPE_HEADER));
+    Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn(
+        headers.get(AUTHORIZATION_HEADER));
+    Mockito.when(request.getHeader(LENGTH_HEADER)).thenReturn(
+        headers.get(LENGTH_HEADER));
+    Mockito.when(request.getParameterMap()).thenReturn(parameters);
+
+    filter.init(filterConfig);
+    filter.doFilter(request, response, filterChain);
+    filter.destroy();
+  }

Review comment:
       Thanks.  Would it make sense to add one or more other test cases where the filter is expected to reject the request(s)?  I guess the current test would pass even with a no-op filter.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on a change in pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
adoroszlai commented on a change in pull request #2810:
URL: https://github.com/apache/ozone/pull/2810#discussion_r758677306



##########
File path: hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestUgiFilter.java
##########
@@ -125,28 +117,78 @@ public void testUgiFilterDoFilter() throws IOException, ServletException {
         headers.get(DATE_HEADER));
     Mockito.when(request.getHeader(ENCRYPT_TYPE_HEADER)).thenReturn(
         headers.get(ENCRYPT_TYPE_HEADER));
-    Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn(
-        headers.get(AUTHORIZATION_HEADER));
+    Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenAnswer(
+        invocation -> headers.get(AUTHORIZATION_HEADER));
     Mockito.when(request.getHeader(LENGTH_HEADER)).thenReturn(
         headers.get(LENGTH_HEADER));
     Mockito.when(request.getParameterMap()).thenReturn(parameters);
 
-    filter.init(filterConfig);
-    filter.doFilter(request, response, filterChain);
-    filter.destroy();
+    // Should generate exception because of incorrect date
+    try {
+      filter.init(filterConfig);
+      filter.doFilter(request, response, filterChain);
+      filter.destroy();
+      Assert.fail("Filter should generate OS3 exception.");
+    } catch(Exception e) {
+      Assert.assertTrue(e.getCause() instanceof OS3Exception);
+    }
+
+    // correct date in authorization header for AuthorizationV4QueryParser
+    // date validator
+    headers.put(AUTHORIZATION_HEADER, headers.
+        get(AUTHORIZATION_HEADER).replace("20210616", curDate));
+
+
+    // Should not generate exception because of corrected date

Review comment:
       Nit: adding each test case in a separate method would be cleaner.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] GeorgeJahad commented on a change in pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
GeorgeJahad commented on a change in pull request #2810:
URL: https://github.com/apache/ozone/pull/2810#discussion_r758992919



##########
File path: hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestUgiFilter.java
##########
@@ -125,28 +117,78 @@ public void testUgiFilterDoFilter() throws IOException, ServletException {
         headers.get(DATE_HEADER));
     Mockito.when(request.getHeader(ENCRYPT_TYPE_HEADER)).thenReturn(
         headers.get(ENCRYPT_TYPE_HEADER));
-    Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn(
-        headers.get(AUTHORIZATION_HEADER));
+    Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenAnswer(
+        invocation -> headers.get(AUTHORIZATION_HEADER));
     Mockito.when(request.getHeader(LENGTH_HEADER)).thenReturn(
         headers.get(LENGTH_HEADER));
     Mockito.when(request.getParameterMap()).thenReturn(parameters);
 
-    filter.init(filterConfig);
-    filter.doFilter(request, response, filterChain);
-    filter.destroy();
+    // Should generate exception because of incorrect date
+    try {
+      filter.init(filterConfig);
+      filter.doFilter(request, response, filterChain);
+      filter.destroy();
+      Assert.fail("Filter should generate OS3 exception.");
+    } catch(Exception e) {
+      Assert.assertTrue(e.getCause() instanceof OS3Exception);
+    }
+
+    // correct date in authorization header for AuthorizationV4QueryParser
+    // date validator
+    headers.put(AUTHORIZATION_HEADER, headers.
+        get(AUTHORIZATION_HEADER).replace("20210616", curDate));
+
+
+    // Should not generate exception because of corrected date

Review comment:
       ok, @adoroszlai I split them up.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] GeorgeJahad commented on a change in pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
GeorgeJahad commented on a change in pull request #2810:
URL: https://github.com/apache/ozone/pull/2810#discussion_r745221003



##########
File path: hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestUgiFilter.java
##########
@@ -0,0 +1,171 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.apache.hadoop.ozone.s3;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import java.time.LocalDate;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Collections;
+import java.io.IOException;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.s3.signature.*;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+
+import org.apache.hadoop.io.Text;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.apache.hadoop.ozone.s3.signature.SignatureProcessor.DATE_FORMATTER;
+
+/**
+ * Test class for @{@link UgiFilter}.
+ */
+public class TestUgiFilter {
+
+  private OzoneConfiguration conf;
+  private String s3HttpAddr;
+  private Text omService;
+  private String curDate;
+  private Map<String, String> headers;
+  private Map<String, String[]> parameters;
+
+  private static final String HOST_HEADER = "Host";
+  private static final String ENCODE_HEADER = "Accept-Encoding";
+  private static final String USER_AGENT_HEADER = "User-Agent";
+  private static final String DATE_HEADER = "X-Amz-Date";
+  private static final String ENCRYPT_TYPE_HEADER = "X-Amz-Content-SHA256";
+  private static final String AUTHORIZATION_HEADER = "Authorization";
+  private static final String LENGTH_HEADER = "Content-Length";
+
+  @Before
+  public void setup() {
+    conf = new OzoneConfiguration();
+    s3HttpAddr = "localhost:9878";
+    conf.set(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY, s3HttpAddr);
+    s3HttpAddr = s3HttpAddr.substring(0, s3HttpAddr.lastIndexOf(":"));
+    conf.set(S3GatewayConfigKeys.OZONE_S3G_DOMAIN_NAME, s3HttpAddr);
+    omService = new Text("127.0.0.1:9862");
+    LocalDate now = LocalDate.now();
+    curDate = DATE_FORMATTER.format(now);
+
+    headers = new HashMap<>();
+    parameters = new HashMap<>();
+
+    headers.put(HOST_HEADER, "localhost:9878");
+    headers.put(ENCODE_HEADER, "identity");
+    headers.put(USER_AGENT_HEADER, "aws-cli/2.1.29 "+
+        "Python/3.8.8 Linux/4.15.0-144-generic "+
+        "exe/x86_64.ubuntu.18 prompt/off "+
+        "command/s3api.create-bucket");
+    headers.put(DATE_HEADER, "20210616T195044Z");
+    headers.put(ENCRYPT_TYPE_HEADER,
+        "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+    headers.put(AUTHORIZATION_HEADER, "AWS4-HMAC-SHA256 "+
+        "Credential=AKIAIIIE56NH5ZHKLTWQ/20210616/us-east-1/s3/aws4_request, "+
+        "SignedHeaders=host;x-amz-content-sha256;x-amz-date, "+
+        "Signature=c29b4c46e825d5df56cdde12a61adfa65560a54"+
+        "7c8973b9809621086727a2f2e");
+    headers.put(LENGTH_HEADER, "0");
+
+  }
+
+  @Test
+  public void testUgiFilterDoFilter() throws IOException, ServletException {
+    UgiFilter filter = new UgiFilter();
+    filter.setOzoneConfiguration(this.conf);
+    filter.setOmService(this.omService);
+
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+    FilterChain filterChain = Mockito.mock(FilterChain.class);
+    FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
+
+    // correct date in autherization header for AuthorizationV4QueryParser
+    // date validator
+    headers.put(AUTHORIZATION_HEADER, headers.
+        get(AUTHORIZATION_HEADER).replace("20210616", curDate));
+    Enumeration<String> headerNames = Collections.enumeration(headers.keySet());
+
+    Mockito.when(request.getScheme()).thenReturn("http");
+    Mockito.when(request.getMethod()).thenReturn("PUT");
+    Mockito.when(request.getPathInfo()).thenReturn("/bucket1");
+    Mockito.when(request.getHeaderNames()).thenReturn(headerNames);
+    Mockito.when(request.getHeader(HOST_HEADER)).thenReturn(
+        headers.get(HOST_HEADER));
+    Mockito.when(request.getHeader(ENCODE_HEADER)).thenReturn(
+        headers.get(ENCODE_HEADER));
+    Mockito.when(request.getHeader(USER_AGENT_HEADER)).thenReturn(
+        headers.get(USER_AGENT_HEADER));
+    Mockito.when(request.getHeader(DATE_HEADER)).thenReturn(
+        headers.get(DATE_HEADER));
+    Mockito.when(request.getHeader(ENCRYPT_TYPE_HEADER)).thenReturn(
+        headers.get(ENCRYPT_TYPE_HEADER));
+    Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn(
+        headers.get(AUTHORIZATION_HEADER));
+    Mockito.when(request.getHeader(LENGTH_HEADER)).thenReturn(
+        headers.get(LENGTH_HEADER));
+    Mockito.when(request.getParameterMap()).thenReturn(parameters);
+
+    filter.init(filterConfig);
+    filter.doFilter(request, response, filterChain);
+    filter.destroy();
+  }

Review comment:
       @adoroszlai I reviewed with @neils-dev and confirmed that there was an assert missing which I've added.  Thanks for noticing!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] GeorgeJahad commented on a change in pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
GeorgeJahad commented on a change in pull request #2810:
URL: https://github.com/apache/ozone/pull/2810#discussion_r750868364



##########
File path: hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestUgiFilter.java
##########
@@ -0,0 +1,171 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.apache.hadoop.ozone.s3;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import java.time.LocalDate;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Collections;
+import java.io.IOException;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.s3.signature.*;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+
+import org.apache.hadoop.io.Text;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.apache.hadoop.ozone.s3.signature.SignatureProcessor.DATE_FORMATTER;
+
+/**
+ * Test class for @{@link UgiFilter}.
+ */
+public class TestUgiFilter {
+
+  private OzoneConfiguration conf;
+  private String s3HttpAddr;
+  private Text omService;
+  private String curDate;
+  private Map<String, String> headers;
+  private Map<String, String[]> parameters;
+
+  private static final String HOST_HEADER = "Host";
+  private static final String ENCODE_HEADER = "Accept-Encoding";
+  private static final String USER_AGENT_HEADER = "User-Agent";
+  private static final String DATE_HEADER = "X-Amz-Date";
+  private static final String ENCRYPT_TYPE_HEADER = "X-Amz-Content-SHA256";
+  private static final String AUTHORIZATION_HEADER = "Authorization";
+  private static final String LENGTH_HEADER = "Content-Length";
+
+  @Before
+  public void setup() {
+    conf = new OzoneConfiguration();
+    s3HttpAddr = "localhost:9878";
+    conf.set(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY, s3HttpAddr);
+    s3HttpAddr = s3HttpAddr.substring(0, s3HttpAddr.lastIndexOf(":"));
+    conf.set(S3GatewayConfigKeys.OZONE_S3G_DOMAIN_NAME, s3HttpAddr);
+    omService = new Text("127.0.0.1:9862");
+    LocalDate now = LocalDate.now();
+    curDate = DATE_FORMATTER.format(now);
+
+    headers = new HashMap<>();
+    parameters = new HashMap<>();
+
+    headers.put(HOST_HEADER, "localhost:9878");
+    headers.put(ENCODE_HEADER, "identity");
+    headers.put(USER_AGENT_HEADER, "aws-cli/2.1.29 "+
+        "Python/3.8.8 Linux/4.15.0-144-generic "+
+        "exe/x86_64.ubuntu.18 prompt/off "+
+        "command/s3api.create-bucket");
+    headers.put(DATE_HEADER, "20210616T195044Z");
+    headers.put(ENCRYPT_TYPE_HEADER,
+        "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+    headers.put(AUTHORIZATION_HEADER, "AWS4-HMAC-SHA256 "+
+        "Credential=AKIAIIIE56NH5ZHKLTWQ/20210616/us-east-1/s3/aws4_request, "+
+        "SignedHeaders=host;x-amz-content-sha256;x-amz-date, "+
+        "Signature=c29b4c46e825d5df56cdde12a61adfa65560a54"+
+        "7c8973b9809621086727a2f2e");
+    headers.put(LENGTH_HEADER, "0");
+
+  }
+
+  @Test
+  public void testUgiFilterDoFilter() throws IOException, ServletException {
+    UgiFilter filter = new UgiFilter();
+    filter.setOzoneConfiguration(this.conf);
+    filter.setOmService(this.omService);
+
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+    FilterChain filterChain = Mockito.mock(FilterChain.class);
+    FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
+
+    // correct date in autherization header for AuthorizationV4QueryParser
+    // date validator
+    headers.put(AUTHORIZATION_HEADER, headers.
+        get(AUTHORIZATION_HEADER).replace("20210616", curDate));
+    Enumeration<String> headerNames = Collections.enumeration(headers.keySet());
+
+    Mockito.when(request.getScheme()).thenReturn("http");
+    Mockito.when(request.getMethod()).thenReturn("PUT");
+    Mockito.when(request.getPathInfo()).thenReturn("/bucket1");
+    Mockito.when(request.getHeaderNames()).thenReturn(headerNames);
+    Mockito.when(request.getHeader(HOST_HEADER)).thenReturn(
+        headers.get(HOST_HEADER));
+    Mockito.when(request.getHeader(ENCODE_HEADER)).thenReturn(
+        headers.get(ENCODE_HEADER));
+    Mockito.when(request.getHeader(USER_AGENT_HEADER)).thenReturn(
+        headers.get(USER_AGENT_HEADER));
+    Mockito.when(request.getHeader(DATE_HEADER)).thenReturn(
+        headers.get(DATE_HEADER));
+    Mockito.when(request.getHeader(ENCRYPT_TYPE_HEADER)).thenReturn(
+        headers.get(ENCRYPT_TYPE_HEADER));
+    Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn(
+        headers.get(AUTHORIZATION_HEADER));
+    Mockito.when(request.getHeader(LENGTH_HEADER)).thenReturn(
+        headers.get(LENGTH_HEADER));
+    Mockito.when(request.getParameterMap()).thenReturn(parameters);
+
+    filter.init(filterConfig);
+    filter.doFilter(request, response, filterChain);
+    filter.destroy();
+  }

Review comment:
       More tests added @adoroszlai  Sorry it took so long.
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] GeorgeJahad commented on pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
GeorgeJahad commented on pull request #2810:
URL: https://github.com/apache/ozone/pull/2810#issuecomment-984006786


   @adoroszlai since you've approved this pr and the ci tests succeeded, would you be able to merge this into the feature branch? or is there something else that should be done?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on pull request #2810: HDDS-5778. Client side unit tests

Posted by GitBox <gi...@apache.org>.
adoroszlai commented on pull request #2810:
URL: https://github.com/apache/ozone/pull/2810#issuecomment-984027902


   Thanks @GeorgeJahad and @neils-dev for the patch.
   
   > ci tests succeeded
   
   Thanks for the reminder.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org