joseluisll commented on code in PR #8827:
URL: https://github.com/apache/hadoop/pull/8827#discussion_r4352733186


##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestSecurityUtil.java:
##########
@@ -630,4 +632,32 @@ public void testInvalidHostThrowsException() {
       qualifiedHostResolver.getByName(invalidHost);
     }, "Resolving an invalid host should throw UnknownHostException");
   }
+
+  /**
+   * A failure to get the login user with security enabled must go through
+   * {@link ExitUtil#terminate(int, Throwable)} rather than exiting the JVM
+   * directly.
+   */
+  @Test
+  public void testDoAsLoginUserOrFatalTerminatesOnLoginFailure() {
+    IOException loginFailure = new IOException("login failed");
+    ExitUtil.disableSystemExit();
+    ExitUtil.resetFirstExitException();
+    try (MockedStatic<UserGroupInformation> ugi =
+        Mockito.mockStatic(UserGroupInformation.class)) {
+      ugi.when(UserGroupInformation::isSecurityEnabled).thenReturn(true);
+      ugi.when(UserGroupInformation::getLoginUser).thenThrow(loginFailure);
+
+      ExitUtil.ExitException ee = assertThrows(ExitUtil.ExitException.class,
+          () -> SecurityUtil.doAsLoginUserOrFatal(() -> {
+            throw new AssertionError("action should not run");
+          }));
+      assertEquals(-1, ee.getExitCode());
+      assertSame(loginFailure, ee.getCause());
+      assertTrue(ExitUtil.terminateCalled());

Review Comment:
   Thanks @smengcl, dropped in c275d1487fb.



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