aboutsummaryrefslogtreecommitdiff
path: root/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryRequestTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryRequestTest.java')
-rw-r--r--id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryRequestTest.java864
1 files changed, 864 insertions, 0 deletions
diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryRequestTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryRequestTest.java
new file mode 100644
index 000000000..0eda1bfbf
--- /dev/null
+++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryRequestTest.java
@@ -0,0 +1,864 @@
+package eu.stork.peps.test.simple;
+
+import static org.junit.Assert.*;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.opensaml.xml.parse.BasicParserPool;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.stork.peps.auth.commons.IPersonalAttributeList;
+import eu.stork.peps.auth.commons.PersonalAttribute;
+import eu.stork.peps.auth.commons.PersonalAttributeList;
+import eu.stork.peps.auth.commons.STORKAttrQueryRequest;
+import eu.stork.peps.auth.engine.STORKSAMLEngine;
+import eu.stork.peps.exceptions.STORKSAMLEngineException;
+
+public class StorkAttrQueryRequestTest {
+
+ /** The engines. */
+ private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1");
+ private static STORKSAMLEngine engine0 = STORKSAMLEngine.getInstance("CONF0");
+ private static STORKSAMLEngine engine2 = STORKSAMLEngine.getInstance("CONF2");
+ private static STORKSAMLEngine engine3 = STORKSAMLEngine.getInstance("CONF3");
+
+
+ /**
+ * Instantiates a new stork authentication request test.
+ */
+ public StorkAttrQueryRequestTest() {
+ pal = new PersonalAttributeList();
+
+ final PersonalAttribute isAgeOver = new PersonalAttribute();
+ isAgeOver.setName("isAgeOver");
+ isAgeOver.setIsRequired(true);
+ final ArrayList<String> ages = new ArrayList<String>();
+ ages.add("16");
+ ages.add("18");
+ isAgeOver.setValue(ages);
+ pal.add(isAgeOver);
+
+ final PersonalAttribute dateOfBirth = new PersonalAttribute();
+ dateOfBirth.setName("dateOfBirth");
+ dateOfBirth.setIsRequired(false);
+ pal.add(dateOfBirth);
+
+ final PersonalAttribute eIDNumber = new PersonalAttribute();
+ eIDNumber.setName("eIdentifier");
+ eIDNumber.setIsRequired(true);
+ eIDNumber.setValue(Arrays.asList("ES/IS/1234567890"));
+ pal.add(eIDNumber);
+
+ final PersonalAttribute givenName = new PersonalAttribute();
+ givenName.setName("givenName");
+ givenName.setIsRequired(true);
+ givenName.setValue(Arrays.asList("Sveinbjorn"));
+ pal.add(givenName);
+
+ destination = "http://A-PEPS.gov.xx/PEPS/AttributeColleagueRequest";
+ assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse";
+ //spName = "University of Oxford";
+ spSector = "EDU001";
+ spInstitution = "OXF001";
+ spApplication = "APP001";
+ spCountry = "IS";
+
+ spId = "EDU001-OXF001-APP001";
+
+ }
+
+ /** The destination. */
+ private String destination;
+
+ /** The service provider sector. */
+ private String spSector;
+
+ /** The service provider institution. */
+ private String spInstitution;
+
+ /** The service provider application. */
+ private String spApplication;
+
+ /** The service provider country. */
+ private String spCountry;
+
+ /** The service provider id. */
+ private String spId;
+
+ /** The assertion consumer URL. */
+ private String assertConsumerUrl;
+
+ /** The quality authentication assurance level. */
+ private static final int QAAL = 3;
+
+ /** The List of Personal Attributes. */
+ private IPersonalAttributeList pal;
+
+ /** The attribute query request. */
+ private static byte[] attrRequest;
+
+ /** The Constant LOG. */
+ private static final Logger LOG = LoggerFactory
+ .getLogger(StorkAttrQueryRequestTest.class.getName());
+
+ /** Parser manager used to parse XML. */
+ private static BasicParserPool parser;
+
+ static {
+ parser = new BasicParserPool();
+ parser.setNamespaceAware(true);
+ }
+
+ /**
+ * Test generate authentication request.
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testGenerateAttrQueryRequest() throws STORKSAMLEngineException {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+
+ // new parameters
+ request.setEIDSectorShare(false);
+ request.setEIDCrossSectorShare(false);
+ request.setEIDCrossBorderShare(false);
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+ request.setSpCountry(spCountry);
+
+ STORKAttrQueryRequest req1 = engine0.generateSTORKAttrQueryRequest(request);
+ byte[] reqByte = req1.getTokenSaml();
+ FileOutputStream output = null;
+
+ try {
+ output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/AttrQueryRequest.xml"));
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ try {
+ output.write(reqByte);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ LOG.info("STORKAttrQueryRequest 1: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAttrQueryRequest(request).getTokenSaml()));
+
+ request.setCitizenCountryCode("IS");
+ LOG.info("STORKAttrQueryRequest 2: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAttrQueryRequest(request).getTokenSaml()));
+ }
+
+ /**
+ * Test generate authentication request error personal attribute name error.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestPALsErr1() {
+
+ final IPersonalAttributeList palWrong = new PersonalAttributeList();
+
+ final PersonalAttribute worngAttr = new PersonalAttribute();
+ worngAttr.setName("attrNotValid");
+ worngAttr.setIsRequired(true);
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(palWrong);
+
+ // news parameters
+ request.setEIDSectorShare(false);
+ request.setEIDCrossSectorShare(false);
+ request.setEIDCrossBorderShare(false);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+
+
+ /**
+ * Test generate authentication request error personal attribute value error.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestPALsErr2() {
+
+ final IPersonalAttributeList palWrong = new PersonalAttributeList();
+
+ final PersonalAttribute attrNotValid = new PersonalAttribute();
+ attrNotValid.setName("attrNotValid");
+ attrNotValid.setIsRequired(true);
+ palWrong.add(attrNotValid);
+
+
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(palWrong);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test generate authentication request authentication assurance level
+ * negative value.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestQaalErr1() {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(-1);
+ request.setPersonalAttributeList(pal);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test generate authentication request service provider sector null.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestSectorErr() {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ // news parameters
+ request.setSpSector(null);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+
+ }
+ }
+
+ /**
+ * Test generate authentication request service provider institution null.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestDestinationErr() {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(null);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(null);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+ fail("generateSTORKAttrQueryRequest(...) should've thrown an STORKSAMLEngineException!");
+
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test generate authentication request service provider application null.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestApplicationErr() {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(null);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ }
+ }
+
+ /**
+ * Test generate authentication request service provider country null.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestCountryErr() {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(null);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test generate authentication request error with quality authentication
+ * assurance level wrong.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestQaalErr2() {
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(0);
+ request.setPersonalAttributeList(pal);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test generate authentication request personal attribute list null value.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestPALErr1() {
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(null);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+
+ try {
+ engine.generateSTORKAttrQueryRequest(request);
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test validate authentication request null parameter.
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testValidateAttrQueryRequestNullParam()
+ throws STORKSAMLEngineException {
+ try {
+ engine.validateSTORKAttrQueryRequest(null);
+ fail("validateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test validate authentication request error bytes encode.
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testValidateAttrQueryRequestErrorEncode()
+ throws STORKSAMLEngineException {
+ try {
+ engine.validateSTORKAttrQueryRequest("messageError".getBytes());
+ fail("validateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test validate authentication request.
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testValidateAttrQueryRequest() throws STORKSAMLEngineException {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ attrRequest = engine.generateSTORKAttrQueryRequest(request).getTokenSaml();
+
+ final STORKAttrQueryRequest validatedRequest = engine.validateSTORKAttrQueryRequest(attrRequest);
+
+ assertEquals("CrossBorderShare incorrect: ", validatedRequest.isEIDCrossBorderShare(), false);
+ assertEquals("CrossSectorShare incorrect: ", validatedRequest.isEIDCrossSectorShare(), false);
+ assertEquals("SectorShare incorrect: ", validatedRequest.isEIDSectorShare(), false);
+
+ }
+
+ /**
+ * Test validate data authenticate request. Verified parameters after
+ * validation.
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testValidateDataAttrQueryRequest() throws STORKSAMLEngineException {
+
+ final STORKAttrQueryRequest request = engine.validateSTORKAttrQueryRequest(attrRequest);
+
+ assertEquals("Sestination incorrect: ", request.getDestination(), destination);
+
+ assertEquals("CrossBorderShare incorrect: ", request.isEIDCrossBorderShare(), false);
+ assertEquals("CrossSectorShare incorrect: ", request.isEIDCrossSectorShare(), false);
+ assertEquals("SectorShare incorrect: ", request.isEIDSectorShare(), false);
+
+ assertEquals("QAAL incorrect: ", request.getQaa(), QAAL);
+ assertEquals("SPSector incorrect: ", request.getSpSector(), spSector);
+ assertEquals("SPInstitution incorrect: ", request.getSpInstitution(), null);
+ assertEquals("SPApplication incorrect: ", request.getSpApplication(), spApplication);
+ assertEquals("CitizenCountryCode incorrect: ", request.getCitizenCountryCode(), null);
+
+ }
+
+ /**
+ * Test validate file attribute query request. Validate from XML file.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public final void testValidateFileAttrQueryRequest() throws Exception {
+
+ final byte[] bytes = SSETestUtils.readStorkSamlFromFile("/data/eu/stork/STORKSAMLEngine/AttrQueryRequest1.xml");
+
+ try {
+ engine.validateSTORKAttrQueryRequest(bytes);
+ fail("testValidateFileAttrQueryRequest(...) should've thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error(e.getMessage());
+ }
+ }
+
+ /**
+ * Test validate file authentication request tag delete.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public final void testValidateFileAttrRequestTagDelete() throws Exception {
+
+ final byte[] bytes = SSETestUtils.readStorkSamlFromFile("/data/eu/stork/STORKSAMLEngine/AttrQueryRequestTagDelete.xml");
+
+ try {
+ engine.validateSTORKAttrQueryRequest(bytes);
+ fail("validateSTORKAttrQueryRequest(...) should have thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error(e.getMessage());
+
+ }
+ }
+
+ /**
+ * Test validate authentication request not trusted token.
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testValidateAttrQueryRequestNotTrustedErr1()
+ throws STORKSAMLEngineException {
+
+ try {
+ final STORKSAMLEngine engineNotTrusted = STORKSAMLEngine
+ .getInstance("CONF2");
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+
+ final byte[] authReqNotTrust = engineNotTrusted
+ .generateSTORKAttrQueryRequest(request).getTokenSaml();
+
+ engine.validateSTORKAttrQueryRequest(authReqNotTrust);
+ fail("validateSTORKAttrQueryRequestNotTrusted(...) should have thrown an STORKSAMLEngineException!");
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ }
+ }
+
+ /**
+ * Test validate authentication request trusted.
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testValidateAttrQueryRequestTrusted()
+ throws STORKSAMLEngineException {
+
+ final STORKSAMLEngine engineTrusted = STORKSAMLEngine
+ .getInstance("CONF3");
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+
+ // news parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ final byte[] authReqNotTrust = engineTrusted.generateSTORKAttrQueryRequest(
+ request).getTokenSaml();
+
+ // engine ("CONF1") no have trust certificate from "CONF2"
+ engine.validateSTORKAttrQueryRequest(authReqNotTrust);
+
+ }
+
+
+
+
+ /**
+ * Test generate authentication request service provider application null.
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestNADA() {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+
+ // news parameters
+ request.setSpSector(null);
+ request.setSpInstitution(null);
+ request.setSpApplication(null);
+ request.setSpCountry(null);
+
+ try {
+
+ engine.validateSTORKAttrQueryRequest(attrRequest);
+
+ } catch (STORKSAMLEngineException e) {
+ LOG.error("Error");
+ fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!");
+ }
+ }
+
+ /**
+ * Test validate authentication request with unknown elements.
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testValidateAttrQueryRequestWithUnknownElements() throws STORKSAMLEngineException {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+
+ IPersonalAttributeList pAttList = new PersonalAttributeList();
+
+ final PersonalAttribute unknown = new PersonalAttribute();
+ unknown.setName("unknown");
+ unknown.setIsRequired(true);
+ pAttList.add(unknown);
+
+ final PersonalAttribute eIdentifier = new PersonalAttribute();
+ eIdentifier.setName("eIdentifier");
+ eIdentifier.setIsRequired(true);
+ pAttList.add(eIdentifier);
+
+ request.setPersonalAttributeList(pAttList);
+
+ // new parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ STORKAttrQueryRequest req = new STORKAttrQueryRequest();
+
+ req = engine3.generateSTORKAttrQueryRequest(request);
+
+ req = engine.validateSTORKAttrQueryRequest(req.getTokenSaml());
+
+ assertNull("The value shouldn't exist", req.getPersonalAttributeList().get("unknown"));
+ assertNotNull("The value should exist", req.getPersonalAttributeList().get("eIdentifier"));
+
+ }
+
+ /**
+ * Test generate Request with required elements by default
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ @Test
+ public final void testGenerateAttrQueryRequestWithIsRequiredElementsByDefault() throws STORKSAMLEngineException {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+
+ IPersonalAttributeList pAttList = new PersonalAttributeList();
+
+ final PersonalAttribute eIdentifier = new PersonalAttribute();
+ eIdentifier.setName("eIdentifier");
+ eIdentifier.setIsRequired(true);
+ pAttList.add(eIdentifier);
+
+ request.setPersonalAttributeList(pAttList);
+
+ // new parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ STORKAttrQueryRequest req = new STORKAttrQueryRequest();
+ STORKAttrQueryRequest reqTrue = new STORKAttrQueryRequest();
+ STORKAttrQueryRequest reqFalse = new STORKAttrQueryRequest();
+
+ reqTrue = engine.generateSTORKAttrQueryRequest(request);
+ reqFalse = engine2.generateSTORKAttrQueryRequest(request);
+ req = engine3.generateSTORKAttrQueryRequest(request);
+
+
+ String token = new String(req.getTokenSaml());
+ String reqTrueToken = new String(reqTrue.getTokenSaml());
+ String reqFalseToken = new String(reqFalse.getTokenSaml());
+
+ assertTrue("The token must contain the chain 'isRequired'", token.contains("isRequired"));
+ assertTrue("The token must contain the chain 'isRequired'", reqTrueToken.contains("isRequired"));
+ assertFalse("The token must contain the chain 'isRequired'", reqFalseToken.contains("isRequired"));
+
+ }
+
+ /**
+ * Test validating attribute query and getting alias used to save
+ * the saml trusted certificate into trustore
+ *
+ * @throws STORKSAMLEngineException the STORKSAML engine exception
+ */
+ /*@Test
+ public final void testValidateAtrrQueryRequestGettingItsAlias() throws STORKSAMLEngineException {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ request.setPersonalAttributeList(pal);
+
+ IPersonalAttributeList pAttList = new PersonalAttributeList();
+
+ final PersonalAttribute eIdentifier = new PersonalAttribute();
+ eIdentifier.setName("eIdentifier");
+ eIdentifier.setIsRequired(true);
+ pAttList.add(eIdentifier);
+
+ request.setPersonalAttributeList(pAttList);
+
+ // new parameters
+ request.setSpSector(spSector);
+ request.setSpInstitution(spInstitution);
+ request.setSpApplication(spApplication);
+ request.setSpCountry(spCountry);
+ request.setSPID(spId);
+ request.setCitizenCountryCode("IS");
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+
+ STORKAttrQueryRequest req = new STORKAttrQueryRequest();
+
+ req = engine3.generateSTORKAttrQueryRequest(request);
+ req = engine.validateSTORKAttrQueryRequest(req.getTokenSaml());
+ String prufa = req.getAlias();
+ assertTrue("The alias should match this value", req.getAlias().equals("local-demo"));
+
+ req = engine2.generateSTORKAttrQueryRequest(request);
+ req = engine2.validateSTORKAttrQueryRequest(req.getTokenSaml());
+ assertTrue("The alias should match this value", req.getAlias().equals("local-demo2"));
+ }*/
+
+ @Test
+ public final void testGenerateAttrQueryRequestSignDoc() throws STORKSAMLEngineException {
+
+ final STORKAttrQueryRequest request = new STORKAttrQueryRequest();
+
+ request.setDestination(destination);
+ request.setQaa(QAAL);
+ PersonalAttributeList pal0 = new PersonalAttributeList();
+
+ final PersonalAttribute signDoc = new PersonalAttribute();
+ signDoc.setName("docRequest");
+ signDoc.setIsRequired(true);
+ signDoc.setValue(Arrays.asList("IS/IS/fbea6e68-0393-401b-b616-f767fff9418c"));
+ pal0.add(signDoc);
+
+ request.setPersonalAttributeList(pal0);
+
+ // new parameters
+ /*request.setEIDSectorShare(false);
+ request.setEIDCrossSectorShare(false);
+ request.setEIDCrossBorderShare(false);*/
+ request.setAssertionConsumerServiceURL(assertConsumerUrl);
+ request.setSpCountry(spCountry);
+
+ STORKAttrQueryRequest req1 = engine0.generateSTORKAttrQueryRequest(request);
+ byte[] reqByte = req1.getTokenSaml();
+ FileOutputStream output = null;
+
+ STORKAttrQueryRequest req2 = engine0.validateSTORKAttrQueryRequest(reqByte);
+ //reqByte = req2.getTokenSaml();
+
+ try {
+ //output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/AttrQueryRequestSdoc.xml"));
+ FileOutputStream fos;
+ File outputDir = new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine");
+ File saveFile = new File(outputDir, "AttrQueryRequestSdoc.xml");
+ fos = new FileOutputStream(saveFile);
+ fos.write(reqByte);
+ fos.flush();
+ fos.close();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ try {
+ output.write(reqByte);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ LOG.info("STORKAttrQueryRequest 1: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAttrQueryRequest(request).getTokenSaml()));
+
+ request.setCitizenCountryCode("IS");
+ LOG.info("STORKAttrQueryRequest 2: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAttrQueryRequest(request).getTokenSaml()));
+ }
+
+}