Gargi-jais11 commented on code in PR #9868:
URL: https://github.com/apache/ozone/pull/9868#discussion_r3049432656


##########
hadoop-ozone/cli-debug/src/test/java/org/apache/hadoop/ozone/debug/kerberos/TestOzoneDebugKerberos.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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
+ *
+ *      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.apache.hadoop.ozone.debug.kerberos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.ozone.debug.OzoneDebug;
+import org.apache.ozone.test.GenericTestUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for ozone kerberos debug subcommands.
+ */
+class TestOzoneDebugKerberos {
+
+  private GenericTestUtils.PrintStreamCapturer out;
+  private GenericTestUtils.PrintStreamCapturer err;
+
+  @BeforeEach
+  void init() {
+    out = GenericTestUtils.captureOut();
+    err = GenericTestUtils.captureErr();
+  }
+
+  @AfterEach
+  void cleanup() {
+    IOUtils.closeQuietly(out);
+    IOUtils.closeQuietly(err);
+    System.clearProperty("java.security.krb5.conf");
+  }
+
+  /**
+   * Test ozone debug kerberos diagnose.
+   */
+  @Test
+  void testDiagnoseSubcommandSuccess() {
+
+    int rc = executeDiagnose();
+    String stdOut = normalize(out.get());
+
+    assertThat(stdOut)
+        .contains("Ozone Kerberos Diagnostics")
+        .contains("-- Host Information --")
+        .contains("-- Environment Variables --")
+        .contains("-- JVM Kerberos Properties --")
+        .contains("-- Kerberos Configuration --")
+        .contains("-- Kerberos kinit Command --")
+        .contains("-- Keytab Validation --")
+        .contains("-- Kerberos Ticket --")
+        .contains("-- auth_to_local mapping --")
+        .contains("-- Ozone Service Principals --")
+        .contains("-- Security Configuration --")
+        .contains("-- Authorization Configuration --")
+        .contains("-- HTTP Kerberos Authentication --")
+        .contains("== Diagnostic Summary ==")
+        .contains("PASS :")
+        .contains("WARN :")
+        .contains("FAIL :");
+
+    assertThat(rc).isGreaterThanOrEqualTo(0);
+  }
+
+  /**
+   * Test ozone debug kerberos diagnose.
+   */
+  @Test
+  void testDiagnoseSubcommandFailure() {
+
+    // Force Kerberos failure
+    System.setProperty("java.security.krb5.conf", "/invalid/path");

Review Comment:
   I think you need to update the comment as `java.security.krb5.conf` is for 
jvm kerberos probe to fail and accordingly assertion should check for `-- JVM 
Kerberos Properties --` not Kerberos configuration.
   DiagnoseSubcommand prints a banner for every probe:
   So "-- Kerberos Configuration --" is always printed when that probe runs, 
whether it PASS, WARN, or FAIL.
   Asserting that string only proves “this section appeared,” not that 
KerberosConfigProbe was the thing that failed.
   So: the test works for “something Kerberos-related failed,” but the intent 
and assertions don’t match what really broke.



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