You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by GitBox <gi...@apache.org> on 2021/09/28 14:02:24 UTC

[GitHub] [ws-wss4j] free-ice commented on a change in pull request #41: Add wfc compat for 2 3 x

free-ice commented on a change in pull request #41:
URL: https://github.com/apache/ws-wss4j/pull/41#discussion_r717611144



##########
File path: ws-security-common/src/test/java/org/apache/wss4j/common/util/CommaDelimiterRfc2253NameTest.java
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.wss4j.common.util;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import javax.security.auth.x500.X500Principal;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.PKIXParameters;
+import java.security.cert.TrustAnchor;
+import java.security.cert.X509Certificate;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class CommaDelimiterRfc2253NameTest {
+
+	private static final String TYPICAL_CA ="CN=Entrust Certification Authority - L1K,OU=(c) 2012 Entrust\\, Inc. - for authorized use only,OU=See www.entrust.net/legal-terms,O=Entrust\\, Inc.,C=US";
+	private static final String QUOTES_TYPICAL_CA ="CN=Entrust Certification Authority - L1K, OU=\"(c) 2012 Entrust, Inc. - for authorized use only\", OU=See www.entrust.net/legal-terms, O=\"Entrust, Inc.\", C=US";
+
+	private CommaDelimiterRfc2253Name subject = new CommaDelimiterRfc2253Name();
+
+
+	@Test
+	void whenMultipleAttributesArePresentThenSpaceIsPlacedAfterComma() {
+		String actual = new CommaDelimiterRfc2253Name().execute("CN=EOIR,OU=Some Unit,DC=Another place");
+		assertEquals("CN=EOIR, OU=Some Unit, DC=Another place",actual);
+	}
+	@Test
+	void whenRdnContainsACommaThenTheRdnIsSurroundedByDoubleQuotes() {
+		String actual = new CommaDelimiterRfc2253Name().execute(TYPICAL_CA);
+		assertEquals(QUOTES_TYPICAL_CA,actual);
+	}
+
+	@Test
+	void whenRdnIsInvalidThenExpectException() {
+		Assertions.assertThrows(IllegalArgumentException.class, () -> {
+			subject.execute("invalid");
+		});
+	}
+
+
+	@Test
+	void whenCallingUnescapeWithStringNoEscapesThenNoChangesAreMade() throws Exception {
+		String input = "This is a string with (c) no escaped! sStrings $";
+		String actual = subject.unEscapeRfc2253RdnSubPart(input);
+		assertEquals(input,actual,"Expect that string is unchanged");
+	}
+
+
+	@Test
+	void whenCallingUnescapeWithStringThenItUnescapesAppropiateCharacters() throws Exception {
+		String input = "This is a string with escapes \\,\\; \\\\ and \\< then \\> \\\"Copyright Apache\\\" ";
+		String expected = "This is a string with escapes ,; \\ and < then > \"Copyright Apache\" ";
+		String actual = subject.unEscapeRfc2253RdnSubPart(input);
+		assertEquals(expected,actual,"Expect that string is unescaped");
+	}
+
+
+	@Test
+	void whenCallingUnescapeWithStringWithMultiValueRdnThenItUnescapesAppropriateCharacters() throws Exception {
+		String input = "OU=Sales\\+CN=J. Smith\\,O=Widget Inc.\\,C=US";
+		String expected = "OU=Sales+CN=J. Smith,O=Widget Inc.,C=US";
+		String actual = subject.unEscapeRfc2253RdnSubPart(input);
+		assertEquals(expected,actual,"Expect that string is unescaped");
+	}
+
+	@Test
+	public void testThatACommaDelimitedDnStringAndABackSlashEscapedDnProducesTheSameX509PrincipalUsingDefaultTruststore()
+			throws KeyStoreException, InvalidAlgorithmParameterException, CertificateException, NoSuchAlgorithmException, IOException {
+		KeyStore keystore = loadDefaultKeyStore();
+		assertAllCaTransformsAreEquivalent(keystore);
+	}
+
+	@Test
+	public void testThatACommaDelimitedDnStringAndABackSlashEscapedDnProducesTheSameX509Principal()
+			throws KeyStoreException, InvalidAlgorithmParameterException, CertificateException, NoSuchAlgorithmException, IOException {
+		KeyStore keystore = loadKeyStore("keys/cacerts-openjdk.jks", "changeit");

Review comment:
       Done




-- 
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: dev-unsubscribe@ws.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ws.apache.org
For additional commands, e-mail: dev-help@ws.apache.org