smengcl commented on code in PR #12114:
URL: https://github.com/apache/ozone/pull/12114#discussion_r4676309258


##########
hadoop-ozone/cli-repair/src/main/java/org/apache/hadoop/ozone/repair/scm/cert/RecoverSCMCertificate.java:
##########
@@ -149,12 +148,32 @@ private static X509Certificate getRootCertificate(
     return cert.get();
   }
 
-  private static X509Certificate getSubCertificate(
-      Map<BigInteger, X509Certificate> allCerts, String hostName) throws 
Exception {
+  /** This SCM's ID, or null if its storage cannot be read: then certificates 
are only matched by host name. */
+  private String getScmId() {
+    try {
+      return new SCMStorageConfig(getOzoneConf()).getScmId();
+    } catch (IOException e) {
+      error("Failed to read the SCM ID, matching certificates by host name 
only: %s", e.getMessage());
+      return null;
+    }
+  }
+
+  /** Whether this SCM issued {@code rootCertificate}: its subject has this 
host name or, if longer, this SCM ID. */
+  @VisibleForTesting

Review Comment:
   nit: package-private access is enough for the test, so the 
`@VisibleForTesting` annotations (and the import) can be dropped.



##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/x509/certificate/utils/CsrTestUtil.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.hdds.security.x509.certificate.utils;
+
+import java.io.IOException;
+import 
org.apache.hadoop.hdds.security.x509.certificate.client.DefaultCertificateClient;
+import org.bouncycastle.asn1.x500.style.BCStyle;
+
+/**
+ * Helpers for tests of certificate signing requests, so that tests in other 
modules do not use Bouncy Castle.
+ */
+public final class CsrTestUtil {
+
+  private CsrTestUtil() {
+  }
+
+  /** @return the commonName in the subject of the CSR that {@code client} 
builds. */
+  public static String getCsrCommonName(DefaultCertificateClient client) 
throws IOException {

Review Comment:
   nit: the new tests repeat the same long host name literal 7 times 
(`aaaa-ozone-000-...svc.cluster.local`) and read the CN three ways: `LdapName` 
in `TestHASecurityUtils`, `X500Name` + `BCStyle` in `TestSCMCertificateClient` 
and others, and this helper. A `LONG_HOST_NAME` constant and a CN helper for 
certificates here would also let `TestHASecurityUtils#rootCaCommonName` and 
`TestSCMCertificateClient#rootCaCommonName` share code.



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