From 0cd66104ede9917665d782c93c4e405538d3142c Mon Sep 17 00:00:00 2001 From: Ger-Jan te Dorsthorst Date: Mon, 2 Oct 2023 20:25:12 +0200 Subject: [PATCH] [ELY-2625] Add a test to X500AttributePrincipalDecoderTest that makes use of the PrincipalDecoder#aggregate method --- .../X500AttributePrincipalDecoderTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/base/src/test/java/org/wildfly/security/x500/X500AttributePrincipalDecoderTest.java b/tests/base/src/test/java/org/wildfly/security/x500/X500AttributePrincipalDecoderTest.java index 19a3fa89433..2031e181bab 100644 --- a/tests/base/src/test/java/org/wildfly/security/x500/X500AttributePrincipalDecoderTest.java +++ b/tests/base/src/test/java/org/wildfly/security/x500/X500AttributePrincipalDecoderTest.java @@ -19,6 +19,7 @@ package org.wildfly.security.x500; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import javax.security.auth.x500.X500Principal; @@ -61,6 +62,39 @@ public void testDecodeAttributeWithSubrange() { assertEquals("jboss.redhat.com", decoder.getName(principal)); } + @Test + public void testDecodeWithAggregation() { + X500Principal principal; + PrincipalDecoder dcDecoder, dcDecoder1, cnDecoder, ouDecoder, aggregateDecoder; + principal = new X500Principal("cn=bob.smith,cn=bob,ou=people,dc=example,dc=redhat,dc=com"); + dcDecoder = new X500AttributePrincipalDecoder(X500.OID_DC); + cnDecoder = new X500AttributePrincipalDecoder(X500.OID_AT_COMMON_NAME, 1); + aggregateDecoder = PrincipalDecoder.aggregate(cnDecoder, dcDecoder); + assertEquals("bob.smith", aggregateDecoder.getName(principal)); + aggregateDecoder = PrincipalDecoder.aggregate(dcDecoder, cnDecoder); + assertEquals("example.redhat.com", aggregateDecoder.getName(principal)); + + principal = new X500Principal("cn=bob.smith,ou=people,dc=example,dc=redhat"); + cnDecoder = new X500AttributePrincipalDecoder(X500.OID_AT_COMMON_NAME); + ouDecoder = new X500AttributePrincipalDecoder(X500.OID_AT_ORGANIZATIONAL_UNIT_NAME, 1); + dcDecoder = new X500AttributePrincipalDecoder(X500.OID_DC, 1); + dcDecoder1 = new X500AttributePrincipalDecoder(X500.OID_DC, 1, 1); + aggregateDecoder = PrincipalDecoder.aggregate(dcDecoder1, dcDecoder, ouDecoder, cnDecoder); + assertEquals("redhat", aggregateDecoder.getName(principal)); + aggregateDecoder = PrincipalDecoder.aggregate(dcDecoder, dcDecoder1, ouDecoder, cnDecoder); + assertEquals("example", aggregateDecoder.getName(principal)); + aggregateDecoder = PrincipalDecoder.aggregate(cnDecoder, dcDecoder1, dcDecoder, ouDecoder); + assertEquals("bob.smith", aggregateDecoder.getName(principal)); + + principal = new X500Principal("cn=bob.smith,dc=example,dc=redhat"); + aggregateDecoder = PrincipalDecoder.aggregate(ouDecoder); + assertNull(aggregateDecoder.getName(principal)); + aggregateDecoder = PrincipalDecoder.aggregate(dcDecoder, ouDecoder); + assertEquals("example", aggregateDecoder.getName(principal)); + aggregateDecoder = PrincipalDecoder.aggregate(dcDecoder, ouDecoder, dcDecoder1); + assertEquals("example", aggregateDecoder.getName(principal)); + } + @Test public void testDecodeWithConcatenation() { X500Principal principal; new X500Principal("cn=bob.smith,cn=bob,ou=people,dc=example,dc=redhat,dc=com");