From ce2250d0e285dfa456072729989f9ac2a498cec1 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Wed, 11 Dec 2019 07:33:04 +0100 Subject: add BM.I specific example of country-selection template add new i18n content add jUnit tests --- basicConfig/default_config.properties | 2 +- basicConfig/properties/messages.properties | 98 +++++++++ basicConfig/properties/messages_de.properties | 11 + basicConfig/properties/messages_en.properties | 88 -------- basicConfig/templates/countrySelection.html | 237 +++++++++++++++++++++ .../config/StaticResourceConfiguration.java | 1 + .../resources/specific_eIDAS_connector.beans.xml | 28 +-- .../specific_eIDAS_connector.storage.beans.xml | 4 +- .../task/EvaluateCountrySelectionTaskTest.java | 191 +++++++++++++++++ .../GenerateCountrySelectionFrameTaskTest.java | 146 +++++++++++++ .../spring/SpringTest-context_simple_storage.xml | 15 ++ 11 files changed, 716 insertions(+), 105 deletions(-) create mode 100644 basicConfig/properties/messages.properties delete mode 100644 basicConfig/properties/messages_en.properties create mode 100644 basicConfig/templates/countrySelection.html create mode 100644 connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/EvaluateCountrySelectionTaskTest.java create mode 100644 connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/GenerateCountrySelectionFrameTaskTest.java create mode 100644 connector/src/test/resources/spring/SpringTest-context_simple_storage.xml diff --git a/basicConfig/default_config.properties b/basicConfig/default_config.properties index 81ce2f6a..4cb6fa0a 100644 --- a/basicConfig/default_config.properties +++ b/basicConfig/default_config.properties @@ -17,7 +17,7 @@ eidas.ms.revisionlog.logIPAddressOfUser=true eidas.ms.webcontent.static.directory=webcontent/ eidas.ms.webcontent.templates=templates/ eidas.ms.webcontent.properties=properties/messages -eidas.ms.webcontent.templates.countryselection=countrySelection_example.html +eidas.ms.webcontent.templates.countryselection=countrySelection.html ## extended validation of pending-request Id's eidas.ms.core.pendingrequestid.maxlifetime=300 diff --git a/basicConfig/properties/messages.properties b/basicConfig/properties/messages.properties new file mode 100644 index 00000000..ea604cda --- /dev/null +++ b/basicConfig/properties/messages.properties @@ -0,0 +1,98 @@ +####### GUI elements #### +gui.general.language.selection.title=Language selection +gui.general.language.selection.de=Deutsch +gui.general.language.selection.en=English + +##Errorpage template +gui.errorpage.msg.title=Authentication error arise +gui.errorpage.msg.information=The authentication stops on account of a process error: +gui.errorpage.msg.errorcode=Error Code: +gui.errorpage.msg.errormsg=Error Message: +gui.errorpage.msg.stacktrace=Stacktrace: + +##Country-Selection page +gui.countryselection.title=eIDAS-Login Countryselection +gui.countryselection.logo.bmi.alt=Logo BMI +gui.countryselection.link.bmi=Mainpage BMI +gui.countryselection.header1=Federal Ministry of Internal Affairs +gui.countryselection.header2=Austrian Central eIDAS Node +gui.countryselection.header3=Operated by Federal Ministry of Internal Affairs +gui.countryselection.header.selection=Select your country +gui.countryselection.cancle=Cancel +gui.countryselection.notsupportedinfo=If you cannot find your country in this list then your electronic identity (eID) is not yet supported. + +gui.countryselection.infos.general.header=Information on Logins with European eIDs +gui.countryselection.infos.general.link.1=eIDAS regulation of the European Union +gui.countryselection.infos.general.link.2=Austrian Supplementary Register for Natural Persons (ERnP) +gui.countryselection.infos.general.part.1=This is the central eIDAS node of the Republic of Austria, operated by the +gui.countryselection.infos.general.part.2=It enables logins at Austrian online services using an electronic identity (eID) of another EU member state. You have been redirected to this page, as you have initiated a login to an online service using the option "EU Login". +gui.countryselection.infos.general.part.3=The central eIDAS node of the Republic of Austria allows you to login to Austrian online services using the eID of your home country. This way, compliance with the +gui.countryselection.infos.general.part.4=, which regulates the mutual cross-border acceptance of national eIDs, is achieved. The mutual cross-border acceptance of national eIDs is implemented successively within the EU. Currently, the central eIDAS node of the Republic of Austria supports logins using the eID systems of the Member States mentioned above. More Member States will be added according to availability of their respective eID solutions. +gui.countryselection.infos.general.part.5=After selecting your home country on this page, you are forwarded to the familiar login environment of the selected member state. There, you can login with your eID as usual. After successful completion of the login process, you are automatically forwarded and logged in to the online service, from which you have been redirected to this page. During your first login, your eID data is also registered in the +gui.countryselection.infos.general.part.6=This ensures that you will also be successfully and uniquely identified in subsequent logins at Austrian online services. + +gui.countryselection.country.be=Belgium +gui.countryselection.country.be.logo.alt=Belgium-eID +gui.countryselection.country.hr=Croatia +gui.countryselection.country.hr.logo.alt=Croatia-eID +gui.countryselection.country.cy=Cyprus +gui.countryselection.country.cy.logo.alt=Cyprus-eID +gui.countryselection.country.cz=Czech Republic +gui.countryselection.country.cz.logo.alt=Czech Republic-eID +gui.countryselection.country.ee=Estonia +gui.countryselection.country.ee.logo.alt=Estonia-eID +gui.countryselection.country.de=Germany +gui.countryselection.country.de.logo.alt=German-eID +gui.countryselection.country.is=Iceland +gui.countryselection.country.is.logo.alt=Iceland-eID +gui.countryselection.country.it=Italy +gui.countryselection.country.it.logo.alt=Italy-eID +gui.countryselection.country.lt=Lithuania +gui.countryselection.country.lt.logo.alt=Lithuania-eID +gui.countryselection.country.lv=Latvia +gui.countryselection.country.lv.logo.alt=Latvia-eID +gui.countryselection.country.nl=Netherlands +gui.countryselection.country.nl.logo.alt=Netherlands-eID +gui.countryselection.country.pl=Poland +gui.countryselection.country.pl.logo.alt=Poland-eID +gui.countryselection.country.pt=Portugal +gui.countryselection.country.pt.logo.alt=Portugal-eID +gui.countryselection.country.si=Slovenia +gui.countryselection.country.si.logo.alt=Slovenia-eID +gui.countryselection.country.es=SSpain +gui.countryselection.country.es.logo.alt=Spain-eID + +gui.countryselection.country.bg=Bulgaria +gui.countryselection.country.bg.logo.alt=Bulgaria-eID +gui.countryselection.country.dk=Denmark +gui.countryselection.country.dk.logo.alt=Denmark-eID +gui.countryselection.country.fi=Finland +gui.countryselection.country.fi.logo.alt=Finland-eID +gui.countryselection.country.fr=France +gui.countryselection.country.fr.logo.alt=France-eID +gui.countryselection.country.gr=Greece +gui.countryselection.country.gr.logo.alt=Greece-eID +gui.countryselection.country.hu=Hungary +gui.countryselection.country.hu.logo.alt=Hungary-eID +gui.countryselection.country.ir=Ireland +gui.countryselection.country.ir.logo.alt=Ireland-eID +gui.countryselection.country.lu=Luxembourg +gui.countryselection.country.lu.logo.alt=Luxembourg-eID +gui.countryselection.country.mt=Malta +gui.countryselection.country.mt.logo.alt=Malta-eID +gui.countryselection.country.ro=Romania +gui.countryselection.country.ro.logo.alt=Romania-eID +gui.countryselection.country.sk=Slovakia +gui.countryselection.country.sk.logo.alt=Slovakia-eID +gui.countryselection.country.sw=Sweden +gui.countryselection.country.sw.logo.alt=Sweden-eID +gui.countryselection.country.uk=United Kingdom +gui.countryselection.country.uk.logo.alt=United Kingdom-eID + +gui.countryselection.country.testcountry=TestCountry +gui.countryselection.country.testcountry.logo.alt=Testcountry-eID + +gui.countryselection.mode.prod=Production +gui.countryselection.mode.qs=QS +gui.countryselection.mode.test=Test +gui.countryselection.mode.dev=Development \ No newline at end of file diff --git a/basicConfig/properties/messages_de.properties b/basicConfig/properties/messages_de.properties index 945e66fd..989b8d9c 100644 --- a/basicConfig/properties/messages_de.properties +++ b/basicConfig/properties/messages_de.properties @@ -21,6 +21,17 @@ gui.countryselection.header.selection=Wählen Sie Ihr Land gui.countryselection.cancle=Abbrechen gui.countryselection.notsupportedinfo=Wenn Sie Ihr Land in dieser Aufzählung nicht entdecken, dann wird Ihre elektronische Identität (eID) leider noch nicht unterstützt. +gui.countryselection.infos.general.header=Information zur Anmeldung über Europäische eIDs +gui.countryselection.infos.general.link.1=eIDAS-Verordnung der Europäischen Union +gui.countryselection.infos.general.link.2=Ergänzungsregister für natürliche Personen (ERnP) +gui.countryselection.infos.general.part.1=Sie befinden sich am zentralen eIDAS-Knoten der Republik Österreich. Dieser wird vom Österreichischen +gui.countryselection.infos.general.part.2=betrieben und ermöglicht eine Anmeldungen zu österreichischen Online-Anwendungen unter Verwendung einer elektronischen Identität (eID) anderer EU-Mitgliedstaaten. Sie wurden hierher weitergeleitet, da Sie in einer Online-Anwendung eine Anmeldung via EU-Login initiiert haben. +gui.countryselection.infos.general.part.3=Der zentrale eIDAS-Knoten der Republik Österreich ermöglicht Ihnen eine Anmeldung zu österreichischen Online-Anwendungen mit der eID Ihres Herkunftsstaates. Damit werden die Vorgaben der +gui.countryselection.infos.general.part.4=erfüllt, die eine staatenübergreifende Akzeptanz nationaler eIDs vorsieht. Die wechselseitige Anerkennung nationaler eIDs erfolgt in der EU schrittweise. Aktuell unterstützt der zentrale eIDAS-Knoten der Republik Österreich Anmeldungen mit den eID-Systemen der oben angeführten Mitgliedstaaten. Diese Liste wird laufend erweitert. +gui.countryselection.infos.general.part.5=Nachdem Sie auf dieser Seite einen Mitgliedsstaat ausgewählt haben, werden Sie an die gewohnte Anmeldeumgebung des jeweiligen Mitgliedsstaats weitergeleitet. Dort können Sie sich mit Ihrer eID wie gewohnt anmelden. Haben Sie den Anmeldeprozess erfolgreich abgeschlossen, werden Sie automatisch an die Online-Anwendung, von der aus Sie auf diese Auswahlseite gelangt sind, weitergeleitet und dort mit den Identitätsdaten Ihrer eID angemeldet. Gleichzeitig werden Sie bei Ihrer ersten Anmeldung auf diesem Weg mit Ihren eID-Daten in das österreichische +gui.countryselection.infos.general.part.6=eingetragen. Damit wird sichergestellt, dass Sie auch im Rahmen zukünftiger Anmeldeprozesse zu österreichischen Online-Anwendungen erfolgreich und eindeutig identifiziert werden können. + + gui.countryselection.country.be=Belgien gui.countryselection.country.be.logo.alt=Belgische-eID gui.countryselection.country.hr=Kroatien diff --git a/basicConfig/properties/messages_en.properties b/basicConfig/properties/messages_en.properties deleted file mode 100644 index 0d312c75..00000000 --- a/basicConfig/properties/messages_en.properties +++ /dev/null @@ -1,88 +0,0 @@ -####### GUI elements #### -gui.general.language.selection.title=Language selection -gui.general.language.selection.de=Deutsch -gui.general.language.selection.en=English - -##Errorpage template -gui.errorpage.msg.title=Authentication error arise -gui.errorpage.msg.information=The authentication stops on account of a process error: -gui.errorpage.msg.errorcode=Error Code: -gui.errorpage.msg.errormsg=Error Message: -gui.errorpage.msg.stacktrace=Stacktrace: - -##Country-Selection page -gui.countryselection.title=eIDAS-Login Countryselection -gui.countryselection.logo.bmi.alt=Logo BMI -gui.countryselection.link.bmi=Mainpage BMI -gui.countryselection.header1=Federal Ministry of Internal Affairs -gui.countryselection.header2=Austrian Central eIDAS Node -gui.countryselection.header3=Operated by Federal Ministry of Internal Affairs -gui.countryselection.header.selection=Select your country -gui.countryselection.cancle=Cancel -gui.countryselection.notsupportedinfo=If you cannot find your country in this list then your electronic identity (eID) is not yet supported. - -gui.countryselection.country.be=Belgium -gui.countryselection.country.be.logo.alt=Belgium-eID -gui.countryselection.country.hr=Croatia -gui.countryselection.country.hr.logo.alt=Croatia-eID -gui.countryselection.country.cy=Cyprus -gui.countryselection.country.cy.logo.alt=Cyprus-eID -gui.countryselection.country.cz=Czech Republic -gui.countryselection.country.cz.logo.alt=Czech Republic-eID -gui.countryselection.country.ee=Estonia -gui.countryselection.country.ee.logo.alt=Estonia-eID -gui.countryselection.country.de=Germany -gui.countryselection.country.de.logo.alt=German-eID -gui.countryselection.country.is=Iceland -gui.countryselection.country.is.logo.alt=Iceland-eID -gui.countryselection.country.it=Italy -gui.countryselection.country.it.logo.alt=Italy-eID -gui.countryselection.country.lt=Lithuania -gui.countryselection.country.lt.logo.alt=Lithuania-eID -gui.countryselection.country.lv=Latvia -gui.countryselection.country.lv.logo.alt=Latvia-eID -gui.countryselection.country.nl=Netherlands -gui.countryselection.country.nl.logo.alt=Netherlands-eID -gui.countryselection.country.pl=Poland -gui.countryselection.country.pl.logo.alt=Poland-eID -gui.countryselection.country.pt=Portugal -gui.countryselection.country.pt.logo.alt=Portugal-eID -gui.countryselection.country.si=Slovenia -gui.countryselection.country.si.logo.alt=Slovenia-eID -gui.countryselection.country.es=SSpain -gui.countryselection.country.es.logo.alt=Spain-eID - -gui.countryselection.country.bg=Bulgaria -gui.countryselection.country.bg.logo.alt=Bulgaria-eID -gui.countryselection.country.dk=Denmark -gui.countryselection.country.dk.logo.alt=Denmark-eID -gui.countryselection.country.fi=Finland -gui.countryselection.country.fi.logo.alt=Finland-eID -gui.countryselection.country.fr=France -gui.countryselection.country.fr.logo.alt=France-eID -gui.countryselection.country.gr=Greece -gui.countryselection.country.gr.logo.alt=Greece-eID -gui.countryselection.country.hu=Hungary -gui.countryselection.country.hu.logo.alt=Hungary-eID -gui.countryselection.country.ir=Ireland -gui.countryselection.country.ir.logo.alt=Ireland-eID -gui.countryselection.country.lu=Luxembourg -gui.countryselection.country.lu.logo.alt=Luxembourg-eID -gui.countryselection.country.mt=Malta -gui.countryselection.country.mt.logo.alt=Malta-eID -gui.countryselection.country.ro=Romania -gui.countryselection.country.ro.logo.alt=Romania-eID -gui.countryselection.country.sk=Slovakia -gui.countryselection.country.sk.logo.alt=Slovakia-eID -gui.countryselection.country.sw=Sweden -gui.countryselection.country.sw.logo.alt=Sweden-eID -gui.countryselection.country.uk=United Kingdom -gui.countryselection.country.uk.logo.alt=United Kingdom-eID - -gui.countryselection.country.testcountry=TestCountry -gui.countryselection.country.testcountry.logo.alt=Testcountry-eID - -gui.countryselection.mode.prod=Production -gui.countryselection.mode.qs=QS -gui.countryselection.mode.test=Test -gui.countryselection.mode.dev=Development \ No newline at end of file diff --git a/basicConfig/templates/countrySelection.html b/basicConfig/templates/countrySelection.html new file mode 100644 index 00000000..0c9b42bf --- /dev/null +++ b/basicConfig/templates/countrySelection.html @@ -0,0 +1,237 @@ + + + + + + + + eIDAS-Login Länderauswahl + + + + + +
+
+
+ + +

Bundesministerium für Inneres

+
+
+ +
+
+
+
+

Zentraler eIDAS Knoten der Republik Österreich

+

Betrieben durch das Bundesministerium für Inneres

+
+ +

Wählen Sie Ihr Land / Select your country

+ +
+ +
+ Germany-eID + + + +
+ +
+ + +
+ + + +
+ +

Wenn Sie Ihr Land in dieser Aufzählung nicht entdecken ...

+ +

Information zur Anmeldung über Europäische eIDs

+

+ first part + Bundesministerium für Inneres + second part +

+ +

+ third part + eIDAS-Verordnung der Europäischen Union + fourth part +

+ +

fived part + + sixed part +

+ +
+ + + diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java index 81ab02ce..e3931afe 100644 --- a/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/config/StaticResourceConfiguration.java @@ -123,6 +123,7 @@ public class StaticResourceConfiguration implements WebMvcConfigurer { final String absPath = FileUtils.makeAbsoluteUrl(staticResources, basicConfig .getConfigurationRootDirectory()); messageSource.setBasename(absPath); + messageSource.setFallbackToSystemLocale(false); } else { log.debug("No Ressourcefolder for dynamic Web content templates"); diff --git a/connector/src/main/resources/specific_eIDAS_connector.beans.xml b/connector/src/main/resources/specific_eIDAS_connector.beans.xml index e7a46657..5cf0d5b8 100644 --- a/connector/src/main/resources/specific_eIDAS_connector.beans.xml +++ b/connector/src/main/resources/specific_eIDAS_connector.beans.xml @@ -23,7 +23,7 @@ - + @@ -35,17 +35,17 @@ class="at.asitplus.eidas.specific.connector.builder.AuthenticationDataBuilder" /> + class="at.asitplus.eidas.specific.connector.config.PvpEndPointConfiguration" /> + class="at.asitplus.eidas.specific.connector.provider.PvpEndPointCredentialProvider" /> + class="at.asitplus.eidas.specific.connector.provider.PvpMetadataConfigurationFactory" /> - + class="at.asitplus.eidas.specific.connector.controller.Pvp2SProfileEndpoint"> + @@ -54,18 +54,18 @@ class="at.asitplus.eidas.specific.connector.verification.AuthnRequestValidator" /> + class="at.gv.egiz.eaaf.modules.pvp2.impl.verification.SamlVerificationEngine" /> - + - + @@ -79,22 +79,22 @@ class="at.gv.egiz.eaaf.core.impl.utils.SecurePendingRequestIdGenerationStrategy" /> + class="at.asitplus.eidas.specific.connector.provider.PvpMetadataProvider" /> + class="at.asitplus.eidas.specific.connector.builder.PvpSubjectNameGenerator" /> + class="at.asitplus.eidas.specific.connector.gui.GuiBuilderConfigurationFactory" /> + class="at.asitplus.eidas.specific.connector.gui.DefaultVelocityGuiBuilderImpl" /> + class="at.asitplus.eidas.specific.connector.gui.SpringMvcGuiFormBuilderImpl" /> diff --git a/connector/src/main/resources/specific_eIDAS_connector.storage.beans.xml b/connector/src/main/resources/specific_eIDAS_connector.storage.beans.xml index 9ee5cf88..08c7b672 100644 --- a/connector/src/main/resources/specific_eIDAS_connector.storage.beans.xml +++ b/connector/src/main/resources/specific_eIDAS_connector.storage.beans.xml @@ -18,10 +18,10 @@ /> --> + class="at.asitplus.eidas.specific.connector.storage.EidasCacheTransactionStoreDecorator" /> + class="at.asitplus.eidas.specific.connector.storage.CacheWithEidasBackend"> diff --git a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/EvaluateCountrySelectionTaskTest.java b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/EvaluateCountrySelectionTaskTest.java new file mode 100644 index 00000000..44b54366 --- /dev/null +++ b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/EvaluateCountrySelectionTaskTest.java @@ -0,0 +1,191 @@ +package at.asitplus.eidas.specific.connector.test.task; + +import java.io.UnsupportedEncodingException; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import at.asitplus.eidas.specific.connector.MsEidasNodeConstants; +import at.asitplus.eidas.specific.connector.processes.tasks.EvaluateCountrySelectionTask; +import at.gv.egiz.eaaf.core.api.data.EaafConstants; +import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; +import at.gv.egiz.eaaf.core.impl.idp.controller.tasks.AbstractLocaleAuthServletTask; +import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl; +import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ + "/applicationContext.xml", + "/specific_eIDAS_connector.beans.xml", + "/eaaf_core.beans.xml", + "/eaaf_pvp.beans.xml", + "/eaaf_pvp_idp.beans.xml", + "/spring/SpringTest-context_simple_storage.xml" }) +@WebAppConfiguration +public class EvaluateCountrySelectionTaskTest { + + @Autowired private EvaluateCountrySelectionTask task; + + private ExecutionContextImpl executionContext = new ExecutionContextImpl(); + private TestRequestImpl pendingReq; + private MockHttpServletRequest httpReq; + private MockHttpServletResponse httpResp; + + /** + * jUnit class initializer. + * + */ + @BeforeClass + public static void classInitializer() { + final String current = new java.io.File(".").toURI().toString(); + System.setProperty("eidas.ms.configuration", current + "../basicConfig/default_config.properties"); + + } + + /** + * jUnit test set-up. + * + */ + @Before + public void initialize() { + httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); + httpResp = new MockHttpServletResponse(); + RequestContextHolder.resetRequestAttributes(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); + + pendingReq = new TestRequestImpl(); + pendingReq.setAuthUrl("https://localhost/ms_connector"); + pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10)); + + LocaleContextHolder.resetLocaleContext(); + } + + @Test + public void withoutCountrySelection() throws TaskExecutionException, UnsupportedEncodingException { + + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertEquals("wrong change-language flag", false, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNull("Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertNull("Environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } + + @Test + public void withCountrySelection() throws TaskExecutionException, UnsupportedEncodingException { + String ccc = RandomStringUtils.randomAlphabetic(2); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, ccc); + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertEquals("wrong change-language flag", false, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNotNull("no Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertEquals("Wrong country found", ccc, + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + + Assert.assertNull("Environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } + + @Test + public void withCountrySelectionAndEnvironment() + throws TaskExecutionException, UnsupportedEncodingException { + String ccc = RandomStringUtils.randomAlphabetic(2); + String environment = RandomStringUtils.randomAlphabetic(5); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, ccc); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT, environment); + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertEquals("wrong change-language flag", false, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNotNull("no Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertEquals("Wrong country found", ccc, + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + + Assert.assertNotNull("No environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + Assert.assertEquals("Wrong environment-selection", environment, + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } + + @Test + public void withCountrySelectionAndEnvironmentAndLangSelection() + throws TaskExecutionException, UnsupportedEncodingException { + String ccc = RandomStringUtils.randomAlphabetic(2); + String environment = RandomStringUtils.randomAlphabetic(5); + String lang = RandomStringUtils.randomAlphabetic(2); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, ccc); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT, environment); + httpReq.setParameter(AbstractLocaleAuthServletTask.PROP_REQ_PARAM_LOCALE, lang); + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertEquals("wrong change-language flag", true, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNull("Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertNull("Environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } + + @Test + public void withCountrySelectionAndEnvironmentAndStopSelection() + throws TaskExecutionException, UnsupportedEncodingException { + String ccc = RandomStringUtils.randomAlphabetic(2); + String environment = RandomStringUtils.randomAlphabetic(5); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, ccc); + httpReq.setParameter(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT, environment); + httpReq.setParameter(EaafConstants.PARAM_HTTP_STOP_PROCESS, "true"); + + task.execute(pendingReq, executionContext); + + //result validation + Assert.assertTrue("wrong process-cancelled flag", executionContext.isProcessCancelled()); + Assert.assertTrue("wrong pendingReq stop flag", pendingReq.isAbortedByUser()); + Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + + Assert.assertEquals("wrong change-language flag", false, + executionContext.get(EaafConstants.PROCESSCONTEXT_SWITCH_LANGUAGE)); + Assert.assertNull("Country-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY)); + Assert.assertNull("Environment-selection found", + executionContext.get(MsEidasNodeConstants.REQ_PARAM_SELECTED_ENVIRONMENT)); + + } +} diff --git a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/GenerateCountrySelectionFrameTaskTest.java b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/GenerateCountrySelectionFrameTaskTest.java new file mode 100644 index 00000000..61d68774 --- /dev/null +++ b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/task/GenerateCountrySelectionFrameTaskTest.java @@ -0,0 +1,146 @@ +package at.asitplus.eidas.specific.connector.test.task; + +import java.io.UnsupportedEncodingException; +import java.util.Locale; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import at.asitplus.eidas.specific.connector.processes.tasks.GenerateCountrySelectionFrameTask; +import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; +import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl; +import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ + "/applicationContext.xml", + "/specific_eIDAS_connector.beans.xml", + "/eaaf_core.beans.xml", + "/eaaf_pvp.beans.xml", + "/eaaf_pvp_idp.beans.xml", + "/spring/SpringTest-context_simple_storage.xml" }) +@WebAppConfiguration +public class GenerateCountrySelectionFrameTaskTest { + + @Autowired private GenerateCountrySelectionFrameTask task; + + private ExecutionContextImpl executionContext = new ExecutionContextImpl(); + private TestRequestImpl pendingReq; + private MockHttpServletRequest httpReq; + private MockHttpServletResponse httpResp; + + /** + * jUnit class initializer. + * + */ + @BeforeClass + public static void classInitializer() { + final String current = new java.io.File(".").toURI().toString(); + System.setProperty("eidas.ms.configuration", current + "../basicConfig/default_config.properties"); + + } + + /** + * jUnit test set-up. + * + */ + @Before + public void initialize() { + httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); + httpResp = new MockHttpServletResponse(); + RequestContextHolder.resetRequestAttributes(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); + + pendingReq = new TestRequestImpl(); + pendingReq.setAuthUrl("https://localhost/ms_connector"); + pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10)); + + LocaleContextHolder.resetLocaleContext(); + } + + @Test + public void validHtmlResponseWithOutLocale() throws TaskExecutionException, UnsupportedEncodingException { + + task.execute(pendingReq, executionContext); + + //result validation + String html = doBasicValidation(); + + Assert.assertTrue("No english text", + html.contains("Information on Logins with European eIDs")); + + } + + @Test + public void validHtmlResponseWithDE() throws TaskExecutionException, UnsupportedEncodingException { + LocaleContextHolder.setLocale(Locale.GERMAN); + httpReq.addHeader("Accept-Language", "de"); + + task.execute(pendingReq, executionContext); + + //result validation + String html = doBasicValidation(); + + Assert.assertTrue("No english text", + html.contains("Information zur Anmeldung über Europäische eIDs")); + + } + + @Test + public void validHtmlResponseWithEN() throws TaskExecutionException, UnsupportedEncodingException { + LocaleContextHolder.setLocale(Locale.ENGLISH); + + task.execute(pendingReq, executionContext); + + //result validation + String html = doBasicValidation(); + + Assert.assertTrue("No english text", + html.contains("Information on Logins with European eIDs")); + + } + + @Test + public void validHtmlResponseWithFR() throws TaskExecutionException, UnsupportedEncodingException { + LocaleContextHolder.setLocale(Locale.FRANCE); + httpReq.addHeader("Accept-Language", "fr"); + + task.execute(pendingReq, executionContext); + + //result validation + String html = doBasicValidation(); + + Assert.assertTrue("No english text", + html.contains("Information on Logins with European eIDs")); + + } + + private String doBasicValidation() throws UnsupportedEncodingException { + Assert.assertEquals("Wrong http StatusCode", 200, httpResp.getStatus()); + Assert.assertEquals("Wrong http ContentType", "text/html;charset=UTF-8", httpResp.getContentType()); + + String html = httpResp.getContentAsString(); + Assert.assertNotNull("html result is null", html); + Assert.assertFalse("html result is empty", html.isEmpty()); + Assert.assertTrue("No language selector with pendingRequestId", + html.contains("/myHomeCountry?pendingid=" + pendingReq.getPendingRequestId())); + Assert.assertTrue("No country-selection form", + html.contains("
")); + + return html; + + } +} diff --git a/connector/src/test/resources/spring/SpringTest-context_simple_storage.xml b/connector/src/test/resources/spring/SpringTest-context_simple_storage.xml new file mode 100644 index 00000000..5ee3e0b8 --- /dev/null +++ b/connector/src/test/resources/spring/SpringTest-context_simple_storage.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file -- cgit v1.2.3