aboutsummaryrefslogtreecommitdiff
path: root/id/server/modules/moa-id-module-eIDAS/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/modules/moa-id-module-eIDAS/src/test/java')
-rw-r--r--id/server/modules/moa-id-module-eIDAS/src/test/java/test/at/gv/egovernment/moa/id/modules/eidas/eid4u/AttributeScopeMapperTest.java253
1 files changed, 253 insertions, 0 deletions
diff --git a/id/server/modules/moa-id-module-eIDAS/src/test/java/test/at/gv/egovernment/moa/id/modules/eidas/eid4u/AttributeScopeMapperTest.java b/id/server/modules/moa-id-module-eIDAS/src/test/java/test/at/gv/egovernment/moa/id/modules/eidas/eid4u/AttributeScopeMapperTest.java
new file mode 100644
index 000000000..0daa90b40
--- /dev/null
+++ b/id/server/modules/moa-id-module-eIDAS/src/test/java/test/at/gv/egovernment/moa/id/modules/eidas/eid4u/AttributeScopeMapperTest.java
@@ -0,0 +1,253 @@
+package test.at.gv.egovernment.moa.id.modules.eidas.eid4u;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Base64;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonParser;
+
+import at.gv.egiz.eid4u.api.attributes.Definitions;
+import at.gv.egovernment.moa.id.auth.modules.eidas.eid4u.utils.AttributeScopeMapper;
+import eu.eidas.auth.commons.protocol.eidas.impl.PostalAddress;
+
+
+public class AttributeScopeMapperTest {
+
+ private static final String TUG_AP_RESPONSE_B64 = "ewogICAiQU5ZQHR1Z3Jhei5pZG0uYXR0ci5Db3VudHJ5T2ZCaXJ0aCI6IiIsCiAgICJBTllAdHVncmF6LmlkbS5hdHRyLkN1cnJlbnREZWdyZWVOYW1lIjoiRHIudGVjaG4uIiwKICAgIkFOWUB0dWdyYXouaWRtLmF0dHIuQ3VycmVudEZpZWxkT2ZTdHVkeSI6IjA2ODg7OTk5OSIsCiAgICJBTllAdHVncmF6LmlkbS5hdHRyLkN1cnJlbnRMZXZlbE9mU3R1ZHkiOiI4IiwKICAgIkFOWUB0dWdyYXouaWRtLmF0dHIuRW1haWxTdHVkIjoidC5rZXJuQHN0dWRlbnQudHVncmF6LmF0IiwKICAgIkFOWUB0dWdyYXouaWRtLmF0dHIuSG9tZUluc3RpdHV0aW9uQWRkcmVzc0NvdW50cnlDb2RlIjoiQVQiLAogICAiQU5ZQHR1Z3Jhei5pZG0uYXR0ci5Ib21lSW5zdGl0dXRpb25BZGRyZXNzUG9zdGFsQ29kZSI6IjgwMTAiLAogICAiQU5ZQHR1Z3Jhei5pZG0uYXR0ci5Ib21lSW5zdGl0dXRpb25BZGRyZXNzU3RyZWV0IjoiUmVjaGJhdWVyc3RyYcOfZSAxMiIsCiAgICJBTllAdHVncmF6LmlkbS5hdHRyLkhvbWVJbnN0aXR1dGlvbkNvdW50cnkiOiJBVCIsCiAgICJBTllAdHVncmF6LmlkbS5hdHRyLkhvbWVJbnN0aXR1dGlvbk5hbWUiOiJHcmF6IFVuaXZlcnNpdHkgT2YgVGVjaG5vbG9neSIsCiAgICJBTllAdHVncmF6LmlkbS5hdHRyLkhvbWVJbnN0aXR1dGlvbkFkZHJlc3NDaXR5IjoiR3JheiIsCiAgICJBTllAdHVncmF6LmlkbS5hdHRyLlN0dWR5QWRkcmVzc0NpdHkiOiJGcm9obmxlaXRlbiIsCiAgICJBTllAdHVncmF6LmlkbS5hdHRyLlN0dWR5QWRkcmVzc1Bvc3RhbENvZGUiOiI4MTMwIiwKICAgIkFOWUB0dWdyYXouaWRtLmF0dHIuU3R1ZHlBZGRyZXNzQ291bnRyeUNvZGUiOiJBVCIsCiAgICJBTllAdHVncmF6LmlkbS5hdHRyLlN0dWR5QWRkcmVzc1N0cmVldCI6IkvDvGhhdSAyMiIKfQ==";
+
+ private AttributeScopeMapper mapper = null;
+
+ @Test
+ public void dummyTest() throws Exception {
+
+
+ }
+
+ @Test
+ public void checkTugApResponseMapping() throws JsonParseException, UnsupportedEncodingException {
+ JsonElement fullAttrSet = new JsonParser().parse(new String(
+ Base64.getDecoder().decode(TUG_AP_RESPONSE_B64.getBytes()), "UTF-8"));
+
+ Map<String, Object> result = getMapper().populateEid4uAttributesFromTugResponse(fullAttrSet.getAsJsonObject());
+
+ Assert.assertTrue("eID4u attribte-table is EMPTY after mapping", !result.isEmpty());
+
+ Assert.assertTrue(result.containsKey(Definitions.COUNTRYOFBIRTH_NAME));
+ Assert.assertEquals("", result.get(Definitions.COUNTRYOFBIRTH_NAME));
+
+ Assert.assertTrue(result.containsKey(Definitions.CURRENTDEGREE_NAME));
+ Assert.assertEquals("Dr.techn.", result.get(Definitions.CURRENTDEGREE_NAME));
+
+ Assert.assertTrue(result.containsKey(Definitions.FIELDOFSTUDY_NAME));
+ Assert.assertEquals("0688;9999", result.get(Definitions.FIELDOFSTUDY_NAME));
+
+ Assert.assertTrue(result.containsKey(Definitions.CURRENTLEVELOFSTUDY_NAME));
+ Assert.assertEquals("8", result.get(Definitions.CURRENTLEVELOFSTUDY_NAME));
+
+ Assert.assertTrue(result.containsKey(Definitions.EMAIL_NAME));
+ Assert.assertEquals("t.kern@student.tugraz.at", result.get(Definitions.EMAIL_NAME));
+
+ Assert.assertTrue(result.containsKey(Definitions.HOMEINSTITUTIONNAME_NAME));
+ Assert.assertEquals("Graz University Of Technology", result.get(Definitions.HOMEINSTITUTIONNAME_NAME));
+
+ Assert.assertTrue(result.containsKey(Definitions.HOMEINSTITUTIONCOUNTRY_NAME));
+ Assert.assertEquals("AT", result.get(Definitions.HOMEINSTITUTIONCOUNTRY_NAME));
+
+ Assert.assertTrue(result.containsKey(Definitions.HOMEINSTITUTIONADDRESS_NAME));
+ checkComplexeAddress(
+ result.get(Definitions.HOMEINSTITUTIONADDRESS_NAME),
+ "AT",
+ "8010",
+ "Rechbauerstraße 12",
+ "Graz");
+
+ Assert.assertTrue(result.containsKey(Definitions.TEMPORARYADDRESS_NAME));
+ checkComplexeAddress(
+ result.get(Definitions.TEMPORARYADDRESS_NAME),
+ "AT",
+ "8130",
+ "Kühau 22",
+ "Frohnleiten");
+
+ }
+
+ private void checkComplexeAddress(Object toCheck, String cc, String postalCode, String Street, String city) {
+ Assert.assertNotNull(toCheck);
+ Assert.assertTrue(toCheck instanceof PostalAddress);
+
+ PostalAddress addr = (PostalAddress)toCheck;
+ Assert.assertEquals(postalCode, addr.getPostCode());
+ Assert.assertEquals(Street, addr.getCvAddressArea());
+ Assert.assertEquals(Street, addr.getThoroughfare());
+ Assert.assertEquals(city, addr.getPostName());
+
+ }
+
+ @Test
+ public void checkCitizenship() throws Exception {
+ checkBasicMappingInitialization(Definitions.CITIZENSHIP_NAME, AttributeScopeMapper.Citizenship, false);
+
+ }
+
+ @Test
+ public void checkCityOfBirth() throws Exception {
+ checkBasicMappingInitialization(eu.eidas.auth.engine.core.eidas.spec.NaturalPersonSpec.Definitions.PLACE_OF_BIRTH.getNameUri().toString(), AttributeScopeMapper.CityOfBirth, false);
+
+ }
+
+ @Test
+ public void checkCountryOfBirth() throws Exception {
+ checkBasicMappingInitialization(Definitions.COUNTRYOFBIRTH_NAME, AttributeScopeMapper.CountryOfBirth, false);
+
+ }
+
+ @Test
+ public void checkCurrentDegreeName() throws Exception {
+ checkBasicMappingInitialization(Definitions.CURRENTDEGREE_NAME, AttributeScopeMapper.CurrentDegreeName, false);
+
+ }
+
+ @Test
+ public void checkCurrentFieldOfStudy() throws Exception {
+ checkBasicMappingInitialization(Definitions.FIELDOFSTUDY_NAME, AttributeScopeMapper.CurrentFieldOfStudy, false);
+ }
+
+ @Test
+ public void checkCurrentLevelOfStudy() throws Exception {
+ checkBasicMappingInitialization(Definitions.CURRENTLEVELOFSTUDY_NAME, AttributeScopeMapper.CurrentLevelOfStudy, false);
+
+ }
+
+ @Test
+ public void checkEmailStud() throws Exception {
+ checkBasicMappingInitialization(Definitions.EMAIL_NAME, AttributeScopeMapper.EmailStud, false);
+
+ }
+
+ @Test
+ public void checkGender() throws Exception {
+ checkBasicMappingInitialization(eu.eidas.auth.engine.core.eidas.spec.NaturalPersonSpec.Definitions.GENDER.getNameUri().toString(), AttributeScopeMapper.Gender, false);
+
+ }
+
+ @Test
+ public void checkHomeInstitutionName() throws Exception {
+ checkBasicMappingInitialization(Definitions.HOMEINSTITUTIONNAME_NAME, AttributeScopeMapper.HomeInstitutionName, false);
+
+ }
+
+ @Test
+ public void checkHomeInstitutionCountry() throws Exception {
+ checkBasicMappingInitialization(Definitions.HOMEINSTITUTIONCOUNTRY_NAME, AttributeScopeMapper.HomeInstitutionCountry, false);
+
+ }
+
+ @Test
+ public void checkHomeInstitutionAddressCountryCode() throws Exception {
+ checkBasicMappingInitialization(Definitions.HOMEINSTITUTIONADDRESS_NAME, AttributeScopeMapper.HomeInstitutionAddressCountryCode, true);
+
+ }
+
+ @Test
+ public void checkHomeInstitutionAddressPostalCode() throws Exception {
+ checkBasicMappingInitialization(Definitions.HOMEINSTITUTIONADDRESS_NAME, AttributeScopeMapper.HomeInstitutionAddressPostalCode, true);
+
+ }
+
+ @Test
+ public void checkHomeInstitutionAddressStreet() throws Exception {
+ checkBasicMappingInitialization(Definitions.HOMEINSTITUTIONADDRESS_NAME, AttributeScopeMapper.HomeInstitutionAddressStreet, true);
+
+ }
+
+ @Test
+ public void checkHomeInstitutionAddressCity() throws Exception {
+ checkBasicMappingInitialization(Definitions.HOMEINSTITUTIONADDRESS_NAME, AttributeScopeMapper.HomeInstitutionAddressCity, true);
+
+ }
+
+ @Test
+ public void checkPermanentAddressCity() throws Exception {
+ checkBasicMappingInitialization(eu.eidas.auth.engine.core.eidas.spec.NaturalPersonSpec.Definitions.CURRENT_ADDRESS.getNameUri().toString(), AttributeScopeMapper.PermanentAddressCity, true);
+
+ }
+
+ @Test
+ public void checkPermanentAddressCountryCode() throws Exception {
+ checkBasicMappingInitialization(eu.eidas.auth.engine.core.eidas.spec.NaturalPersonSpec.Definitions.CURRENT_ADDRESS.getNameUri().toString(), AttributeScopeMapper.PermanentAddressCountryCode, true);
+
+ }
+
+ @Test
+ public void checkPermanentAddressPostalCode() throws Exception {
+ checkBasicMappingInitialization(eu.eidas.auth.engine.core.eidas.spec.NaturalPersonSpec.Definitions.CURRENT_ADDRESS.getNameUri().toString(), AttributeScopeMapper.PermanentAddressPostalCode, true);
+
+ }
+
+ @Test
+ public void checkPermanentAddressStreet() throws Exception {
+ checkBasicMappingInitialization(eu.eidas.auth.engine.core.eidas.spec.NaturalPersonSpec.Definitions.CURRENT_ADDRESS.getNameUri().toString(), AttributeScopeMapper.PermanentAddressStreet, true);
+
+ }
+
+ @Test
+ public void checkStudyAddressCity() throws Exception {
+ checkBasicMappingInitialization(Definitions.TEMPORARYADDRESS_NAME, AttributeScopeMapper.StudyAddressCity, true);
+
+ }
+
+ @Test
+ public void checkStudyAddressCountryCode() throws Exception {
+ checkBasicMappingInitialization(Definitions.TEMPORARYADDRESS_NAME, AttributeScopeMapper.StudyAddressCountryCode, true);
+
+ }
+
+ @Test
+ public void checkStudyAddressPostalCode() throws Exception {
+ checkBasicMappingInitialization(Definitions.TEMPORARYADDRESS_NAME, AttributeScopeMapper.StudyAddressPostalCode, true);
+
+ }
+
+ @Test
+ public void checkStudyAddressStreet() throws Exception {
+ checkBasicMappingInitialization(Definitions.TEMPORARYADDRESS_NAME, AttributeScopeMapper.StudyAddressStreet, true);
+
+ }
+
+ private void checkBasicMappingInitialization(String eid4Uattr, String scope, boolean isComplexe) {
+ Assert.assertTrue((getMapper().isComplexeScope(scope) == isComplexe));
+
+ String eid4UattrRes = getMapper().geteIDASAttrFromScope(scope);
+ Assert.assertEquals(eid4Uattr, eid4UattrRes);
+
+ String scopeRes = getMapper().getTUGScopesForAttribute(eid4Uattr);
+ if (isComplexe) {
+ Assert.assertNotNull(scopeRes);
+ Assert.assertTrue(scopeRes.contains(scope));
+
+ } else
+ Assert.assertEquals(scope, scopeRes);
+
+ }
+
+ private void checkAddress() {
+
+
+ }
+
+ private AttributeScopeMapper getMapper() {
+ if (mapper == null)
+ mapper = AttributeScopeMapper.getInstance();
+
+ return mapper;
+ }
+
+
+
+
+}