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/05/03 18:08:23 UTC

[GitHub] [ozone] avijayanhwx commented on a change in pull request #2200: HDDS-5165. OM DB checkpoint servlet not accessible in a secure cluster

avijayanhwx commented on a change in pull request #2200:
URL: https://github.com/apache/ozone/pull/2200#discussion_r625267090



##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
##########
@@ -83,114 +89,184 @@
    * <p>
    * Ozone is made active by setting OZONE_ENABLED = true
    *
-   * @throws IOException
+   * @throws Exception
    */
   @BeforeClass
   public static void init() throws Exception {
     conf = new OzoneConfiguration();
-    clusterId = UUID.randomUUID().toString();
-    scmId = UUID.randomUUID().toString();
-    omId = UUID.randomUUID().toString();
-    conf.setBoolean(OZONE_ACL_ENABLED, false);
-    conf.set(OZONE_ADMINISTRATORS, OZONE_ADMINISTRATORS_WILDCARD);
-    conf.setInt(OZONE_OPEN_KEY_EXPIRE_THRESHOLD_SECONDS, 2);
-    cluster = MiniOzoneCluster.newBuilder(conf)
-        .setClusterId(clusterId)
-        .setScmId(scmId)
-        .setOmId(omId)
-        .setNumDatanodes(1)
-        .build();
-    cluster.waitForClusterToBeReady();
-    omMetrics = cluster.getOzoneManager().getMetrics();
+
+    tempFile = File.createTempFile("testDoGet_" + System
+        .currentTimeMillis(), ".tar.gz");
+
+    FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
+
+    servletOutputStream = new ServletOutputStream() {
+      @Override
+      public boolean isReady() {
+        return true;
+      }
+
+      @Override
+      public void setWriteListener(WriteListener writeListener) {
+      }
+
+      @Override
+      public void write(int b) throws IOException {
+        fileOutputStream.write(b);
+      }
+    };
   }
 
   /**
    * Shutdown MiniDFSCluster.
    */
   @AfterClass
-  public static void shutdown() {
+  public static void shutdown() throws InterruptedException {
     if (cluster != null) {
       cluster.shutdown();
     }
+    FileUtils.deleteQuietly(tempFile);
   }
 
   @Test
-  public void testDoGet() throws ServletException, IOException {
-    File tempFile = null;
-    try {
-      OMDBCheckpointServlet omDbCheckpointServletMock =
-          mock(OMDBCheckpointServlet.class);
-
-      final OzoneManager om = cluster.getOzoneManager();
-
-      doCallRealMethod().when(omDbCheckpointServletMock).init();
-      doCallRealMethod().when(omDbCheckpointServletMock).initialize(
-          om.getMetadataManager().getStore(),
-          om.getMetrics().getDBCheckpointMetrics(),
-          om.getAclsEnabled(),
-          om.getOzoneAdmins(om.getConfiguration()));
-
-      HttpServletRequest requestMock = mock(HttpServletRequest.class);
-      // Return current user short name when asked
-      when(requestMock.getRemoteUser())
-          .thenReturn(UserGroupInformation.getCurrentUser().getShortUserName());
-      HttpServletResponse responseMock = mock(HttpServletResponse.class);
-
-      ServletContext servletContextMock = mock(ServletContext.class);
-      when(omDbCheckpointServletMock.getServletContext())
-          .thenReturn(servletContextMock);
-
-      when(servletContextMock.getAttribute(OzoneConsts.OM_CONTEXT_ATTRIBUTE))
-          .thenReturn(cluster.getOzoneManager());
-      when(requestMock.getParameter(OZONE_DB_CHECKPOINT_REQUEST_FLUSH))
-          .thenReturn("true");
-      doNothing().when(responseMock).setContentType("application/x-tgz");
-      doNothing().when(responseMock).setHeader(Matchers.anyString(),
-          Matchers.anyString());
-
-      tempFile = File.createTempFile("testDoGet_" + System
-          .currentTimeMillis(), ".tar.gz");
-
-      FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
-      when(responseMock.getOutputStream()).thenReturn(
-          new ServletOutputStream() {
-            @Override
-            public boolean isReady() {
-              return true;
-            }
-
-            @Override
-            public void setWriteListener(WriteListener writeListener) {
-            }
-
-            @Override
-            public void write(int b) throws IOException {
-              fileOutputStream.write(b);
-            }
-          });
-
-      doCallRealMethod().when(omDbCheckpointServletMock).doGet(requestMock,
-          responseMock);
-
-      omDbCheckpointServletMock.init();
-      long initialCheckpointCount =
-          omMetrics.getDBCheckpointMetrics().getNumCheckpoints();
-
-      omDbCheckpointServletMock.doGet(requestMock, responseMock);
-
-      Assert.assertTrue(tempFile.length() > 0);
-      Assert.assertTrue(
-          omMetrics.getDBCheckpointMetrics().
-              getLastCheckpointCreationTimeTaken() > 0);
-      Assert.assertTrue(
-          omMetrics.getDBCheckpointMetrics().
-              getLastCheckpointStreamingTimeTaken() > 0);
-      Assert.assertTrue(omMetrics.getDBCheckpointMetrics().
-          getNumCheckpoints() > initialCheckpointCount);
-    } finally {
-      FileUtils.deleteQuietly(tempFile);
-    }
+  public void testDoGet() throws Exception {
+    conf.setBoolean(OZONE_ACL_ENABLED, false);
+    conf.set(OZONE_ADMINISTRATORS, OZONE_ADMINISTRATORS_WILDCARD);
+    conf.setInt(OZONE_OPEN_KEY_EXPIRE_THRESHOLD_SECONDS, 2);
+    cluster = MiniOzoneCluster.newBuilder(conf)
+        .setNumDatanodes(1)
+        .build();
+    cluster.waitForClusterToBeReady();
+    OMMetrics omMetrics = cluster.getOzoneManager().getMetrics();
+
+    OMDBCheckpointServlet omDbCheckpointServletMock =
+        mock(OMDBCheckpointServlet.class);
+
+    final OzoneManager om = cluster.getOzoneManager();
+
+    doCallRealMethod().when(omDbCheckpointServletMock).init();
+    doCallRealMethod().when(omDbCheckpointServletMock).initialize(
+        om.getMetadataManager().getStore(),
+        om.getMetrics().getDBCheckpointMetrics(),
+        om.getAclsEnabled(),
+        om.getOzoneAdmins(om.getConfiguration()),
+        om.isSpnegoEnabled(),
+        om.getConfiguration());
+
+    HttpServletRequest requestMock = mock(HttpServletRequest.class);
+    // Return current user short name when asked
+    when(requestMock.getRemoteUser())
+        .thenReturn(UserGroupInformation.getCurrentUser().getShortUserName());
+    HttpServletResponse responseMock = mock(HttpServletResponse.class);
+
+    ServletContext servletContextMock = mock(ServletContext.class);
+    when(omDbCheckpointServletMock.getServletContext())
+        .thenReturn(servletContextMock);
+
+    when(servletContextMock.getAttribute(OzoneConsts.OM_CONTEXT_ATTRIBUTE))
+        .thenReturn(cluster.getOzoneManager());
+    when(requestMock.getParameter(OZONE_DB_CHECKPOINT_REQUEST_FLUSH))
+        .thenReturn("true");
+    doNothing().when(responseMock).setContentType("application/x-tgz");
+    doNothing().when(responseMock).setHeader(Matchers.anyString(),
+        Matchers.anyString());
+
+    when(responseMock.getOutputStream()).thenReturn(servletOutputStream);
+
+    doCallRealMethod().when(omDbCheckpointServletMock).doGet(requestMock,
+        responseMock);
+
+    omDbCheckpointServletMock.init();
+    long initialCheckpointCount =
+        omMetrics.getDBCheckpointMetrics().getNumCheckpoints();
+
+    omDbCheckpointServletMock.doGet(requestMock, responseMock);
+
+    Assert.assertTrue(tempFile.length() > 0);
+    Assert.assertTrue(
+        omMetrics.getDBCheckpointMetrics().
+            getLastCheckpointCreationTimeTaken() > 0);
+    Assert.assertTrue(
+        omMetrics.getDBCheckpointMetrics().
+            getLastCheckpointStreamingTimeTaken() > 0);
+    Assert.assertTrue(omMetrics.getDBCheckpointMetrics().
+        getNumCheckpoints() > initialCheckpointCount);
+  }
+
+  @Test
+  public void testSpnegoEnabled() throws Exception {
+    cluster.shutdown();
+    conf.setBoolean(OZONE_ACL_ENABLED, true);
+    conf.set(OZONE_ADMINISTRATORS, "");
+    conf.set(OZONE_OM_HTTP_AUTH_TYPE, "kerberos");
+    conf.set(OZONE_RECON_KERBEROS_PRINCIPAL_KEY, "recon/host1@REALM");

Review comment:
       There seems to be some common code between the 2 tests. Can they be moved to common method?




-- 
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.

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