aboutsummaryrefslogtreecommitdiff
path: root/connector/src/test/java/at/asitplus/eidas/specific/connector/test/saml2/Pvp2SProfileEndPointTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'connector/src/test/java/at/asitplus/eidas/specific/connector/test/saml2/Pvp2SProfileEndPointTest.java')
-rw-r--r--connector/src/test/java/at/asitplus/eidas/specific/connector/test/saml2/Pvp2SProfileEndPointTest.java178
1 files changed, 89 insertions, 89 deletions
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 ebc07680..a9612297 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,12 +118,12 @@ 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(
@@ -133,34 +133,34 @@ public class Pvp2SProfileEndPointTest {
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(
@@ -170,34 +170,34 @@ public class Pvp2SProfileEndPointTest {
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(
@@ -207,34 +207,34 @@ public class Pvp2SProfileEndPointTest {
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(
@@ -244,67 +244,67 @@ public class Pvp2SProfileEndPointTest {
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());
-
+
}
-
+
}