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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to