yandrey321 commented on code in PR #12114:
URL: https://github.com/apache/ozone/pull/12114#discussion_r4675284840
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/x509/certificate/utils/TestCertificateSignRequest.java:
##########
@@ -270,6 +283,66 @@ public void testCsrSerialization() throws Exception {
assertEquals(csr, dsCsr);
}
+ @Test
+ public void testDistinguishedNameEncodingUnchanged() throws Exception {
+ String clusterID = UUID.randomUUID().toString();
+ String scmID = UUID.randomUUID().toString();
+ String subject = "[email protected]";
+
+ assertArrayEquals(
+ new X500Name(String.format(DISTINGUISHED_NAME_FORMAT, subject, scmID,
clusterID)).getEncoded(),
+ getDistinguishedName(subject, scmID, clusterID).getEncoded());
+ assertArrayEquals(
+ new X500Name(String.format(DISTINGUISHED_NAME_WITH_SN_FORMAT, subject,
scmID, clusterID, "12345"))
+ .getEncoded(),
+ getDistinguishedNameWithSN(subject, scmID, clusterID,
"12345").getEncoded());
+ // A datanode sends null SCM and cluster IDs before registration.
+ assertArrayEquals(
+ new X500Name(String.format(DISTINGUISHED_NAME_FORMAT, subject, null,
null)).getEncoded(),
+ getDistinguishedName(subject, null, null).getEncoded());
+ }
+
+ @Test
+ public void testCommonName() {
+ String id = UUID.randomUUID().toString();
+ String fits = "dn@" + StringUtils.repeat('a', 61);
+ assertEquals(64, fits.length());
+ assertEquals(fits, CertificateSignRequest.commonName(fits, "dn", id));
+ // one character too long, and a long user@FQDN: the same prefix@id,
whatever the host names have in common
+ assertEquals("dn@" + id, CertificateSignRequest.commonName(fits + "b",
"dn", id));
+ assertEquals("dn@" + id, CertificateSignRequest.commonName(LONG_SUBJECT,
"dn", id));
+
+ assertEquals("dn",
CertificateSignRequest.commonNamePrefix(NodeType.DATANODE));
+ assertEquals("om", CertificateSignRequest.commonNamePrefix(NodeType.OM));
+ assertEquals("recon",
CertificateSignRequest.commonNamePrefix(NodeType.RECON));
+ assertEquals(OzoneConsts.SCM_SUB_CA,
CertificateSignRequest.commonNamePrefix(NodeType.SCM));
+ }
+
+ @Test
+ public void testGenerateCSRWithLongSubject() throws Exception {
+ String clusterID = UUID.randomUUID().toString();
+ String scmID = UUID.randomUUID().toString();
+ assertThat(LONG_SUBJECT.length()).isGreaterThan(64);
Review Comment:
Done. The test now asserts that new X500Name(String) accepts a 64-character
CN, and throws IllegalArgumentException for 65 characters and for LONG_SUBJECT.
That pins the Bouncy Castle behavior the typed builder works around, so a
Bouncy Castle change will show up here. The same 64/65 boundary for
CertificateSignRequest.commonName is checked in testCommonName.
--
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]