aboutsummaryrefslogtreecommitdiff
path: root/modules/eidas_proxy-sevice/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'modules/eidas_proxy-sevice/src/test/java')
-rw-r--r--modules/eidas_proxy-sevice/src/test/java/at/asitplus/eidas/specific/modules/msproxyservice/test/services/ProxyEidasAttributeRegistryTest.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/modules/eidas_proxy-sevice/src/test/java/at/asitplus/eidas/specific/modules/msproxyservice/test/services/ProxyEidasAttributeRegistryTest.java b/modules/eidas_proxy-sevice/src/test/java/at/asitplus/eidas/specific/modules/msproxyservice/test/services/ProxyEidasAttributeRegistryTest.java
new file mode 100644
index 00000000..6034c92a
--- /dev/null
+++ b/modules/eidas_proxy-sevice/src/test/java/at/asitplus/eidas/specific/modules/msproxyservice/test/services/ProxyEidasAttributeRegistryTest.java
@@ -0,0 +1,95 @@
+package at.asitplus.eidas.specific.modules.msproxyservice.test.services;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+
+import at.asitplus.eidas.specific.modules.msproxyservice.service.ProxyEidasAttributeRegistry;
+import lombok.NonNull;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {
+ "/spring/SpringTest-context_basic_test.xml",
+ "/spring/SpringTest-context_basic_mapConfig.xml",
+ })
+@EnableWebMvc
+public class ProxyEidasAttributeRegistryTest {
+
+ @Autowired ProxyEidasAttributeRegistry attrRegistry;
+
+ @Test
+ public void checkDefaultAttributes() {
+ assertEquals("default attributes without mandates", 2,
+ attrRegistry.getAlwaysRequestedAttributes(false).count());
+ assertEquals("default attributes with mandates", 4,
+ attrRegistry.getAlwaysRequestedAttributes(true).count());
+
+ }
+
+ @Test
+ public void eidasAttributeMapping() {
+ checkAttributeMapping("http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", false,
+ Arrays.asList("urn:oid:1.2.40.0.10.2.1.1.149"));
+ checkAttributeMapping("http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", true,
+ Arrays.asList("urn:oid:1.2.40.0.10.2.1.1.149", "urn:oid:1.2.40.0.10.2.1.1.261.98"));
+
+ }
+
+ @Test
+ public void eidasAttributeMappingMandateOnly() {
+ checkAttributeMapping("http://eidas.europa.eu/attributes/legalperson/LegalPersonIdentifier", false,
+ Collections.emptyList());
+ checkAttributeMapping("http://eidas.europa.eu/attributes/legalperson/LegalPersonIdentifier", true,
+ Arrays.asList("urn:oid:1.2.40.0.10.2.1.1.261.100"));
+
+ }
+
+ @Test
+ public void eidasAttributeMappingWithNoIdaAttribute() {
+ checkAttributeMapping("http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth", false,
+ Collections.emptyList());
+ checkAttributeMapping("http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth", true,
+ Collections.emptyList());
+
+ }
+
+ @Test
+ public void unknownEidasAttribute() {
+ checkAttributeMapping("http://eidas.europa.eu/attributes/jUnit/not/exits", false,
+ Collections.emptyList());
+ checkAttributeMapping("http://eidas.europa.eu/attributes/jUnit/not/exits", true,
+ Collections.emptyList());
+
+ }
+
+ @Test
+ public void unknownEidasAttribute2() {
+ checkAttributeMapping(RandomStringUtils.randomAlphabetic(10), false,
+ Collections.emptyList());
+ checkAttributeMapping(RandomStringUtils.randomAlphabetic(10), true,
+ Collections.emptyList());
+
+ }
+
+ private void checkAttributeMapping(String eidasAttr, boolean withMandates, List<String> idaAttributes) {
+ @NonNull
+ Set<String> idaAttrResult = attrRegistry.getIdaAttributesForEidasAttribute(eidasAttr, withMandates);
+ assertEquals("wrong number of IDA attributes", idaAttributes.size(), idaAttrResult.size());
+ idaAttributes.forEach(
+ el -> assertTrue("missing: " + el, idaAttrResult.contains(el)));
+
+ }
+
+}