Skip to content

Commit

Permalink
Merge pull request #1756 from xjusko/Add_test_cases_to_MappedRegexRea…
Browse files Browse the repository at this point in the history
…lmMapperTest

[ELY-2411] Add test cases to MappedRegexRealmMapperTest
  • Loading branch information
fjuma authored Feb 21, 2023
2 parents a72b698 + 7d411db commit 17b620a
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

import java.security.Principal;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

import org.junit.Assert;
import org.junit.Test;
import org.wildfly.security.auth.principal.NamePrincipal;
import org.wildfly.security.auth.server.RealmMapper;
import org.wildfly.security.x500.X500PrincipalBuilder;

/**
Expand Down Expand Up @@ -60,4 +62,26 @@ public void testReturnSpecificRealmMapping() {
Principal principal = new NamePrincipal("A-9999");
Assert.assertEquals(realmName, mappedRegexRealmMapper.getRealmMapping(principal, null));
}

@Test
public void testReturnSpecificRealmMappingForDelegate() {
String delegateName = "delegate_realm";
Pattern pattern = Pattern.compile("([A-Z]-\\d{4})");
Map<String, String> realmNameMap = Collections.singletonMap("A-9999", delegateName);
MappedRegexRealmMapper mappedRegexRealmMapper = new MappedRegexRealmMapper(pattern, RealmMapper.single("A-9999"), realmNameMap);
Principal principal = new NamePrincipal("A-1");
Assert.assertEquals(delegateName, mappedRegexRealmMapper.getRealmMapping(principal, null));
}

@Test
public void testReturnCorrectRealmMappingWithPrincipalAndDelegateMatchingPattern() {
String realmName = "realm";
Pattern pattern = Pattern.compile("([A-Z]-\\d{4})");
Map<String, String> realmNameMap = new HashMap<>();
realmNameMap.put("A-9999", realmName);
realmNameMap.put("A-1111", "delegateRealm");
MappedRegexRealmMapper mappedRegexRealmMapper = new MappedRegexRealmMapper(pattern, RealmMapper.single("A-1111"), realmNameMap);
Principal principal = new NamePrincipal("A-9999");
Assert.assertEquals(realmName, mappedRegexRealmMapper.getRealmMapping(principal, null));
}
}

0 comments on commit 17b620a

Please sign in to comment.