/* * Copyright 2018 A-SIT Plus GmbH * AT-specific eIDAS Connector has been developed in a cooperation between EGIZ, * A-SIT Plus GmbH, A-SIT, and Graz University of Technology. * * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "License"); * You may not use this work except in compliance with the License. * You may obtain a copy of the License at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.validation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.RandomStringUtils; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasSAuthenticationException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.CcSpecificEidProcessingService; import at.asitplus.eidas.specific.modules.core.eidas.EidasConstants; import lombok.SneakyThrows; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/SpringTest-context_tasks_test.xml", "/SpringTest-context_basic_mapConfig.xml" }) @DirtiesContext(classMode = ClassMode.AFTER_CLASS) public class EidasAttributePostProcessingTest { @Autowired private CcSpecificEidProcessingService postProcessor; // lower case private static final String P1_eIDASID = "DE/AT/532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25"; private static final String P1_GIVENNAME = "Max"; private static final String P1_FAMILYNAME = "Mustermann"; private static final String P1_DATEOFBIRTH = "2020-01-04"; private static final String P1_PLACEOFBIRTH = "Nirgendwo"; private static final String P1_BIRTHNAME = "Musterkind"; // mixed private static final String P3_eIDASID = "DE/AT/532eaabd9574880dbf76b9b8cc00832c20A6ec113d682299550d7a6e0f345e25"; private static final String P3_GIVENNAME = "Max"; private static final String P3_FAMILYNAME = "Mustermann"; private static final String P3_DATEOFBIRTH = "2020-01-03"; private static final String P3_PLACEOFBIRTH = "Nirgendwo"; private static final String P3_BIRTHNAME = "Musterkind"; // upper case private static final String P4_eIDASID = "DE/AT/532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25"; private static final String P4_GIVENNAME = "Max"; private static final String P4_FAMILYNAME = "Mustermann"; private static final String P4_DATEOFBIRTH = "2020-01-05"; private static final String P4_PLACEOFBIRTH = "Nirgendwo"; private static final String P4_BIRTHNAME = "Musterkind"; // To long identifier private static final String P5_eIDASID = "DE/AT/532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E251"; private static final String P5_GIVENNAME = "Max"; private static final String P5_FAMILYNAME = "Mustermann"; private static final String P5_DATEOFBIRTH = "2020-01-06"; private static final String P5_PLACEOFBIRTH = "Nirgendwo"; private static final String P5_BIRTHNAME = "Musterkind"; // to short identifier private static final String P6_eIDASID = "DE/AT/532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F"; private static final String P6_GIVENNAME = "Max"; private static final String P6_FAMILYNAME = "Mustermann"; private static final String P6_DATEOFBIRTH = "2020-01-08"; private static final String P6_PLACEOFBIRTH = "Nirgendwo"; private static final String P6_BIRTHNAME = "Musterkind"; // no hex encoded identifier private static final String P7_eIDASID = "DE/AT/532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F"; private static final String P7_GIVENNAME = "Max"; private static final String P7_FAMILYNAME = "Mustermann"; private static final String P7_DATEOFBIRTH = "2020-01-09"; private static final String P7_PLACEOFBIRTH = "Nirgendwo"; private static final String P7_BIRTHNAME = "Musterkind"; private static final String P2_eIDASID = "EE/AT/asfasfasdfasdfasdfasdfasdfasvafasdfasdfasdfasdfasdfasvascasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd"; private static final String P2_GIVENNAME = "Max"; private static final String P2_FAMILYNAME = "Mustermann"; private static final String P2_DATEOFBIRTH = "2020-01-10"; private static final String P2_PLACEOFBIRTH = "Nirgendwo"; private static final String P2_BIRTHNAME = "Musterkind"; private static final String P8_eIDASID_PID = RandomStringUtils.randomAlphabetic(10); private static final String P8_eIDASID ="EL/AT/" + P8_eIDASID_PID; private static final String P8_GIVENNAME = RandomStringUtils.randomAlphabetic(10); private static final String P8_FAMILYNAME = RandomStringUtils.randomAlphabetic(10); private static final String P8_DATEOFBIRTH = "2028-05-11"; private static final String P8_PLACEOFBIRTH = RandomStringUtils.randomAlphabetic(10); private static final String P8_BIRTHNAME = RandomStringUtils.randomAlphabetic(10); /** * jUnit class initializer. * * @throws IOException In case of an error */ @BeforeClass public static void classInitializer() throws IOException { final String current = new java.io.File(".").toURI().toString(); System.setProperty("eidas.ms.configuration", current + "../../basicConfig/default_config.properties"); } @Test @SneakyThrows public void deWithHexLowerCase() { final SimpleEidasData result = postProcessor.postProcess( generateInputData( P1_eIDASID, P1_FAMILYNAME, P1_GIVENNAME, P1_DATEOFBIRTH, P1_PLACEOFBIRTH, P1_BIRTHNAME)); validate(result, "Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=", "DE", P1_FAMILYNAME, P1_GIVENNAME, P1_DATEOFBIRTH, P1_PLACEOFBIRTH, P1_BIRTHNAME); } @Test @SneakyThrows public void deWithHexMixedCase() { final SimpleEidasData result = postProcessor.postProcess( generateInputData( P3_eIDASID, P3_FAMILYNAME, P3_GIVENNAME, P3_DATEOFBIRTH, P3_PLACEOFBIRTH, P3_BIRTHNAME)); validate(result, "Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=", "DE", P3_FAMILYNAME, P3_GIVENNAME, P3_DATEOFBIRTH, P3_PLACEOFBIRTH, P3_BIRTHNAME); } @Test @SneakyThrows public void deWithHexUpperCase() { final SimpleEidasData result = postProcessor.postProcess( generateInputData( P4_eIDASID, P4_FAMILYNAME, P4_GIVENNAME, P4_DATEOFBIRTH, P4_PLACEOFBIRTH, P4_BIRTHNAME)); validate(result, "Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=", "DE", P4_FAMILYNAME, P4_GIVENNAME, P4_DATEOFBIRTH, P4_PLACEOFBIRTH, P4_BIRTHNAME); } @Test public void deWithHexTooLongCase() throws Exception { assertThrows("missing exception", EidasSAuthenticationException.class, () -> postProcessor.postProcess( generateInputData( P5_eIDASID, P5_FAMILYNAME, P5_GIVENNAME, P5_DATEOFBIRTH, P5_PLACEOFBIRTH, P5_BIRTHNAME))); } @Test public void deWithHexTooShortCase() throws Exception { assertThrows("missing exception", EidasSAuthenticationException.class, () -> postProcessor.postProcess( generateInputData( P6_eIDASID, P6_FAMILYNAME, P6_GIVENNAME, P6_DATEOFBIRTH, P6_PLACEOFBIRTH, P6_BIRTHNAME))); } @Test public void deWithNoHexCase() throws Exception { assertThrows("missing exception", EidasSAuthenticationException.class, () -> postProcessor.postProcess( generateInputData( P7_eIDASID, P7_FAMILYNAME, P7_GIVENNAME, P7_DATEOFBIRTH, P7_PLACEOFBIRTH, P7_BIRTHNAME))); } @Test public void elTestCase() throws Exception { final SimpleEidasData result = postProcessor.postProcess( generateInputData( P8_eIDASID, P8_FAMILYNAME, P8_GIVENNAME, P8_DATEOFBIRTH, P8_PLACEOFBIRTH, P8_BIRTHNAME)); validate(result, P8_eIDASID_PID, "EL", P8_FAMILYNAME, P8_GIVENNAME, P8_DATEOFBIRTH, P8_PLACEOFBIRTH, P8_BIRTHNAME); } @Test public void eeTestCase() throws Exception { final SimpleEidasData result = postProcessor.postProcess( generateInputData( P2_eIDASID, P2_FAMILYNAME, P2_GIVENNAME, P2_DATEOFBIRTH, P2_PLACEOFBIRTH, P2_BIRTHNAME)); validate(result, "asfasfasdfasdfasdfasdfasdfasvafasdfasdfasdfasdfasdfasvascasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd", "EE", P2_FAMILYNAME, P2_GIVENNAME, P2_DATEOFBIRTH, P2_PLACEOFBIRTH, P2_BIRTHNAME); } @Test public void eeTestFamilyNameMissingCase() throws Exception { assertThrows("missing exception", EidasSAuthenticationException.class, () -> postProcessor.postProcess( generateInputData( P2_eIDASID, null, P2_GIVENNAME, P2_DATEOFBIRTH, P2_PLACEOFBIRTH, P2_BIRTHNAME))); } @Test public void eeTestGivenNameMissingCase() throws Exception { assertThrows("missing exception", EidasSAuthenticationException.class, () -> postProcessor.postProcess( generateInputData( P2_eIDASID, P2_FAMILYNAME, null, P2_DATEOFBIRTH, P2_PLACEOFBIRTH, P2_BIRTHNAME))); } @Test public void eeTestDateOfBirthMissingCase() throws Exception { assertThrows("missing exception", EidasSAuthenticationException.class, () -> postProcessor.postProcess( generateInputData( P2_eIDASID, P2_FAMILYNAME, P2_GIVENNAME, null, P2_PLACEOFBIRTH, P2_BIRTHNAME))); } @Test public void eeTestIdMissingCase() throws Exception { assertThrows("missing exception", EidasSAuthenticationException.class, () -> postProcessor.postProcess( generateInputData( null, P2_FAMILYNAME, P2_GIVENNAME, P2_DATEOFBIRTH, P2_PLACEOFBIRTH, P2_BIRTHNAME))); } private Map generateInputData(String id, String familyName, String givenName, String dateOfBirth, String placeOfBirth, String birthName) { final Map result = new HashMap<>(); result.put(EidasConstants.eIDAS_ATTR_PERSONALIDENTIFIER, id); result.put(EidasConstants.eIDAS_ATTR_CURRENTGIVENNAME, givenName); result.put(EidasConstants.eIDAS_ATTR_CURRENTFAMILYNAME, familyName); result.put(EidasConstants.eIDAS_ATTR_DATEOFBIRTH, dateOfBirth); result.put(EidasConstants.eIDAS_ATTR_PLACEOFBIRTH, placeOfBirth); result.put(EidasConstants.eIDAS_ATTR_BIRTHNAME, birthName); return result; } private void validate(SimpleEidasData result, String id, String cc, String familyName, String givenName, String dateOfBirth, String placeOfBirth, String birthName) { assertEquals("pseudonym", id, result.getPseudonym()); assertEquals("countrycode", cc, result.getCitizenCountryCode()); assertEquals("familyName", familyName, result.getFamilyName()); assertEquals("givenName", givenName, result.getGivenName()); assertEquals("dateOfBirth", dateOfBirth, result.getDateOfBirth()); assertEquals("placeOfBirth", placeOfBirth, result.getPlaceOfBirth()); assertEquals("birthName", birthName, result.getBirthName()); } }