aboutsummaryrefslogtreecommitdiff
path: root/connector/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'connector/src/test/java')
-rw-r--r--connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java52
-rw-r--r--connector/src/test/java/at/asitplus/eidas/specific/connector/test/saml2/Pvp2SProfileEndPointTest.java202
2 files changed, 127 insertions, 127 deletions
diff --git a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java
index 4e66d324..fd22cea4 100644
--- a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java
+++ b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/FullStartUpAndProcessTest.java
@@ -115,7 +115,7 @@ import szrservices.SignContentResponseType;
public class FullStartUpAndProcessTest {
private static final String FINAL_REDIRECT = "http://localhost/public/secure/finalizeAuthProtocol?pendingid=";
-
+
@Autowired private WebApplicationContext wac;
@Autowired private PvpEndPointCredentialProvider credentialProvider;
@Autowired private PvpMetadataProvider metadataProvider;
@@ -128,7 +128,7 @@ public class FullStartUpAndProcessTest {
@Autowired private ProtocolFinalizationController finalize;
@Autowired private IStatusMessenger messager;
-
+
@Rule
public final SoapServiceRule soap = SoapServiceRule.newInstance();
@@ -203,7 +203,7 @@ public class FullStartUpAndProcessTest {
}
LogMessageProviderFactory.setStatusMessager(messager);
-
+
szrMock = soap.mock(SZR.class, "http://localhost:1234/demoszr");
zmrClient = soap.mock(ServicePort.class, "http://localhost:1234/demozmr");
@@ -240,7 +240,7 @@ public class FullStartUpAndProcessTest {
Assert.assertFalse("selectionPage is empty", selectionPage.isEmpty());
String pendingReqId = extractRequestToken(selectionPage,
- "<input type=\"hidden\" name=\"pendingid\" value=\"");
+ "<input type=\"hidden\" name=\"pendingid\" value=\"");
Assert.assertFalse("PendingReqId", pendingReqId.isEmpty());
@@ -316,7 +316,7 @@ public class FullStartUpAndProcessTest {
Assert.assertFalse("selectionPage is empty", selectionPage.isEmpty());
String pendingReqId = extractRequestToken(selectionPage,
- "<input type=\"hidden\" name=\"pendingid\" value=\"");
+ "<input type=\"hidden\" name=\"pendingid\" value=\"");
Assert.assertFalse("PendingReqId", pendingReqId.isEmpty());
@@ -357,8 +357,8 @@ public class FullStartUpAndProcessTest {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(eidasNodeRespReq, finalizeResp));
injectZmrResponse();
- injectSzrResponse();
-
+ injectSzrResponse();
+
//excute eIDAS node response
eidasSignal.restoreEidasAuthProcess(eidasNodeRespReq, finalizeResp);
@@ -415,7 +415,7 @@ public class FullStartUpAndProcessTest {
extractor.getSingleAttributeValue("urn:eidgvat:attributes.piiTransactionId"));
Assert.assertEquals("Wrong attr:EID_STATUS_LEVEL ", "http://eid.gv.at/eID/status/identity",
extractor.getSingleAttributeValue(PvpAttributeDefinitions.EID_IDENTITY_STATUS_LEVEL_NAME));
-
+
}
private void injectSzrResponse() throws Exception {
@@ -428,52 +428,52 @@ public class FullStartUpAndProcessTest {
when(szrMock.signContent(any(), any(), any())).thenReturn(signContentResp);
}
-
+
private void injectZmrResponse() throws Exception {
ResponseType resp = new ResponseType();
-
+
WorkflowInfoServer workflow = new WorkflowInfoServer();
- workflow.setProzessInstanzID(new BigInteger(RandomStringUtils.randomNumeric(10)));
+ workflow.setProzessInstanzID(new BigInteger(RandomStringUtils.randomNumeric(10)));
resp.setWorkflowInfoServer(workflow);
PersonSuchenResponse persRespObj = new PersonSuchenResponse();
PersonensuchergebnisType searchResult = new PersonensuchergebnisType();
PersonErgebnisSatzType personInfoObj = new PersonErgebnisSatzType();
- resp.setPersonSuchenResponse(persRespObj);
- persRespObj.setPersonensuchergebnis(searchResult);
-
+ resp.setPersonSuchenResponse(persRespObj);
+ persRespObj.setPersonensuchergebnis(searchResult);
+
searchResult.setGefundeneSaetzeERnP(0);
- searchResult.setGefundeneSaetze(1);
+ searchResult.setGefundeneSaetze(1);
searchResult.getPersonErgebnisSatz().add(personInfoObj);
-
+
PersonErgebnisType personInfo = new PersonErgebnisType();
Personendaten personDataObj = new Personendaten();
personInfoObj.setPersonendaten(personDataObj);
personDataObj.getPersonErgebnis().add(personInfo);
-
+
EidasIdentitaetErgebnisType eidasPersonalIdentifier = new EidasIdentitaetErgebnisType();
personInfo.getEidasIdentitaet().add(eidasPersonalIdentifier);
eidasPersonalIdentifier.setEidasWert(personalId);
eidasPersonalIdentifier.setEidasArt(Constants.eIDAS_ATTRURN_PERSONALIDENTIFIER);
- eidasPersonalIdentifier.setStaatscode2(cc);
-
+ eidasPersonalIdentifier.setStaatscode2(cc);
+
NatuerlichePersonErgebnisType natInfo = new NatuerlichePersonErgebnisType();
IdentificationType bpk = new IdentificationType();
PersonenName natName = new PersonenName();
natInfo.getIdentification().add(bpk);
- natInfo.setPersonenName(natName);
+ natInfo.setPersonenName(natName);
personInfo.setNatuerlichePerson(natInfo);
-
+
bpk.setType(EaafConstants.URN_PREFIX_CDID + "ZP");
- bpk.setValue(RandomStringUtils.randomAlphabetic(10));
+ bpk.setValue(RandomStringUtils.randomAlphabetic(10));
natInfo.setGeburtsdatum(dateOfBirth);
natName.setFamilienname(familyName);
- natName.setVorname(givenName);
-
+ natName.setVorname(givenName);
+
when(zmrClient.service(any(), any())).thenReturn(resp);
-
+
}
-
+
private String validateEidasNodeRequestAndBuildResponse(String eidasNodeReqToken)
throws SpecificCommunicationException, URISyntaxException {
diff --git a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/saml2/Pvp2SProfileEndPointTest.java b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/saml2/Pvp2SProfileEndPointTest.java
index bcba3e11..1a2bba13 100644
--- a/connector/src/test/java/at/asitplus/eidas/specific/connector/test/saml2/Pvp2SProfileEndPointTest.java
+++ b/connector/src/test/java/at/asitplus/eidas/specific/connector/test/saml2/Pvp2SProfileEndPointTest.java
@@ -80,37 +80,37 @@ public class Pvp2SProfileEndPointTest {
@Autowired private PvpMetadataProvider metadataProvider;
@Autowired private ResourceLoader resourceLoader;
@Autowired private IRequestStorage storage;
-
+
private static CertificateFactory fact;
-
-
+
+
private MockHttpServletRequest httpReq;
private MockHttpServletResponse httpResp;
-
+
/**
* jUnit class initializer.
* @throws ComponentInitializationException In case of an error
* @throws InitializationException In case of an error
- * @throws CertificateException
- *
+ * @throws CertificateException
+ *
*/
@BeforeClass
- public static void classInitializer() throws InitializationException,
+ public static void classInitializer() throws InitializationException,
ComponentInitializationException, CertificateException {
final String current = new java.io.File(".").toURI().toString();
System.setProperty("eidas.ms.configuration", current + "src/test/resources/config/junit_config_1.properties");
-
+
EaafOpenSaml3xInitializer.eaafInitialize();
-
+
fact = CertificateFactory.getInstance("X.509");
-
+
}
-
+
/**
* jUnit test set-up.
- * @throws EaafException
- *
+ * @throws EaafException
+ *
*/
@Before
public void initialize() throws EaafException {
@@ -118,193 +118,193 @@ public class Pvp2SProfileEndPointTest {
httpResp = new MockHttpServletResponse();
RequestContextHolder.resetRequestAttributes();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
-
+
}
-
+
@Test
- public void authnReqWrongEndpoint() throws EaafException, XMLParserException, UnmarshallingException,
- UnsupportedEncodingException, TransformerException, IOException, MarshallingException,
+ public void authnReqWrongEndpoint() throws EaafException, XMLParserException, UnmarshallingException,
+ UnsupportedEncodingException, TransformerException, IOException, MarshallingException,
ComponentInitializationException {
//initialize test
final RequestAbstractType authnReq = (RequestAbstractType) XMLObjectSupport.unmarshallFromInputStream(
XMLObjectProviderRegistrySupport.getParserPool(),
Pvp2SProfileEndPointTest.class.getResourceAsStream("/data/pvp2_authn_3.xml"));
- authnReq.setIssueInstant(DateTime.now());
- RequestAbstractType signedAuthnReq =
- Saml2Utils.signSamlObject(authnReq, credentialProvider.getMetaDataSigningCredential(), true);
+ authnReq.setIssueInstant(DateTime.now());
+ RequestAbstractType signedAuthnReq =
+ Saml2Utils.signSamlObject(authnReq, credentialProvider.getMetaDataSigningCredential(), true);
String b64 = Base64Utils.encodeToString(DomUtils.serializeNode(
- XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8"));
+ XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8"));
httpReq.setParameter("SAMLRequest", b64);
-
+
final org.springframework.core.io.Resource resource = resourceLoader.getResource(
"classpath:/data/metadata_valid.xml");
Timer timer = new Timer("PVP metadata-resolver refresh");
- ResourceBackedMetadataResolver fileSystemResolver =
+ ResourceBackedMetadataResolver fileSystemResolver =
new ResourceBackedMetadataResolver(timer, new OpenSaml3ResourceAdapter(resource));
fileSystemResolver.setId("test");
fileSystemResolver.setParserPool(XMLObjectProviderRegistrySupport.getParserPool());
- fileSystemResolver.initialize();
+ fileSystemResolver.initialize();
metadataProvider.addMetadataResolverIntoChain(fileSystemResolver);
-
-
+
+
//request SAML2 authentication
try {
controller.pvpIdpPostRequest(httpReq, httpResp);
Assert.fail("wrong AuthnRequest not detected");
-
+
}catch (EaafException e) {
- Assert.assertEquals("wrong errorId", "pvp2.22", e.getErrorId());
-
- }
+ Assert.assertEquals("wrong errorId", "pvp2.22", e.getErrorId());
+
+ }
}
-
+
@Test
- public void authnReqWrongSigned() throws EaafException, XMLParserException, UnmarshallingException,
- UnsupportedEncodingException, TransformerException, IOException, MarshallingException,
+ public void authnReqWrongSigned() throws EaafException, XMLParserException, UnmarshallingException,
+ UnsupportedEncodingException, TransformerException, IOException, MarshallingException,
ComponentInitializationException {
//initialize test
final RequestAbstractType authnReq = (RequestAbstractType) XMLObjectSupport.unmarshallFromInputStream(
XMLObjectProviderRegistrySupport.getParserPool(),
Pvp2SProfileEndPointTest.class.getResourceAsStream("/data/pvp2_authn_1.xml"));
- authnReq.setIssueInstant(DateTime.now());
- RequestAbstractType signedAuthnReq =
- Saml2Utils.signSamlObject(authnReq, credentialProvider.getMetaDataSigningCredential(), true);
+ authnReq.setIssueInstant(DateTime.now());
+ RequestAbstractType signedAuthnReq =
+ Saml2Utils.signSamlObject(authnReq, credentialProvider.getMetaDataSigningCredential(), true);
String b64 = Base64Utils.encodeToString(DomUtils.serializeNode(
- XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8"));
+ XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8"));
httpReq.setParameter("SAMLRequest", b64);
-
+
final org.springframework.core.io.Resource resource = resourceLoader.getResource(
"classpath:/data/metadata_valid.xml");
Timer timer = new Timer("PVP metadata-resolver refresh");
- ResourceBackedMetadataResolver fileSystemResolver =
+ ResourceBackedMetadataResolver fileSystemResolver =
new ResourceBackedMetadataResolver(timer, new OpenSaml3ResourceAdapter(resource));
fileSystemResolver.setId("test");
fileSystemResolver.setParserPool(XMLObjectProviderRegistrySupport.getParserPool());
- fileSystemResolver.initialize();
+ fileSystemResolver.initialize();
metadataProvider.addMetadataResolverIntoChain(fileSystemResolver);
-
-
+
+
//request SAML2 authentication
try {
controller.pvpIdpPostRequest(httpReq, httpResp);
Assert.fail("wrong AuthnRequest not detected");
-
+
}catch (EaafException e) {
- Assert.assertEquals("wrong errorId", "pvp2.21", e.getErrorId());
-
- }
+ Assert.assertEquals("wrong errorId", "pvp2.21", e.getErrorId());
+
+ }
}
-
+
@Test
- public void authnReqMetadataExpired() throws EaafException, XMLParserException, UnmarshallingException,
- UnsupportedEncodingException, TransformerException, IOException, MarshallingException,
+ public void authnReqMetadataExpired() throws EaafException, XMLParserException, UnmarshallingException,
+ UnsupportedEncodingException, TransformerException, IOException, MarshallingException,
ComponentInitializationException {
//initialize test
final RequestAbstractType authnReq = (RequestAbstractType) XMLObjectSupport.unmarshallFromInputStream(
XMLObjectProviderRegistrySupport.getParserPool(),
Pvp2SProfileEndPointTest.class.getResourceAsStream("/data/pvp2_authn_1.xml"));
- authnReq.setIssueInstant(DateTime.now());
- RequestAbstractType signedAuthnReq =
- Saml2Utils.signSamlObject(authnReq, credentialProvider.getMetaDataSigningCredential(), true);
+ authnReq.setIssueInstant(DateTime.now());
+ RequestAbstractType signedAuthnReq =
+ Saml2Utils.signSamlObject(authnReq, credentialProvider.getMetaDataSigningCredential(), true);
String b64 = Base64Utils.encodeToString(DomUtils.serializeNode(
- XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8"));
+ XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8"));
httpReq.setParameter("SAMLRequest", b64);
-
+
final org.springframework.core.io.Resource resource = resourceLoader.getResource(
"classpath:/data/metadata_expired.xml");
Timer timer = new Timer("PVP metadata-resolver refresh");
- ResourceBackedMetadataResolver fileSystemResolver =
+ ResourceBackedMetadataResolver fileSystemResolver =
new ResourceBackedMetadataResolver(timer, new OpenSaml3ResourceAdapter(resource));
fileSystemResolver.setId("test");
fileSystemResolver.setParserPool(XMLObjectProviderRegistrySupport.getParserPool());
- fileSystemResolver.initialize();
+ fileSystemResolver.initialize();
metadataProvider.addMetadataResolverIntoChain(fileSystemResolver);
-
-
+
+
//request SAML2 authentication
try {
controller.pvpIdpPostRequest(httpReq, httpResp);
Assert.fail("wrong AuthnRequest not detected");
-
+
}catch (EaafException e) {
- Assert.assertEquals("wrong errorId", "pvp2.21", e.getErrorId());
-
- }
+ Assert.assertEquals("wrong errorId", "pvp2.21", e.getErrorId());
+
+ }
}
-
+
@Test
- public void authnReqValid() throws EaafException, XMLParserException, UnmarshallingException,
- UnsupportedEncodingException, TransformerException, IOException, MarshallingException,
+ public void authnReqValid() throws EaafException, XMLParserException, UnmarshallingException,
+ UnsupportedEncodingException, TransformerException, IOException, MarshallingException,
ComponentInitializationException {
//initialize test
final RequestAbstractType authnReq = (RequestAbstractType) XMLObjectSupport.unmarshallFromInputStream(
XMLObjectProviderRegistrySupport.getParserPool(),
Pvp2SProfileEndPointTest.class.getResourceAsStream("/data/pvp2_authn_1.xml"));
- authnReq.setIssueInstant(DateTime.now());
- RequestAbstractType signedAuthnReq =
- Saml2Utils.signSamlObject(authnReq, credentialProvider.getMessageSigningCredential(), true);
+ authnReq.setIssueInstant(DateTime.now());
+ RequestAbstractType signedAuthnReq =
+ Saml2Utils.signSamlObject(authnReq, credentialProvider.getMessageSigningCredential(), true);
String b64 = Base64Utils.encodeToString(DomUtils.serializeNode(
- XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8"));
+ XMLObjectSupport.getMarshaller(signedAuthnReq).marshall(signedAuthnReq)).getBytes("UTF-8"));
httpReq.setParameter("SAMLRequest", b64);
-
+
final org.springframework.core.io.Resource resource = resourceLoader.getResource(
"classpath:/data/metadata_valid.xml");
Timer timer = new Timer("PVP metadata-resolver refresh");
- ResourceBackedMetadataResolver fileSystemResolver =
+ ResourceBackedMetadataResolver fileSystemResolver =
new ResourceBackedMetadataResolver(timer, new OpenSaml3ResourceAdapter(resource));
fileSystemResolver.setId("test");
fileSystemResolver.setParserPool(XMLObjectProviderRegistrySupport.getParserPool());
- fileSystemResolver.initialize();
+ fileSystemResolver.initialize();
metadataProvider.addMetadataResolverIntoChain(fileSystemResolver);
-
-
+
+
//request SAML2 authentication
controller.pvpIdpPostRequest(httpReq, httpResp);
-
-
+
+
//validate state
Assert.assertEquals("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.assertFalse("html result is empty", html.isEmpty());
Assert.assertTrue("Wrong page", html.contains("action=\"/myHomeCountry\""));
-
- String pattern = "<input type=\"hidden\" name=\"pendingid\" value=\"";
+
+ String pattern = "<input type=\"hidden\" name=\"pendingid\" value=\"";
int pendingIdStart = html.indexOf(pattern) + pattern.length();
- int pendingIdEnd = html.indexOf("\"", pendingIdStart);
- String pendingReqId = html.substring(pendingIdStart, pendingIdEnd);
+ int pendingIdEnd = html.indexOf("\"", pendingIdStart);
+ String pendingReqId = html.substring(pendingIdStart, pendingIdEnd);
Assert.assertFalse("pendingReqId is empty", pendingReqId.isEmpty());
-
+
IRequest pendingReq = storage.getPendingRequest(pendingReqId);
- Assert.assertNotNull("pendingReq", pendingReq);
+ Assert.assertNotNull("pendingReq", pendingReq);
Assert.assertNotNull("piiTransId", pendingReq.getUniquePiiTransactionIdentifier());
Assert.assertNotNull("piiTransId", pendingReq.getUniqueTransactionIdentifier());
-
- Assert.assertEquals("wrong OA Id", "https://demo.egiz.gv.at/demoportal-openID_demo",
+
+ Assert.assertEquals("wrong OA Id", "https://demo.egiz.gv.at/demoportal-openID_demo",
pendingReq.getRawData(MsEidasNodeConstants.DATA_REQUESTERID, String.class));
- Assert.assertEquals("wrong bPK Target", "urn:publicid:gv.at:cdid+BF",
+ Assert.assertEquals("wrong bPK Target", "urn:publicid:gv.at:cdid+BF",
pendingReq.getServiceProviderConfiguration().getAreaSpecificTargetIdentifier());
-
-
+
+
}
-
+
@Test
- public void checkSaml2Metadata() throws EaafException, UnsupportedEncodingException, XMLParserException,
+ public void checkSaml2Metadata() throws EaafException, UnsupportedEncodingException, XMLParserException,
UnmarshallingException, CertificateException, SignatureException {
-
+
//request SAML2 Metadata
controller.pvpMetadataRequest(httpReq, httpResp);
-
+
//validate state
Assert.assertEquals("http statuscode", 200, httpResp.getStatus());
Assert.assertEquals("Wrong http ContentType", "application/xml", httpResp.getContentType());
-
+
String html = httpResp.getContentAsString();
Assert.assertNotNull("html result is null", html);
- Assert.assertFalse("html result is empty", html.isEmpty());
-
+ Assert.assertFalse("html result is empty", html.isEmpty());
+
final EntityDescriptor entity = (EntityDescriptor) XMLObjectSupport.unmarshallFromInputStream(
XMLObjectProviderRegistrySupport.getParserPool(),
@@ -320,18 +320,18 @@ public class Pvp2SProfileEndPointTest {
final Credential cred = new BasicX509Credential((X509Certificate) fact.generateCertificate(
Pvp2SProfileEndPointTest.class.getResourceAsStream("/config/keys/Metadata.pem")));
SignatureValidator.validate(entity.getSignature(), cred);
-
+
Assert.assertEquals("wrong entityId", "http://localhost/pvp/metadata", entity.getEntityID());
Assert.assertNotNull("IDPSSODescr", entity.getRoleDescriptors(IDPSSODescriptor.DEFAULT_ELEMENT_NAME));
Assert.assertNotNull("SPSSODescr", entity.getRoleDescriptors(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
- Assert.assertEquals("SPSSODescr. size", 0,
+ Assert.assertEquals("SPSSODescr. size", 0,
entity.getRoleDescriptors(SPSSODescriptor.DEFAULT_ELEMENT_NAME).size());
-
+
List<RoleDescriptor> idp = entity.getRoleDescriptors(IDPSSODescriptor.DEFAULT_ELEMENT_NAME);
Assert.assertEquals("IDP descr. size", 1, idp.size());
Assert.assertEquals("IDP descr. endpoints", 2, idp.get(0).getEndpoints().size());
Assert.assertEquals("IDP descr. keyDescr", 1, idp.get(0).getKeyDescriptors().size());
-
+
}
-
+
}