Skip to content

Commit

Permalink
[ELY-2625] Add a test to X500AttributePrincipalDecoderTest that makes…
Browse files Browse the repository at this point in the history
… use of the PrincipalDecoder#aggregate method
  • Loading branch information
gerjantd committed Oct 2, 2023
1 parent f173144 commit 0cd6610
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 0cd6610

Please sign in to comment.