From f71531346c6be197957311712ba093e024545e37 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Fri, 7 Aug 2015 13:24:09 +0200 Subject: preparing the old code for the merge --- .../eu/stork/peps/test/simple/SSETestUtils.java | 248 +-- .../eu/stork/peps/test/simple/SimpleBaseTest.java | 61 +- .../test/simple/StorkAttrQueryRequestTest.java | 1612 +++++++++--------- .../test/simple/StorkAttrQueryResponseTest.java | 1757 +++++++++----------- .../peps/test/simple/StorkAuthRequestTest.java | 1669 +++++++++---------- .../peps/test/simple/StorkLogoutRequestTest.java | 129 +- .../peps/test/simple/StorkLogoutResponseTest.java | 223 ++- .../peps/test/simple/StorkNewResponseTest.java | 825 +++++---- .../stork/peps/test/simple/StorkResponseTest.java | 1586 +++++++++--------- 9 files changed, 3939 insertions(+), 4171 deletions(-) (limited to 'id/server/stork2-saml-engine/src/test/java/eu') diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java index eb885eea9..b421dce8c 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java @@ -44,130 +44,130 @@ import org.w3c.dom.Element; * The Class SSETestUtils. */ public final class SSETestUtils { - - - /** The Constant LOG. */ - private static final Logger LOG = LoggerFactory - .getLogger(SSETestUtils.class.getName()); - - /** - * Instantiates a new sSE test utils. - */ - private SSETestUtils() { - } - - /** - * Prints the tree DOM. - * - * @param samlToken the SAML token - * @param isIndent the is indent - * - * @return the string - * @throws TransformerException the exception - */ - public static String printTreeDOM(final Element samlToken, final boolean isIndent) throws TransformerException { - // set up a transformer - final TransformerFactory transfac = TransformerFactory.newInstance(); - final Transformer trans = transfac.newTransformer(); - trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - trans.setOutputProperty(OutputKeys.INDENT, String.valueOf(isIndent)); - - // create string from XML tree - final StringWriter stringWriter = new StringWriter(); - final StreamResult result = new StreamResult(stringWriter); - final DOMSource source = new DOMSource(samlToken); - trans.transform(source, result); - final String xmlString = stringWriter.toString(); - - return xmlString; - } - - /** - * Marshall. - * - * @param samlToken the SAML token - * - * @return the byte[] - * - * @throws MarshallingException the marshalling exception - * @throws ParserConfigurationException the parser configuration exception - * @throws TransformerException the transformer exception - */ - public static byte[] marshall(final XMLObject samlToken) - throws MarshallingException, ParserConfigurationException, - TransformerException { - - final javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory - .newInstance(); - dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - dbf.setNamespaceAware(true); - dbf.setIgnoringComments(true); - final javax.xml.parsers.DocumentBuilder docBuild = dbf - .newDocumentBuilder(); - - // Get the marshaller factory - final MarshallerFactory marshallerFactory = Configuration - .getMarshallerFactory(); - - // Get the Subject marshaller - final Marshaller marshaller = marshallerFactory - .getMarshaller(samlToken); - - final Document doc = docBuild.newDocument(); - - // Marshall the SAML token - marshaller.marshall(samlToken, doc); - - // Obtain a byte array representation of the marshalled SAML object - final DOMSource domSource = new DOMSource(doc); - final StringWriter writer = new StringWriter(); - final StreamResult result = new StreamResult(writer); - final TransformerFactory transFact = TransformerFactory.newInstance(); - final Transformer transformer = transFact.newTransformer(); - transformer.transform(domSource, result); - - return writer.toString().getBytes(); - } - - /** - * Encode SAML token. - * - * @param samlToken the SAML token - * - * @return the string - */ - public static String encodeSAMLToken(final byte[] samlToken) { - return new String(Base64.encode(samlToken)); - } - - /** - * Read stork SAML from file. - * - * @param resource the resource - * - * @return the byte[] - * @throws IOException the exception - * - */ - public static byte[] readStorkSamlFromFile(final String resource) - throws IOException { - InputStream inputStream = null; - byte[] bytes; - - try { - inputStream = StorkAuthRequestTest.class - .getResourceAsStream(resource); - - // Create the byte array to hold the data - bytes = new byte[(int) inputStream.available()]; - inputStream.read(bytes); - } catch (IOException e) { - LOG.error("Error read from file: " + resource); - throw e; - } finally { - IOUtils.closeQuietly(inputStream); + + /** The Constant LOG. */ + private static final Logger LOG = LoggerFactory.getLogger(SSETestUtils.class.getName()); + + /** + * Instantiates a new sSE test utils. + */ + private SSETestUtils() { + } + + /** + * Prints the tree DOM. + * + * @param samlToken + * the SAML token + * @param isIndent + * the is indent + * + * @return the string + * @throws TransformerException + * the exception + */ + public static String printTreeDOM(final Element samlToken, final boolean isIndent) throws TransformerException { + // set up a transformer + final TransformerFactory transfac = TransformerFactory.newInstance(); + final Transformer trans = transfac.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + trans.setOutputProperty(OutputKeys.INDENT, String.valueOf(isIndent)); + + // create string from XML tree + final StringWriter stringWriter = new StringWriter(); + final StreamResult result = new StreamResult(stringWriter); + final DOMSource source = new DOMSource(samlToken); + trans.transform(source, result); + final String xmlString = stringWriter.toString(); + + return xmlString; + } + + /** + * Marshall. + * + * @param samlToken + * the SAML token + * + * @return the byte[] + * + * @throws MarshallingException + * the marshalling exception + * @throws ParserConfigurationException + * the parser configuration exception + * @throws TransformerException + * the transformer exception + */ + public static byte[] marshall(final XMLObject samlToken) throws MarshallingException, ParserConfigurationException, TransformerException { + + final javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); + dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + dbf.setNamespaceAware(true); + dbf.setIgnoringComments(true); + final javax.xml.parsers.DocumentBuilder docBuild = dbf.newDocumentBuilder(); + + // Get the marshaller factory + final MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); + + // Get the Subject marshaller + final Marshaller marshaller = marshallerFactory.getMarshaller(samlToken); + + final Document doc = docBuild.newDocument(); + + // Marshall the SAML token + marshaller.marshall(samlToken, doc); + + // Obtain a byte array representation of the marshalled SAML object + final DOMSource domSource = new DOMSource(doc); + final StringWriter writer = new StringWriter(); + final StreamResult result = new StreamResult(writer); + final TransformerFactory transFact = TransformerFactory.newInstance(); + final Transformer transformer = transFact.newTransformer(); + transformer.transform(domSource, result); + + return writer.toString().getBytes(); + } + + /** + * Encode SAML token. + * + * @param samlToken + * the SAML token + * + * @return the string + */ + public static String encodeSAMLToken(final byte[] samlToken) { + return new String(Base64.encode(samlToken)); } - return bytes; - } + /** + * Read stork SAML from file. + * + * @param resource + * the resource + * + * @return the byte[] + * @throws IOException + * the exception + * + */ + public static byte[] readStorkSamlFromFile(final String resource) throws IOException { + InputStream inputStream = null; + byte[] bytes; + + try { + inputStream = StorkAuthRequestTest.class.getResourceAsStream(resource); + + // Create the byte array to hold the data + bytes = new byte[(int) inputStream.available()]; + inputStream.read(bytes); + } catch (IOException e) { + LOG.error("Error read from file: " + resource); + throw e; + } finally { + IOUtils.closeQuietly(inputStream); + } + return bytes; + + } } diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SimpleBaseTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SimpleBaseTest.java index c52b8a779..bdb8780c3 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SimpleBaseTest.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SimpleBaseTest.java @@ -22,43 +22,42 @@ import junit.framework.TestCase; import eu.stork.peps.auth.engine.STORKSAMLEngine; /** - * The Class SimpleBaseTest. Defines a set of test the initialization of the - * SAML engine. + * The Class SimpleBaseTest. Defines a set of test the initialization of the SAML engine. */ @SuppressWarnings("deprecation") public class SimpleBaseTest extends TestCase { - /** - * Test SAML engine correct configuration name. - */ - + /** + * Test SAML engine correct configuration name. + */ + @Test - public final void testSamlEngineCorrectInit() { - Assert.assertNotNull(STORKSAMLEngine.getInstance("CONF1")); - } + public final void testSamlEngineCorrectInit() { + Assert.assertNotNull(STORKSAMLEngine.getInstance("CONF1")); + } - /** - * Test SAML engine error configuration name. - */ - @Test - public final void testSamlEngineErrorNameConf() { - Assert.assertNull(STORKSAMLEngine.getInstance("CONF_ERROR")); - } + /** + * Test SAML engine error configuration name. + */ + @Test + public final void testSamlEngineErrorNameConf() { + Assert.assertNull(STORKSAMLEngine.getInstance("CONF_ERROR")); + } - /** - * Test SAML engine error name null. - */ - @Test - public final void testSamlEngineErrorNameNull() { - Assert.assertNull(STORKSAMLEngine.getInstance(null)); - } + /** + * Test SAML engine error name null. + */ + @Test + public final void testSamlEngineErrorNameNull() { + Assert.assertNull(STORKSAMLEngine.getInstance(null)); + } + + /** + * Test SAML engine correct name configuration with spaces. + */ + @Test + public final void testSamlEngineErrorNameSpaces() { + Assert.assertNotNull(STORKSAMLEngine.getInstance(" CONF1 ")); + } - /** - * Test SAML engine correct name configuration with spaces. - */ - @Test - public final void testSamlEngineErrorNameSpaces() { - Assert.assertNotNull(STORKSAMLEngine.getInstance(" CONF1 ")); - } - } 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 index 0eda1bfbf..502e0e461 100644 --- 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 @@ -20,845 +20,821 @@ 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 ages = new ArrayList(); - 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(); + + /** 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 ages = new ArrayList(); + 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"; + } - try { - output.write(reqByte); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + + /** 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); } - - 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. + * + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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. - * - * @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 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 validate file authentication request tag delete. - * - * @throws Exception the exception - */ - @Test - public final void testValidateFileAttrRequestTagDelete() throws Exception { + /** + * 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); - final byte[] bytes = SSETestUtils.readStorkSamlFromFile("/data/eu/stork/STORKSAMLEngine/AttrQueryRequestTagDelete.xml"); + try { - try { - engine.validateSTORKAttrQueryRequest(bytes); - fail("validateSTORKAttrQueryRequest(...) should have thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error(e.getMessage()); + engine.validateSTORKAttrQueryRequest(attrRequest); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + } } - } - - /** - * 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 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(); + + /** + * 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")); + } - try { - output.write(reqByte); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + + /** + * 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())); } - - LOG.info("STORKAttrQueryRequest 1: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAttrQueryRequest(request).getTokenSaml())); - - request.setCitizenCountryCode("IS"); - LOG.info("STORKAttrQueryRequest 2: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAttrQueryRequest(request).getTokenSaml())); - } - + } diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryResponseTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryResponseTest.java index a98d5b7c3..0ecca1eab 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryResponseTest.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAttrQueryResponseTest.java @@ -36,842 +36,763 @@ import eu.stork.peps.auth.engine.STORKSAMLEngine; import eu.stork.peps.exceptions.STORKSAMLEngineException; public class StorkAttrQueryResponseTest { - + /** The engine. */ - private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); - - /** - * Gets the engine. - * - * @return the engine - */ - public static STORKSAMLEngine getEngine() { - return engine; - } - - /** - * Sets the engine. - * - * @param newEngine the new engine - */ - public static void setEngine(final STORKSAMLEngine newEngine) { - StorkAttrQueryResponseTest.engine = newEngine; - } - - /** The destination. */ - private static String destination; - - /** The service provider sector. */ - private static String spSector; - - /** The service provider institution. */ - private static String spInstitution; - - /** The service provider application. */ - private static String spApplication; - - /** The service provider country. */ - private static String spCountry; - - /** The service provider id. */ - private static String spId; - - /** The quality authentication assurance level. */ - private static final int QAAL = 3; - - /** The state. */ - private static String state = "IS"; - - /** The town. */ - private static String town = "Reykjavik"; - - /** The postal code. */ - private static String postalCode = "105"; - - /** The street name. */ - private static String streetName = "Gudrunartun"; - - /** The street number. */ - private static String streetNumber = "10"; - - /** The List of Personal Attributes. */ - private static IPersonalAttributeList pal; - - /** The assertion consumer URL. */ - private static String assertConsumerUrl; - - /** The attribute query request. */ - private static byte[] attrQueryRequest; - - /** The attribute query response. */ - private static byte[] attrQueryResponse; - - /** The attribute query request. */ - private static STORKAttrQueryRequest attrQueryenRequest; - - /** The attribute query response. */ - private static STORKAttrQueryResponse attrQeuryenResponse; - - /** The Constant LOG. */ - private static final Logger LOG = LoggerFactory - .getLogger(StorkAttrQueryResponseTest.class.getName()); - - /** - * Instantiates a new stork response test. - */ - public StorkAttrQueryResponseTest() { - super(); - } - - /** The IP address. */ - private static String ipAddress; - - /** The destination URL. */ - private static String destinationUrl; - - /** The is hashing. */ - private final boolean isHashing = Boolean.TRUE; - - /** The is not hashing. */ - private final boolean isNotHashing = Boolean.FALSE; - - /** The ERROR text. */ - private static final String ERROR_TXT = "generateAttrQueryResponse(...) should've thrown an STORKSAMLEngineException!"; - - - /** Parser manager used to parse XML. */ - private static BasicParserPool parser; - - - - static { - parser = new BasicParserPool(); - parser.setNamespaceAware(true); - - pal = new PersonalAttributeList(); - - PersonalAttribute isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(false); - ArrayList ages = new ArrayList(); - ages.add("16"); - ages.add("18"); - isAgeOver.setValue(ages); - pal.add(isAgeOver); - - PersonalAttribute dateOfBirth = new PersonalAttribute(); - dateOfBirth.setName("dateOfBirth"); - dateOfBirth.setIsRequired(false); - pal.add(dateOfBirth); - - PersonalAttribute eIDNumber = new PersonalAttribute(); - eIDNumber.setName("eIdentifier"); - List eid = Arrays.asList("IS/IS/1234567890"); - eIDNumber.setValue(eid); - eIDNumber.setIsRequired(true); - pal.add(eIDNumber); - - final PersonalAttribute givenName = new PersonalAttribute(); - givenName.setName("givenName"); - givenName.setIsRequired(true); - pal.add(givenName); - - PersonalAttribute canRessAddress = new PersonalAttribute(); - canRessAddress.setName("canonicalResidenceAddress"); - canRessAddress.setIsRequired(true); - pal.add(canRessAddress); - - PersonalAttribute newAttribute = new PersonalAttribute(); - newAttribute.setName("newAttribute2"); - newAttribute.setIsRequired(true); - pal.add(newAttribute); - - destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; - assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; - spSector = "EDU001"; - spInstitution = "OXF001"; - spApplication = "APP001"; - spCountry = "EN"; - - spId = "EDU001-APP001-APP001"; - - final STORKAttrQueryRequest request = new STORKAttrQueryRequest(); - request.setDestination(destination); - //request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // new parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("IS"); - - try { - attrQueryRequest = getEngine().generateSTORKAttrQueryRequest(request) - .getTokenSaml(); - - attrQueryenRequest = getEngine().validateSTORKAttrQueryRequest(attrQueryRequest); - - } catch (STORKSAMLEngineException e) { - fail("Error create STORKAuthnRequest"); + private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); + + /** + * Gets the engine. + * + * @return the engine + */ + public static STORKSAMLEngine getEngine() { + return engine; } - ipAddress = "111.222.333.444"; - - destinationUrl = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; - - pal = new PersonalAttributeList(); - - isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(true); - ages = new ArrayList(); - - ages.add("16"); - ages.add("18"); - - isAgeOver.setValue(ages); - isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(isAgeOver); - - dateOfBirth = new PersonalAttribute(); - dateOfBirth.setName("dateOfBirth"); - dateOfBirth.setIsRequired(false); - final ArrayList date = new ArrayList(); - date.add("16/12/2008"); - dateOfBirth.setValue(date); - dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(dateOfBirth); - - eIDNumber = new PersonalAttribute(); - eIDNumber.setName("eIdentifier"); - eIDNumber.setIsRequired(true); - final ArrayList idNumber = new ArrayList(); - idNumber.add("123456789IS"); - eIDNumber.setValue(idNumber); - eIDNumber.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(eIDNumber); - - canRessAddress = new PersonalAttribute(); - canRessAddress.setName("canonicalResidenceAddress"); - canRessAddress.setIsRequired(true); - canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - final HashMap address = new HashMap(); - - address.put("state", state); - address.put("town", town); - address.put("postalCode", postalCode); - address.put("streetName", streetName); - address.put("streetNumber", streetNumber); - - canRessAddress.setComplexValue(address); - pal.add(canRessAddress); - - newAttribute = new PersonalAttribute(); - newAttribute.setName("newAttribute2"); - newAttribute.setIsRequired(true); - newAttribute.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - final HashMap values = new HashMap(); - - values.put("value1", "value1"); - values.put("value2", "value2"); - values.put("value3", "value3"); - values.put("value4", "value4"); - - newAttribute.setComplexValue(values); - pal.add(newAttribute); - - } - - /** - * Test generate attribute query request without errors. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testGenerateAttrQueryResponse() throws STORKSAMLEngineException { - - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setPersonalAttributeList(pal); - - final STORKAttrQueryResponse storkResponse = getEngine() - .generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, - destinationUrl, isNotHashing); - - attrQueryResponse = storkResponse.getTokenSaml(); - - FileOutputStream output = null; - - try { - output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/AttrQueryResponse.xml")); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + /** + * Sets the engine. + * + * @param newEngine + * the new engine + */ + public static void setEngine(final STORKSAMLEngine newEngine) { + StorkAttrQueryResponseTest.engine = newEngine; } - try { - output.write(attrQueryResponse); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + + /** The destination. */ + private static String destination; + + /** The service provider sector. */ + private static String spSector; + + /** The service provider institution. */ + private static String spInstitution; + + /** The service provider application. */ + private static String spApplication; + + /** The service provider country. */ + private static String spCountry; + + /** The service provider id. */ + private static String spId; + + /** The quality authentication assurance level. */ + private static final int QAAL = 3; + + /** The state. */ + private static String state = "IS"; + + /** The town. */ + private static String town = "Reykjavik"; + + /** The postal code. */ + private static String postalCode = "105"; + + /** The street name. */ + private static String streetName = "Gudrunartun"; + + /** The street number. */ + private static String streetNumber = "10"; + + /** The List of Personal Attributes. */ + private static IPersonalAttributeList pal; + + /** The assertion consumer URL. */ + private static String assertConsumerUrl; + + /** The attribute query request. */ + private static byte[] attrQueryRequest; + + /** The attribute query response. */ + private static byte[] attrQueryResponse; + + /** The attribute query request. */ + private static STORKAttrQueryRequest attrQueryenRequest; + + /** The attribute query response. */ + private static STORKAttrQueryResponse attrQeuryenResponse; + + /** The Constant LOG. */ + private static final Logger LOG = LoggerFactory.getLogger(StorkAttrQueryResponseTest.class.getName()); + + /** + * Instantiates a new stork response test. + */ + public StorkAttrQueryResponseTest() { + super(); } - - LOG.info("RESPONSE: " + SSETestUtils.encodeSAMLToken(attrQueryResponse)); - - - } - - /** - * Test validation id parameter mandatory. - */ - @Test - public final void testResponseMandatoryId() { - final String identifier = attrQueryenRequest.getSamlId(); - attrQueryenRequest.setSamlId(null); - - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setPersonalAttributeList(pal); - - try { - getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, - ipAddress, destinationUrl, isHashing); - fail(ERROR_TXT); - } catch (STORKSAMLEngineException e) { - attrQueryenRequest.setSamlId(identifier); - LOG.error("Error"); + + /** The IP address. */ + private static String ipAddress; + + /** The destination URL. */ + private static String destinationUrl; + + /** The is hashing. */ + private final boolean isHashing = Boolean.TRUE; + + /** The is not hashing. */ + private final boolean isNotHashing = Boolean.FALSE; + + /** The ERROR text. */ + private static final String ERROR_TXT = "generateAttrQueryResponse(...) should've thrown an STORKSAMLEngineException!"; + + /** Parser manager used to parse XML. */ + private static BasicParserPool parser; + + static { + parser = new BasicParserPool(); + parser.setNamespaceAware(true); + + pal = new PersonalAttributeList(); + + PersonalAttribute isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(false); + ArrayList ages = new ArrayList(); + ages.add("16"); + ages.add("18"); + isAgeOver.setValue(ages); + pal.add(isAgeOver); + + PersonalAttribute dateOfBirth = new PersonalAttribute(); + dateOfBirth.setName("dateOfBirth"); + dateOfBirth.setIsRequired(false); + pal.add(dateOfBirth); + + PersonalAttribute eIDNumber = new PersonalAttribute(); + eIDNumber.setName("eIdentifier"); + List eid = Arrays.asList("IS/IS/1234567890"); + eIDNumber.setValue(eid); + eIDNumber.setIsRequired(true); + pal.add(eIDNumber); + + final PersonalAttribute givenName = new PersonalAttribute(); + givenName.setName("givenName"); + givenName.setIsRequired(true); + pal.add(givenName); + + PersonalAttribute canRessAddress = new PersonalAttribute(); + canRessAddress.setName("canonicalResidenceAddress"); + canRessAddress.setIsRequired(true); + pal.add(canRessAddress); + + PersonalAttribute newAttribute = new PersonalAttribute(); + newAttribute.setName("newAttribute2"); + newAttribute.setIsRequired(true); + pal.add(newAttribute); + + destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; + assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; + spSector = "EDU001"; + spInstitution = "OXF001"; + spApplication = "APP001"; + spCountry = "EN"; + + spId = "EDU001-APP001-APP001"; + + final STORKAttrQueryRequest request = new STORKAttrQueryRequest(); + request.setDestination(destination); + // request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // new parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("IS"); + + try { + attrQueryRequest = getEngine().generateSTORKAttrQueryRequest(request).getTokenSaml(); + + attrQueryenRequest = getEngine().validateSTORKAttrQueryRequest(attrQueryRequest); + + } catch (STORKSAMLEngineException e) { + fail("Error create STORKAuthnRequest"); + } + + ipAddress = "111.222.333.444"; + + destinationUrl = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; + + pal = new PersonalAttributeList(); + + isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(true); + ages = new ArrayList(); + + ages.add("16"); + ages.add("18"); + + isAgeOver.setValue(ages); + isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(isAgeOver); + + dateOfBirth = new PersonalAttribute(); + dateOfBirth.setName("dateOfBirth"); + dateOfBirth.setIsRequired(false); + final ArrayList date = new ArrayList(); + date.add("16/12/2008"); + dateOfBirth.setValue(date); + dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(dateOfBirth); + + eIDNumber = new PersonalAttribute(); + eIDNumber.setName("eIdentifier"); + eIDNumber.setIsRequired(true); + final ArrayList idNumber = new ArrayList(); + idNumber.add("123456789IS"); + eIDNumber.setValue(idNumber); + eIDNumber.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(eIDNumber); + + canRessAddress = new PersonalAttribute(); + canRessAddress.setName("canonicalResidenceAddress"); + canRessAddress.setIsRequired(true); + canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + final HashMap address = new HashMap(); + + address.put("state", state); + address.put("town", town); + address.put("postalCode", postalCode); + address.put("streetName", streetName); + address.put("streetNumber", streetNumber); + + canRessAddress.setComplexValue(address); + pal.add(canRessAddress); + + newAttribute = new PersonalAttribute(); + newAttribute.setName("newAttribute2"); + newAttribute.setIsRequired(true); + newAttribute.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + final HashMap values = new HashMap(); + + values.put("value1", "value1"); + values.put("value2", "value2"); + values.put("value3", "value3"); + values.put("value4", "value4"); + + newAttribute.setComplexValue(values); + pal.add(newAttribute); + } - } - - /** - * Test generate attribute query response in response to err1. - */ - @Test - public final void testResponseMandatoryIssuer() { - - final String issuer = attrQueryenRequest.getIssuer(); - attrQueryenRequest.setIssuer(null); - - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setPersonalAttributeList(pal); - - try { - getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, - ipAddress, destinationUrl, isHashing); - fail(ERROR_TXT); - } catch (STORKSAMLEngineException e) { - attrQueryenRequest.setIssuer(issuer); - LOG.error("Error"); + + /** + * Test generate attribute query request without errors. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateAttrQueryResponse() throws STORKSAMLEngineException { + + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setPersonalAttributeList(pal); + + final STORKAttrQueryResponse storkResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing); + + attrQueryResponse = storkResponse.getTokenSaml(); + + FileOutputStream output = null; + + try { + output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/AttrQueryResponse.xml")); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + output.write(attrQueryResponse); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + LOG.info("RESPONSE: " + SSETestUtils.encodeSAMLToken(attrQueryResponse)); + } - } - - - /** - * Test generate attribute query response assertion consumer null. - */ - /*@Test - public final void testResponseMandatoryAssertionConsumerServiceURL() { - final String asserConsumerUrl = attrQueryenRequest - .getAssertionConsumerServiceURL(); - attrQueryenRequest.setAssertionConsumerServiceURL(null); - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setPersonalAttributeList(pal); - try { - getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, - ipAddress, isHashing); - fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - attrQueryenRequest.setAssertionConsumerServiceURL(asserConsumerUrl); - LOG.error("Error"); + + /** + * Test validation id parameter mandatory. + */ + @Test + public final void testResponseMandatoryId() { + final String identifier = attrQueryenRequest.getSamlId(); + attrQueryenRequest.setSamlId(null); + + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setPersonalAttributeList(pal); + + try { + getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isHashing); + fail(ERROR_TXT); + } catch (STORKSAMLEngineException e) { + attrQueryenRequest.setSamlId(identifier); + LOG.error("Error"); + } } - } - - /** - * Test generate attribute query response IP address null. - */ - @Test - public final void testResponseValidationIP() { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setPersonalAttributeList(pal); - - try { - getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, null, - destinationUrl, isHashing); - fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate attribute query response in response to err1. + */ + @Test + public final void testResponseMandatoryIssuer() { + + final String issuer = attrQueryenRequest.getIssuer(); + attrQueryenRequest.setIssuer(null); + + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setPersonalAttributeList(pal); + + try { + getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isHashing); + fail(ERROR_TXT); + } catch (STORKSAMLEngineException e) { + attrQueryenRequest.setIssuer(issuer); + LOG.error("Error"); + } } - } - - /** - * Test generate attribute query response with personal attribute list null. - */ - @Test - public final void testResponseMandatoryPersonalAttributeList() { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setPersonalAttributeList(null); - - - try { - getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, - ipAddress, destinationUrl, isHashing); - fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate attribute query response assertion consumer null. + */ + /* + * @Test public final void testResponseMandatoryAssertionConsumerServiceURL() { final String asserConsumerUrl = attrQueryenRequest .getAssertionConsumerServiceURL(); + * attrQueryenRequest.setAssertionConsumerServiceURL(null); + * + * final STORKAuthnResponse response = new STORKAuthnResponse(); response.setPersonalAttributeList(pal); try { getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, + * isHashing); fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); } catch (STORKSAMLEngineException e) { + * attrQueryenRequest.setAssertionConsumerServiceURL(asserConsumerUrl); LOG.error("Error"); } } + * + * /** Test generate attribute query response IP address null. + */ + @Test + public final void testResponseValidationIP() { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setPersonalAttributeList(pal); + + try { + getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, null, destinationUrl, isHashing); + fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test validate attribute query response token null. - */ - @Test - public final void testResponseInvalidParametersToken() { - try { - getEngine().validateSTORKAttrQueryResponse(null, ipAddress); - fail(ERROR_TXT); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate attribute query response with personal attribute list null. + */ + @Test + public final void testResponseMandatoryPersonalAttributeList() { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setPersonalAttributeList(null); + + try { + getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isHashing); + fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test validate attribute query response IP null. - */ - @Test - public final void STORKAttrQueryResponse() { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setPersonalAttributeList(pal); - try { - attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate attribute query response token null. + */ + @Test + public final void testResponseInvalidParametersToken() { + try { + getEngine().validateSTORKAttrQueryResponse(null, ipAddress); + fail(ERROR_TXT); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate attribute query response parameter name wrong. - */ - @Test - public final void testResponseInvalidParametersAttr() { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("AttrWrong"); - wrongList.add(worngAttr); - - - response.setPersonalAttributeList(wrongList); - try { - attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate attribute query response IP null. + */ + @Test + public final void STORKAttrQueryResponse() { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setPersonalAttributeList(pal); + try { + attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate attribute query response set null value into attribute. - */ - @Test - public final void testResponseInvalidParametersAttrSimpleValue() { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("isAgeOver"); - worngAttr.setValue(null); - wrongList.add(worngAttr); - - response.setPersonalAttributeList(wrongList); - try { - attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate attribute query response parameter name wrong. + */ + @Test + public final void testResponseInvalidParametersAttr() { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("AttrWrong"); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate attribute query response set null value into attribute. - */ - @Test - public final void testResponseInvalidParametersAttrNoValue() { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("isAgeOver"); - wrongList.add(worngAttr); - - response.setPersonalAttributeList(wrongList); - try { - attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate attribute query response set null value into attribute. + */ + @Test + public final void testResponseInvalidParametersAttrSimpleValue() { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("isAgeOver"); + worngAttr.setValue(null); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate attribute query response set null value into attribute. - */ - @Test - public final void testResponseInvalidParametersAttrNoName() { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - wrongList.add(worngAttr); - - response.setPersonalAttributeList(wrongList); - try { - attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate attribute query response set null value into attribute. + */ + @Test + public final void testResponseInvalidParametersAttrNoValue() { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("isAgeOver"); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } + } + + /** + * Test validate attribute query response set null value into attribute. + */ + @Test + public final void testResponseInvalidParametersAttrNoName() { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } + } + + /** + * Test validate attribute query response set null complex value into attribute. + */ + @Test + public final void testResponseInvalidParametersAttrComplexValue() { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("isAgeOver"); + worngAttr.setComplexValue(null); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate attribute query response set null complex value into attribute. - */ - @Test - public final void testResponseInvalidParametersAttrComplexValue() { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("isAgeOver"); - worngAttr.setComplexValue(null); - wrongList.add(worngAttr); - - response.setPersonalAttributeList(wrongList); - try { - attrQueryResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate attribute query response IP distinct and disabled validation IP. + */ + @Test + public final void testResponseInvalidParametersIPDistinct() { + try { + // ipAddress origin "111.222.333.444" + // ipAddrValidation = false + // Subject Confirmation Bearer. + + getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, "127.0.0.1"); + } catch (STORKSAMLEngineException e) { + fail("validateAttributeQueryResponse(...) should've thrown an STORKSAMLEngineException!"); + LOG.error("Error"); + } + } + + /** + * Test response invalid parameters invalid token. + */ + @Test + public final void testResponseInvalidParametersTokenMsg() { + try { + // ipAddress origin "111.222.333.444" + // Subject Confirmation Bearer. + getEngine().validateSTORKAttrQueryResponse("errorMessage".getBytes(), ipAddress); + fail("validateAuthenticationResponse(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - - - /** - * Test validate attribute query response IP distinct and disabled validation - * IP. - */ - @Test - public final void testResponseInvalidParametersIPDistinct() { - try { - // ipAddress origin "111.222.333.444" - // ipAddrValidation = false - // Subject Confirmation Bearer. - - getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, "127.0.0.1"); - } catch (STORKSAMLEngineException e) { - fail("validateAttributeQueryResponse(...) should've thrown an STORKSAMLEngineException!"); - LOG.error("Error"); + + /** + * Test validate attribute query response is fail. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + /* + * @Test public final void testValidateAuthenticationResponseIsFail() throws STORKSAMLEngineException { attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, + * ipAddress); + * + * assertFalse("Generate incorrect response: ", attrQeuryenResponse.isFail()); } + * + * /** Test validate attribute query response destination. + * + * @throws STORKSAMLEngineException the STORKSAML engine exception + */ + @Test + public final void testValidateAuthenticationResponseDestination() throws STORKSAMLEngineException { + attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress); + + assertEquals("Destination incorrect: ", attrQeuryenResponse.getInResponseTo(), attrQueryenRequest.getSamlId()); } - } - - /** - * Test response invalid parameters invalid token. - */ - @Test - public final void testResponseInvalidParametersTokenMsg() { - try { - // ipAddress origin "111.222.333.444" - // Subject Confirmation Bearer. - getEngine().validateSTORKAttrQueryResponse("errorMessage".getBytes(), - ipAddress); - fail("validateAuthenticationResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate attribute query response values. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAuthenticationResponseValuesComplex() throws STORKSAMLEngineException { + attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress); + + assertEquals("Country incorrect:", attrQeuryenResponse.getCountry(), "ES"); + + final Iterator iterator = attrQeuryenResponse.getPersonalAttributeList().iterator(); + + while (iterator.hasNext()) { + final PersonalAttribute attribute = iterator.next(); + if (attribute.getName().equalsIgnoreCase("canonicalResidenceAddress")) { + assertEquals("State incorrect: ", state, attribute.getComplexValue().get("state")); + assertEquals("Town incorrect: ", town, attribute.getComplexValue().get("town")); + assertEquals("Postal code incorrect: ", postalCode, attribute.getComplexValue().get("postalCode")); + assertEquals("Street name incorrect: ", streetName, attribute.getComplexValue().get("streetName")); + assertEquals("Street number incorrect: ", streetNumber, attribute.getComplexValue().get("streetNumber")); + } + } } - } - - /** - * Test validate attribute query response is fail. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - /*@Test - public final void testValidateAuthenticationResponseIsFail() - throws STORKSAMLEngineException { - attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, - ipAddress); - - assertFalse("Generate incorrect response: ", attrQeuryenResponse.isFail()); - } - - /** - * Test validate attribute query response destination. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthenticationResponseDestination() - throws STORKSAMLEngineException { - attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, - ipAddress); - - assertEquals("Destination incorrect: ", - attrQeuryenResponse.getInResponseTo(), attrQueryenRequest.getSamlId()); - } - - /** - * Test validate attribute query response values. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthenticationResponseValuesComplex() - throws STORKSAMLEngineException { - attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, - ipAddress); - - assertEquals("Country incorrect:", attrQeuryenResponse.getCountry(), "ES"); - - final Iterator iterator = attrQeuryenResponse - .getPersonalAttributeList().iterator(); - - while (iterator.hasNext()) { - final PersonalAttribute attribute = iterator.next(); - if (attribute.getName().equalsIgnoreCase( - "canonicalResidenceAddress")) { - assertEquals("State incorrect: ", state, attribute - .getComplexValue().get("state")); - assertEquals("Town incorrect: ", town, attribute - .getComplexValue().get("town")); - assertEquals("Postal code incorrect: ", postalCode, attribute - .getComplexValue().get("postalCode")); - assertEquals("Street name incorrect: ", streetName, attribute - .getComplexValue().get("streetName")); - assertEquals("Street number incorrect: ", streetNumber, - attribute.getComplexValue().get("streetNumber")); - } + + /** + * Test generate attribute query response fail in response to it's null. + * + * @throws STORKSAMLEngineException + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + // ( expected=STORKSAMLEngineException.class) + public final void testGenerateAttrQueryResponseFailInResponseToNull() throws STORKSAMLEngineException { + final String identifier = attrQueryenRequest.getSamlId(); + attrQueryenRequest.setSamlId(null); + + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); + response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); + response.setMessage(""); + + try { + attrQueryResponse = getEngine().generateSTORKAttrQueryResponseFail(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + fail(ERROR_TXT); + } catch (STORKSAMLEngineException e) { + attrQueryenRequest.setSamlId(identifier); + LOG.error("Error"); + // throw new STORKSAMLEngineException(e); + } } - } - - /** - * Test generate attribute query response fail in response to it's null. - * @throws STORKSAMLEngineException - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test //( expected=STORKSAMLEngineException.class) - public final void testGenerateAttrQueryResponseFailInResponseToNull() throws STORKSAMLEngineException { - final String identifier = attrQueryenRequest.getSamlId(); - attrQueryenRequest.setSamlId(null); - - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); - response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); - response.setMessage(""); - - try { - attrQueryResponse = getEngine().generateSTORKAttrQueryResponseFail(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - fail(ERROR_TXT); - } catch (STORKSAMLEngineException e) { - attrQueryenRequest.setSamlId(identifier); - LOG.error("Error"); - //throw new STORKSAMLEngineException(e); + + /** + * Test generate attribute query response fail assertion consumer URL err1. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + /* + * @Test public final void testGenerateAuthnResponseFailAssertionConsumerUrlNull() throws STORKSAMLEngineException { + * + * final String assertConsumerUrl = attrQueryenRequest .getAssertionConsumerServiceURL(); attrQueryenRequest.setAssertionConsumerServiceURL(null); + * + * final STORKAuthnResponse response = new STORKAuthnResponse(); response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); + * response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); response.setMessage(""); + * + * try { attrQueryResponse = getEngine().generateSTORKAuthnResponseFail(attrQueryenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + * fail("generateAuthnResponseFail(...) should've thrown an STORKSAMLEngineException!"); } catch (STORKSAMLEngineException e) { + * attrQueryenRequest.setAssertionConsumerServiceURL(assertConsumerUrl); LOG.error("Error"); } } + * + * /** Test generate attribute query response fail code error err1. + * + * @throws STORKSAMLEngineException the STORKSAML engine exception + */ + @Test + public final void testGenerateAttrQueryResponseFailCodeErrorNull() throws STORKSAMLEngineException { + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setStatusCode(null); + response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); + response.setMessage(""); + + try { + attrQueryResponse = getEngine().generateSTORKAttrQueryResponseFail(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + fail("generateAttrQueryResponseFail(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test generate attribute query response fail assertion consumer URL err1. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - /*@Test - public final void testGenerateAuthnResponseFailAssertionConsumerUrlNull() - throws STORKSAMLEngineException { - - final String assertConsumerUrl = attrQueryenRequest - .getAssertionConsumerServiceURL(); - attrQueryenRequest.setAssertionConsumerServiceURL(null); - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); - response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); - response.setMessage(""); - - try { - attrQueryResponse = getEngine().generateSTORKAuthnResponseFail(attrQueryenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - fail("generateAuthnResponseFail(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - attrQueryenRequest.setAssertionConsumerServiceURL(assertConsumerUrl); - LOG.error("Error"); + + /** + * Test generate attribute query request without errors. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAttrQueryResponse() throws STORKSAMLEngineException { + + IPersonalAttributeList palist = new PersonalAttributeList(); + + PersonalAttribute isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(true); + ArrayList ages = new ArrayList(); + ages.add("16"); + ages.add("18"); + isAgeOver.setValue(ages); + isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + palist.add(isAgeOver); + + PersonalAttribute dateOfBirth = new PersonalAttribute(); + dateOfBirth.setName("dateOfBirth"); + dateOfBirth.setIsRequired(false); + final ArrayList date = new ArrayList(); + date.add("16/12/2008"); + dateOfBirth.setValue(date); + dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + palist.add(dateOfBirth); + + PersonalAttribute eIDNumber = new PersonalAttribute(); + eIDNumber.setName("eIdentifier"); + eIDNumber.setIsRequired(true); + + final ArrayList idNumber = new ArrayList(); + idNumber.add("123456789PÑ"); + + final HashMap complex = new HashMap(); + complex.put("one", "two"); + + // eIDNumber.setValue(null); + // eIDNumber.setValue(idNumber); + // eIDNumber.setComplexValue(complex); + + eIDNumber.setStatus(STORKStatusCode.STATUS_NOT_AVAILABLE.toString()); + palist.add(eIDNumber); + + PersonalAttribute canRessAddress = new PersonalAttribute(); + canRessAddress.setName("canonicalResidenceAddress"); + canRessAddress.setIsRequired(true); + canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + final HashMap address = new HashMap(); + + address.put("state", state); + address.put("town", town); + address.put("postalCode", postalCode); + address.put("streetName", streetName); + address.put("streetNumber", streetNumber); + + canRessAddress.setComplexValue(address); + palist.add(canRessAddress); + + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + + response.setPersonalAttributeList(palist); + + final STORKAttrQueryResponse storkResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing); + + attrQueryResponse = storkResponse.getTokenSaml(); + LOG.info("Request id: " + attrQueryenRequest.getSamlId()); + + LOG.info("RESPONSE: " + SSETestUtils.encodeSAMLToken(attrQueryResponse)); + + attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress); + + LOG.info("RESPONSE ID: " + attrQeuryenResponse.getSamlId()); + LOG.info("RESPONSE IN_RESPONSE_TO: " + attrQeuryenResponse.getInResponseTo()); + LOG.info("RESPONSE COUNTRY: " + attrQeuryenResponse.getCountry()); + } - } - - /** - * Test generate attribute query response fail code error err1. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testGenerateAttrQueryResponseFailCodeErrorNull() - throws STORKSAMLEngineException { - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setStatusCode(null); - response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); - response.setMessage(""); - - try { - attrQueryResponse = getEngine().generateSTORKAttrQueryResponseFail(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - fail("generateAttrQueryResponseFail(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate attribute query response fail is fail. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAttrQueryResponseFailIsFail() throws STORKSAMLEngineException { + + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); + response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); + response.setMessage("message"); + + attrQueryResponse = getEngine().generateSTORKAttrQueryResponseFail(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); + + LOG.error("ERROR_FAIL: " + PEPSUtil.encodeSAMLToken(attrQueryResponse)); + + attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress); + + LOG.info("COUNTRY: " + attrQeuryenResponse.getCountry()); + assertTrue("Generate incorrect response: ", attrQeuryenResponse.isFail()); } - } - - - - - /** - * Test generate attribute query request without errors. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAttrQueryResponse() throws STORKSAMLEngineException { - - IPersonalAttributeList palist = new PersonalAttributeList(); - - PersonalAttribute isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(true); - ArrayList ages = new ArrayList(); - ages.add("16"); - ages.add("18"); - isAgeOver.setValue(ages); - isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - palist.add(isAgeOver); - - PersonalAttribute dateOfBirth = new PersonalAttribute(); - dateOfBirth.setName("dateOfBirth"); - dateOfBirth.setIsRequired(false); - final ArrayList date = new ArrayList(); - date.add("16/12/2008"); - dateOfBirth.setValue(date); - dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - palist.add(dateOfBirth); - - - PersonalAttribute eIDNumber = new PersonalAttribute(); - eIDNumber.setName("eIdentifier"); - eIDNumber.setIsRequired(true); - - final ArrayList idNumber = new ArrayList(); - idNumber.add("123456789PÑ"); - - final HashMap complex = new HashMap(); - complex.put("one", "two"); - - //eIDNumber.setValue(null); - //eIDNumber.setValue(idNumber); - //eIDNumber.setComplexValue(complex); - - eIDNumber.setStatus(STORKStatusCode.STATUS_NOT_AVAILABLE.toString()); - palist.add(eIDNumber); - - PersonalAttribute canRessAddress = new PersonalAttribute(); - canRessAddress.setName("canonicalResidenceAddress"); - canRessAddress.setIsRequired(true); - canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - final HashMap address = new HashMap(); - - address.put("state", state); - address.put("town", town); - address.put("postalCode", postalCode); - address.put("streetName", streetName); - address.put("streetNumber", streetNumber); - - canRessAddress.setComplexValue(address); - palist.add(canRessAddress); - - - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - - response.setPersonalAttributeList(palist); - - final STORKAttrQueryResponse storkResponse = getEngine() - .generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, - destinationUrl, isNotHashing); - - attrQueryResponse = storkResponse.getTokenSaml(); - LOG.info("Request id: " + attrQueryenRequest.getSamlId()); - - LOG.info("RESPONSE: " + SSETestUtils.encodeSAMLToken(attrQueryResponse)); - - - attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, - ipAddress); - - LOG.info("RESPONSE ID: " + attrQeuryenResponse.getSamlId()); - LOG.info("RESPONSE IN_RESPONSE_TO: " + attrQeuryenResponse.getInResponseTo()); - LOG.info("RESPONSE COUNTRY: " + attrQeuryenResponse.getCountry()); - - } - - - - - - /** - * Test validate attribute query response fail is fail. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAttrQueryResponseFailIsFail() - throws STORKSAMLEngineException { - - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); - response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); - response.setMessage("message"); - - attrQueryResponse = getEngine().generateSTORKAttrQueryResponseFail(attrQueryenRequest, - response, ipAddress, destinationUrl, isNotHashing).getTokenSaml(); - - LOG.error("ERROR_FAIL: " + PEPSUtil.encodeSAMLToken(attrQueryResponse)); - - attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, - ipAddress); - - LOG.info("COUNTRY: " + attrQeuryenResponse.getCountry()); - assertTrue("Generate incorrect response: ", attrQeuryenResponse.isFail()); - } - + /** * Test generate/validate response with signedDoc * @@ -879,8 +800,7 @@ public class StorkAttrQueryResponseTest { * the STORKSAML engine exception */ @Test - public final void testGenerateAttrQueryResponseWithSignedDoc() - throws STORKSAMLEngineException { + public final void testGenerateAttrQueryResponseWithSignedDoc() throws STORKSAMLEngineException { String signedDocResponse = " urn:oasis:names:tc:dss:1.0:resultmajor:Success PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48ZHM6U2lnbmF0dXJlIHhtbG5z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MzUwOTUwMyI+PHhhZGVzOk1pbWVUeXBlPmFwcGxpY2F0aW9uL29jdGV0LXN0cmVhbTwveGFkZXM6TWltZVR5cGU+PHhhZGVzOkVuY29kaW5nPmJhc2U2NDwveGFkZXM6RW5jb2Rpbmc+PC94YWRlczpEYXRhT2JqZWN0Rm9ybWF0PjwveGFkZXM6U2lnbmVkRGF0YU9iamVjdFByb3BlcnRpZXM+PC94YWRlczpTaWduZWRQcm9wZXJ0aWVzPjwveGFkZXM6UXVhbGlmeWluZ1Byb3BlcnRpZXM+PC9kczpPYmplY3Q+PC9kczpTaWduYXR1cmU+ "; @@ -909,117 +829,107 @@ public class StorkAttrQueryResponseTest { response.setPersonalAttributeList(palist); - final STORKAttrQueryResponse storkResponse = getEngine() - .generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, - destinationUrl, isNotHashing); + final STORKAttrQueryResponse storkResponse = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, response, ipAddress, destinationUrl, isNotHashing); attrQueryResponse = storkResponse.getTokenSaml(); - attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, - ipAddress); + attrQeuryenResponse = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress); - assertTrue("SignedDoc response should be the same: ", attrQeuryenResponse - .getPersonalAttributeList().get("signedDoc").getValue().get(0) - .equals(signedDocResponse)); + assertTrue("SignedDoc response should be the same: ", attrQeuryenResponse.getPersonalAttributeList().get("signedDoc").getValue().get(0).equals(signedDocResponse)); } - + @Test public final void testEncodeDecode() { - STORKAttrQueryRequest attrRequest = new STORKAttrQueryRequest(); - STORKAttrQueryRequest request; - IPersonalAttributeList list = null; - boolean outcome = false; - - try { - //STEP 1: Create the STORKAttrQueryRequest and get the SAML bytes - attrRequest.setSpSector("NOT AVAILABLE"); - attrRequest.setSpInstitution("NOT AVAILABLE"); - attrRequest.setSpApplication("NOT AVAILABLE"); - attrRequest.setSpCountry("NOT AVAILABLE"); - - attrRequest.setIssuer("123"); - attrRequest.setDestination("456"); - attrRequest.setAssertionConsumerServiceURL("789"); - attrRequest.setQaa(2); - attrRequest.setPersonalAttributeList(pal); - - System.out.println("Original PAL:"); - System.out.println(pal.toString()); - - attrRequest = engine.generateSTORKAttrQueryRequest(attrRequest); - - byte[] saml = attrRequest.getTokenSaml(); - - //STEP 2: RE-Create the STORKAttrQueryRequest from the SAML bytes - request = engine.validateSTORKAttrQueryRequest(saml); - - System.out.println("STORKAttrQueryRequest Issuer: " + request.getIssuer()); - System.out.println("STORKAttrQueryRequest Destination: " + request.getDestination()); - System.out.println("STORKAttrQueryRequest ServiceURL: " + request.getAssertionConsumerServiceURL()); - System.out.println("STORKAttrQueryRequest Attributes: " + request.getPersonalAttributeList().toString()); - System.out.println("STORKAttrQueryRequest QAA: " + request.getQaa()); - //------------------------------ - list = request.getPersonalAttributeList(); - - List values = new ArrayList(); - values.add("test1"); - values.add("test2"); - values.add("test3"); - list.get("newAttribute2").setValue(values); - - System.out.println("Values added in newAttribute2 PAL:"); - System.out.println(list.toString()); - - ////////////////////////////////////////////////////////////////////////// - final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); - response.setPersonalAttributeList(list); - - final STORKAttrQueryResponse storkResponse = - engine.generateSTORKAttrQueryResponse(request, response, "127.0.0.1", - request.getAssertionConsumerServiceURL(), false); - - byte[] samlBytes = storkResponse.getTokenSaml(); - - //STEP 3: RE-Create the STORKAttrQueryResponse from the SAML bytes - STORKAttrQueryResponse attrResponse = null; - attrResponse = - engine.validateSTORKAttrQueryResponse(samlBytes, "127.0.0.1"); - - System.out.println("Response decoded PAL:"); - System.out.println(attrResponse.getPersonalAttributeList().toString()); - - values = attrResponse.getPersonalAttributeList().get("newAttribute2").getValue(); - if ( values.contains("test1") && values.contains("test2") && values.contains("test3") ) - outcome = true; - } catch (final STORKSAMLEngineException e) { - LOG.error("Errror genereating SAML Token for Authentication Request", e); - } - - assertTrue(outcome); + STORKAttrQueryRequest attrRequest = new STORKAttrQueryRequest(); + STORKAttrQueryRequest request; + IPersonalAttributeList list = null; + boolean outcome = false; + + try { + // STEP 1: Create the STORKAttrQueryRequest and get the SAML bytes + attrRequest.setSpSector("NOT AVAILABLE"); + attrRequest.setSpInstitution("NOT AVAILABLE"); + attrRequest.setSpApplication("NOT AVAILABLE"); + attrRequest.setSpCountry("NOT AVAILABLE"); + + attrRequest.setIssuer("123"); + attrRequest.setDestination("456"); + attrRequest.setAssertionConsumerServiceURL("789"); + attrRequest.setQaa(2); + attrRequest.setPersonalAttributeList(pal); + + System.out.println("Original PAL:"); + System.out.println(pal.toString()); + + attrRequest = engine.generateSTORKAttrQueryRequest(attrRequest); + + byte[] saml = attrRequest.getTokenSaml(); + + // STEP 2: RE-Create the STORKAttrQueryRequest from the SAML bytes + request = engine.validateSTORKAttrQueryRequest(saml); + + System.out.println("STORKAttrQueryRequest Issuer: " + request.getIssuer()); + System.out.println("STORKAttrQueryRequest Destination: " + request.getDestination()); + System.out.println("STORKAttrQueryRequest ServiceURL: " + request.getAssertionConsumerServiceURL()); + System.out.println("STORKAttrQueryRequest Attributes: " + request.getPersonalAttributeList().toString()); + System.out.println("STORKAttrQueryRequest QAA: " + request.getQaa()); + // ------------------------------ + list = request.getPersonalAttributeList(); + + List values = new ArrayList(); + values.add("test1"); + values.add("test2"); + values.add("test3"); + list.get("newAttribute2").setValue(values); + + System.out.println("Values added in newAttribute2 PAL:"); + System.out.println(list.toString()); + + // //////////////////////////////////////////////////////////////////////// + final STORKAttrQueryResponse response = new STORKAttrQueryResponse(); + response.setPersonalAttributeList(list); + + final STORKAttrQueryResponse storkResponse = engine.generateSTORKAttrQueryResponse(request, response, "127.0.0.1", request.getAssertionConsumerServiceURL(), false); + + byte[] samlBytes = storkResponse.getTokenSaml(); + + // STEP 3: RE-Create the STORKAttrQueryResponse from the SAML bytes + STORKAttrQueryResponse attrResponse = null; + attrResponse = engine.validateSTORKAttrQueryResponse(samlBytes, "127.0.0.1"); + + System.out.println("Response decoded PAL:"); + System.out.println(attrResponse.getPersonalAttributeList().toString()); + + values = attrResponse.getPersonalAttributeList().get("newAttribute2").getValue(); + if (values.contains("test1") && values.contains("test2") && values.contains("test3")) + outcome = true; + } catch (final STORKSAMLEngineException e) { + LOG.error("Errror genereating SAML Token for Authentication Request", e); + } + + assertTrue(outcome); } - + @Test - public final void testGenerateAttrRequestWithMultipleAssertions() - throws STORKSAMLEngineException { + public final void testGenerateAttrRequestWithMultipleAssertions() throws STORKSAMLEngineException { STORKAttrQueryRequest req = null; STORKAttrQueryResponse res0 = null; STORKAttrQueryResponse res1 = null; STORKAttrQueryResponse res2 = null; STORKAttrQueryResponse res = null; STORKAttrQueryResponse restotal = null; - + try { req = getEngine().validateSTORKAttrQueryRequest(attrQueryRequest); - - attrQueryenRequest = getEngine().validateSTORKAttrQueryRequest(attrQueryRequest); - + + attrQueryenRequest = getEngine().validateSTORKAttrQueryRequest(attrQueryRequest); + } catch (STORKSAMLEngineException e) { - fail("Error validating STORKAuthnRequest"); + fail("Error validating STORKAuthnRequest"); } - + IPersonalAttributeList pList = req.getPersonalAttributeList(); - for (int i =0; i < pList.size(); i++) - { + for (int i = 0; i < pList.size(); i++) { PersonalAttribute attr = pList.get("dateOfBirth"); attr.setValue(Arrays.asList("19820919")); pList.remove("dateOfBirth"); @@ -1031,37 +941,30 @@ public class StorkAttrQueryResponseTest { PersonalAttribute attr2 = pList.get("isAgeOver"); attr2.setValue(Arrays.asList("true")); pList.remove("isAgeOver"); - pList.add(attr2); + pList.add(attr2); } - + res = new STORKAttrQueryResponse(); res.setPersonalAttributeList(pList); - - STORKAttrQueryResponse storkResponse = getEngine() - .generateSTORKAttrQueryResponse(req, res, ipAddress, - destinationUrl, isNotHashing); - + + STORKAttrQueryResponse storkResponse = getEngine().generateSTORKAttrQueryResponse(req, res, ipAddress, destinationUrl, isNotHashing); + res0 = getEngine().validateSTORKAttrQueryResponse(storkResponse.getTokenSaml(), ipAddress); - - storkResponse = getEngine() - .generateSTORKAttrQueryResponse(req, res, ipAddress, - destinationUrl, isNotHashing); + + storkResponse = getEngine().generateSTORKAttrQueryResponse(req, res, ipAddress, destinationUrl, isNotHashing); res1 = getEngine().validateSTORKAttrQueryResponse(storkResponse.getTokenSaml(), ipAddress); - - storkResponse = getEngine() - .generateSTORKAttrQueryResponse(req, res, ipAddress, - destinationUrl, isNotHashing); + + storkResponse = getEngine().generateSTORKAttrQueryResponse(req, res, ipAddress, destinationUrl, isNotHashing); res2 = getEngine().validateSTORKAttrQueryResponse(storkResponse.getTokenSaml(), ipAddress); - + List responses = new ArrayList(); responses.add(res0); responses.add(res1); responses.add(res2); - + STORKAttrQueryResponse resfinal = new STORKAttrQueryResponse(); - storkResponse = getEngine().generateSTORKAttrQueryResponseWithAssertions(req, resfinal, responses, - ipAddress, destinationUrl, isNotHashing); - + storkResponse = getEngine().generateSTORKAttrQueryResponseWithAssertions(req, resfinal, responses, ipAddress, destinationUrl, isNotHashing); + attrQueryResponse = storkResponse.getTokenSaml(); FileOutputStream output = null; try { @@ -1076,7 +979,7 @@ public class StorkAttrQueryResponseTest { // TODO Auto-generated catch block e.printStackTrace(); } - + res = null; res = getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress); System.out.println(res.getTotalPersonalAttributeList().toString()); diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAuthRequestTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAuthRequestTest.java index 02a8a6fab..beca213ac 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAuthRequestTest.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAuthRequestTest.java @@ -38,869 +38,850 @@ import eu.stork.peps.exceptions.STORKSAMLEngineException; */ public class StorkAuthRequestTest { - /** The engines. */ - private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); - private static STORKSAMLEngine engine2 = STORKSAMLEngine.getInstance("CONF2"); - private static STORKSAMLEngine engine3 = STORKSAMLEngine.getInstance("CONF3"); - - - /** - * Instantiates a new stork authentication request test. - */ - public StorkAuthRequestTest() { - pal = new PersonalAttributeList(); - - final PersonalAttribute isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(true); - final ArrayList ages = new ArrayList(); - 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); - + /** The engines. */ + private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); + private static STORKSAMLEngine engine2 = STORKSAMLEngine.getInstance("CONF2"); + private static STORKSAMLEngine engine3 = STORKSAMLEngine.getInstance("CONF3"); + + /** + * Instantiates a new stork authentication request test. + */ + public StorkAuthRequestTest() { + pal = new PersonalAttributeList(); + + final PersonalAttribute isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(true); + final ArrayList ages = new ArrayList(); + 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); - pal.add(eIDNumber); - - destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; - assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; - - spName = "University of Oxford"; - spSector = "EDU001"; - spInstitution = "OXF001"; - spApplication = "APP001"; - spCountry = "EN"; - - spId = "EDU001-OXF001-APP001"; - - } - - /** The destination. */ - private String destination; - - /** The service provider name. */ - private String spName; - - /** 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 quality authentication assurance level. */ - private static final int QAAL = 3; - - /** The List of Personal Attributes. */ - private IPersonalAttributeList pal; - - /** The assertion consumer URL. */ - private String assertConsumerUrl; - - /** The authentication request. */ - private static byte[] authRequest; - - /** The Constant LOG. */ - private static final Logger LOG = LoggerFactory - .getLogger(StorkAuthRequestTest.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 testGenerateAuthnRequest() throws STORKSAMLEngineException { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // new parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - //engine.generateSTORKAuthnRequest(request); - - LOG.info("STORKAuthnRequest 1: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAuthnRequest(request).getTokenSaml())); - request.setCitizenCountryCode("ES"); - LOG.info("STORKAuthnRequest 2: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAuthnRequest(request).getTokenSaml())); - } - - - /** - * Test generate authentication request error personal attribute name error. - */ - @Test - public final void testGenerateAuthnRequestPALsErr1() { - - final IPersonalAttributeList palWrong = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("attrNotValid"); - worngAttr.setIsRequired(true); - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(palWrong); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try { - engine.generateSTORKAuthnRequest(request); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + eIDNumber.setName("eIdentifier"); + eIDNumber.setIsRequired(true); + pal.add(eIDNumber); + + destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; + assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; + + spName = "University of Oxford"; + spSector = "EDU001"; + spInstitution = "OXF001"; + spApplication = "APP001"; + spCountry = "EN"; + + spId = "EDU001-OXF001-APP001"; + } - } - - - - /** - * Test generate authentication request error personal attribute value error. - */ - @Test - public final void testGenerateAuthnRequestPALsErr2() { - - final IPersonalAttributeList palWrong = new PersonalAttributeList(); - - final PersonalAttribute attrNotValid = new PersonalAttribute(); - attrNotValid.setName("attrNotValid"); - attrNotValid.setIsRequired(true); - palWrong.add(attrNotValid); - - - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(palWrong); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try { - engine.generateSTORKAuthnRequest(request); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** The destination. */ + private String destination; + + /** The service provider name. */ + private String spName; + + /** 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 quality authentication assurance level. */ + private static final int QAAL = 3; + + /** The List of Personal Attributes. */ + private IPersonalAttributeList pal; + + /** The assertion consumer URL. */ + private String assertConsumerUrl; + + /** The authentication request. */ + private static byte[] authRequest; + + /** The Constant LOG. */ + private static final Logger LOG = LoggerFactory.getLogger(StorkAuthRequestTest.class.getName()); + + /** Parser manager used to parse XML. */ + private static BasicParserPool parser; + + static { + parser = new BasicParserPool(); + parser.setNamespaceAware(true); } - } - - /** - * Test generate authentication request error provider name null. - */ - @Test - public final void testGenerateAuthnRequestSPNAmeErr1() { - - - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(null); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try - { - engine.generateSTORKAuthnRequest(request); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + + /** + * Test generate authentication request. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateAuthnRequest() throws STORKSAMLEngineException { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // new parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + // engine.generateSTORKAuthnRequest(request); + + LOG.info("STORKAuthnRequest 1: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAuthnRequest(request).getTokenSaml())); + request.setCitizenCountryCode("ES"); + LOG.info("STORKAuthnRequest 2: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKAuthnRequest(request).getTokenSaml())); } - catch (STORKSAMLEngineException e) - { - LOG.error("Error"); + + /** + * Test generate authentication request error personal attribute name error. + */ + @Test + public final void testGenerateAuthnRequestPALsErr1() { + + final IPersonalAttributeList palWrong = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("attrNotValid"); + worngAttr.setIsRequired(true); + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(palWrong); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + engine.generateSTORKAuthnRequest(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 testGenerateAuthnRequestQaalErr1() { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(-1); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - - try { - engine.generateSTORKAuthnRequest(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 testGenerateAuthnRequestPALsErr2() { + + final IPersonalAttributeList palWrong = new PersonalAttributeList(); + + final PersonalAttribute attrNotValid = new PersonalAttribute(); + attrNotValid.setName("attrNotValid"); + attrNotValid.setIsRequired(true); + palWrong.add(attrNotValid); + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(palWrong); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + engine.generateSTORKAuthnRequest(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 testGenerateAuthnRequestSectorErr() { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - 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("ES"); - - try { - engine.generateSTORKAuthnRequest(request); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + /** + * Test generate authentication request error provider name null. + */ + @Test + public final void testGenerateAuthnRequestSPNAmeErr1() { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(null); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + engine.generateSTORKAuthnRequest(request); + fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test generate authentication request service provider institution null. - */ - @Test - public final void testGenerateAuthnRequestInstitutionrErr() { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(null); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try { - engine.generateSTORKAuthnRequest(request); - - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + + /** + * Test generate authentication request authentication assurance level negative value. + */ + @Test + public final void testGenerateAuthnRequestQaalErr1() { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(-1); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + + try { + engine.generateSTORKAuthnRequest(request); + fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test generate authentication request service provider application null. - */ - @Test - public final void testGenerateAuthnRequestApplicationErr() { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - 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("ES"); - - try { - engine.generateSTORKAuthnRequest(request); - - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + + /** + * Test generate authentication request service provider sector null. + */ + @Test + public final void testGenerateAuthnRequestSectorErr() { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + 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("ES"); + + try { + engine.generateSTORKAuthnRequest(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 testGenerateAuthnRequestCountryErr() { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - 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("ES"); - - try { - engine.generateSTORKAuthnRequest(request); - LOG.error("Error"); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); - - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate authentication request service provider institution null. + */ + @Test + public final void testGenerateAuthnRequestInstitutionrErr() { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(null); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + engine.generateSTORKAuthnRequest(request); + + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + } } - } - - /** - * Test generate authentication request error with quality authentication - * assurance level wrong. - */ - @Test - public final void testGenerateAuthnRequestQaalErr2() { - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(0); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try { - engine.generateSTORKAuthnRequest(request); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate authentication request service provider application null. + */ + @Test + public final void testGenerateAuthnRequestApplicationErr() { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + 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("ES"); + + try { + engine.generateSTORKAuthnRequest(request); + + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + } } - } - - /** - * Test generate authentication request personal attribute list null value. - */ - @Test - public final void testGenerateAuthnRequestPALErr1() { - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(null); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try { - engine.generateSTORKAuthnRequest(request); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate authentication request service provider country null. + */ + @Test + public final void testGenerateAuthnRequestCountryErr() { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + 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("ES"); + + try { + engine.generateSTORKAuthnRequest(request); + LOG.error("Error"); + fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test generate authentication request error with assertion consumer URL - * null. - */ - @Test - public final void testGenerateAuthnRequestAssertionConsumerErr1() { - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(null); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try { - engine.generateSTORKAuthnRequest(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 testGenerateAuthnRequestQaalErr2() { + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(0); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + engine.generateSTORKAuthnRequest(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 testValidateAuthnRequestNullParam() - throws STORKSAMLEngineException { - try { - engine.validateSTORKAuthnRequest(null); - fail("validateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate authentication request personal attribute list null value. + */ + @Test + public final void testGenerateAuthnRequestPALErr1() { + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(null); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + engine.generateSTORKAuthnRequest(request); + fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } + } + + /** + * Test generate authentication request error with assertion consumer URL null. + */ + @Test + public final void testGenerateAuthnRequestAssertionConsumerErr1() { + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(null); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + engine.generateSTORKAuthnRequest(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 testValidateAuthnRequestNullParam() throws STORKSAMLEngineException { + try { + engine.validateSTORKAuthnRequest(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 testValidateAuthnRequestErrorEncode() throws STORKSAMLEngineException { + try { + engine.validateSTORKAuthnRequest("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 testValidateAuthnRequest() throws STORKSAMLEngineException { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + authRequest = engine.generateSTORKAuthnRequest(request).getTokenSaml(); + + final STORKAuthnRequest validatedRequest = engine.validateSTORKAuthnRequest(authRequest); + + 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 testValidateDataAuthnRequest() throws STORKSAMLEngineException { + + final STORKAuthnRequest request = engine.validateSTORKAuthnRequest(authRequest); + + 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("Service provider incorrect: ", request.getProviderName(), spName); + 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("Asserition consumer URL incorrect: ", request.getAssertionConsumerServiceURL(), assertConsumerUrl); + + assertEquals("SP Country incorrect: ", request.getSpCountry(), spCountry); + assertEquals("SP Id incorrect: ", request.getSPID(), spId); + assertEquals("CitizenCountryCode incorrect: ", request.getCitizenCountryCode(), "ES"); + + } + + /** + * Test validate file authentication request. Validate from XML file. + * + * @throws Exception + * the exception + */ + @Test + public final void testValidateFileAuthnRequest() throws Exception { + + final byte[] bytes = SSETestUtils.readStorkSamlFromFile("/data/eu/stork/STORKSAMLEngine/AuthnRequest.xml"); + + try { + engine.validateSTORKAuthnRequest(bytes); + fail("testValidateFileAuthnRequest(...) 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 testValidateFileAuthnRequestTagDelete() throws Exception { + + final byte[] bytes = SSETestUtils.readStorkSamlFromFile("/data/eu/stork/STORKSAMLEngine/AuthnRequestTagDelete.xml"); + + try { + engine.validateSTORKAuthnRequest(bytes); + fail("validateSTORKAuthnRequest(...) 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 testValidateAuthnRequestNotTrustedErr1() throws STORKSAMLEngineException { + + try { + final STORKSAMLEngine engineNotTrusted = STORKSAMLEngine.getInstance("CONF2"); + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + 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.generateSTORKAuthnRequest(request).getTokenSaml(); + + engine.validateSTORKAuthnRequest(authReqNotTrust); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + fail("validateSTORKAuthnRequestNotTrusted(...) should not have thrown an STORKSAMLEngineException!"); + } + } + + /** + * Test validate authentication request trusted. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAuthnRequestTrusted() throws STORKSAMLEngineException { + + final STORKSAMLEngine engineTrusted = STORKSAMLEngine.getInstance("CONF3"); + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + 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 = engineTrusted.generateSTORKAuthnRequest(request).getTokenSaml(); + + // engine ("CONF1") no have trust certificate from "CONF2" + engine.validateSTORKAuthnRequest(authReqNotTrust); + } - } - - /** - * Test validate authentication request error bytes encode. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthnRequestErrorEncode() - throws STORKSAMLEngineException { - try { - engine.validateSTORKAuthnRequest("messageError".getBytes()); - fail("validateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate authentication request service provider application null. + */ + @Test + public final void testGenerateAuthnRequestNADA() { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(null); + request.setSpInstitution(null); + request.setSpApplication(null); + request.setSpCountry(null); + + try { + + engine.validateSTORKAuthnRequest(authRequest); + + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + } } - } - - /** - * Test validate authentication request. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthnRequest() throws STORKSAMLEngineException { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - authRequest = engine.generateSTORKAuthnRequest(request).getTokenSaml(); - - final STORKAuthnRequest validatedRequest = engine.validateSTORKAuthnRequest(authRequest); - - 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 testValidateDataAuthnRequest() throws STORKSAMLEngineException { - - final STORKAuthnRequest request = engine.validateSTORKAuthnRequest(authRequest); - - 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("Service provider incorrect: ", request.getProviderName(), spName); - 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("Asserition consumer URL incorrect: ", request.getAssertionConsumerServiceURL(), assertConsumerUrl); - - assertEquals("SP Country incorrect: ", request.getSpCountry(), spCountry); - assertEquals("SP Id incorrect: ", request.getSPID(), spId); - assertEquals("CitizenCountryCode incorrect: ", request.getCitizenCountryCode(), "ES"); - - } - - /** - * Test validate file authentication request. Validate from XML file. - * - * @throws Exception the exception - */ - @Test - public final void testValidateFileAuthnRequest() throws Exception { - - final byte[] bytes = SSETestUtils.readStorkSamlFromFile("/data/eu/stork/STORKSAMLEngine/AuthnRequest.xml"); - - try { - engine.validateSTORKAuthnRequest(bytes); - fail("testValidateFileAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error(e.getMessage()); + + /** + * Test validate authentication request with unknown elements. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAuthnRequestWithUnknownElements() throws STORKSAMLEngineException { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + 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("ES"); + + STORKAuthnRequest req = new STORKAuthnRequest(); + + req = engine3.generateSTORKAuthnRequest(request); + + req = engine.validateSTORKAuthnRequest(req.getTokenSaml()); + + assertNull("The value shouldn't exist", req.getPersonalAttributeList().get("unknown")); + assertNotNull("The value should exist", req.getPersonalAttributeList().get("eIdentifier")); + } - } - /** - * Test validate file authentication request tag delete. - * - * @throws Exception the exception - */ - @Test - public final void testValidateFileAuthnRequestTagDelete() throws Exception { + /** + * Test generate Request with required elements by default + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateAuthnRequestWithIsRequiredElementsByDefault() throws STORKSAMLEngineException { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + IPersonalAttributeList pAttList = new PersonalAttributeList(); - final byte[] bytes = SSETestUtils.readStorkSamlFromFile("/data/eu/stork/STORKSAMLEngine/AuthnRequestTagDelete.xml"); + final PersonalAttribute eIdentifier = new PersonalAttribute(); + eIdentifier.setName("eIdentifier"); + eIdentifier.setIsRequired(true); + pAttList.add(eIdentifier); - try { - engine.validateSTORKAuthnRequest(bytes); - fail("validateSTORKAuthnRequest(...) should have thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error(e.getMessage()); + request.setPersonalAttributeList(pAttList); + + // new parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + STORKAuthnRequest req = new STORKAuthnRequest(); + STORKAuthnRequest reqTrue = new STORKAuthnRequest(); + STORKAuthnRequest reqFalse = new STORKAuthnRequest(); + + reqTrue = engine.generateSTORKAuthnRequest(request); + reqFalse = engine2.generateSTORKAuthnRequest(request); + req = engine3.generateSTORKAuthnRequest(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 validate authentication request not trusted token. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthnRequestNotTrustedErr1() - throws STORKSAMLEngineException { - - try { - final STORKSAMLEngine engineNotTrusted = STORKSAMLEngine - .getInstance("CONF2"); - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - 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 - .generateSTORKAuthnRequest(request).getTokenSaml(); - - engine.validateSTORKAuthnRequest(authReqNotTrust); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); - fail("validateSTORKAuthnRequestNotTrusted(...) should not have thrown an STORKSAMLEngineException!"); - } - } - - /** - * Test validate authentication request trusted. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthnRequestTrusted() - throws STORKSAMLEngineException { - - final STORKSAMLEngine engineTrusted = STORKSAMLEngine - .getInstance("CONF3"); - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - 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 = engineTrusted.generateSTORKAuthnRequest( - request).getTokenSaml(); - - // engine ("CONF1") no have trust certificate from "CONF2" - engine.validateSTORKAuthnRequest(authReqNotTrust); - - } - - - - - /** - * Test generate authentication request service provider application null. - */ - @Test - public final void testGenerateAuthnRequestNADA() { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(null); - request.setSpInstitution(null); - request.setSpApplication(null); - request.setSpCountry(null); - - try { - - engine.validateSTORKAuthnRequest(authRequest); - - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); - fail("generateSTORKAuthnRequest(...) should've thrown an STORKSAMLEngineException!"); + + /** + * Test validating request and getting alias used to save the saml trusted certificate into trustore + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAuthnRequestGettingItsAlias() throws STORKSAMLEngineException { + + final STORKAuthnRequest request = new STORKAuthnRequest(); + + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + 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("ES"); + + STORKAuthnRequest req = new STORKAuthnRequest(); + + req = engine3.generateSTORKAuthnRequest(request); + req = engine.validateSTORKAuthnRequest(req.getTokenSaml()); + assertTrue("The alias should match this value", req.getAlias().equals("local-demo-cert")); + + req = engine2.generateSTORKAuthnRequest(request); + req = engine2.validateSTORKAuthnRequest(req.getTokenSaml()); + assertTrue("The alias should match this value", req.getAlias().equals("local-demo-cert")); + } - } - - /** - * Test validate authentication request with unknown elements. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthnRequestWithUnknownElements() throws STORKSAMLEngineException { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - 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("ES"); - - STORKAuthnRequest req = new STORKAuthnRequest(); - - req = engine3.generateSTORKAuthnRequest(request); - - req = engine.validateSTORKAuthnRequest(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 testGenerateAuthnRequestWithIsRequiredElementsByDefault() throws STORKSAMLEngineException { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - 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("ES"); - - STORKAuthnRequest req = new STORKAuthnRequest(); - STORKAuthnRequest reqTrue = new STORKAuthnRequest(); - STORKAuthnRequest reqFalse = new STORKAuthnRequest(); - - reqTrue = engine.generateSTORKAuthnRequest(request); - reqFalse = engine2.generateSTORKAuthnRequest(request); - req = engine3.generateSTORKAuthnRequest(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 request and getting alias used to save - * the saml trusted certificate into trustore - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthnRequestGettingItsAlias() throws STORKSAMLEngineException { - - final STORKAuthnRequest request = new STORKAuthnRequest(); - - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - 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("ES"); - - STORKAuthnRequest req = new STORKAuthnRequest(); - - req = engine3.generateSTORKAuthnRequest(request); - req = engine.validateSTORKAuthnRequest(req.getTokenSaml()); - assertTrue("The alias should match this value", req.getAlias().equals("local-demo-cert")); - - req = engine2.generateSTORKAuthnRequest(request); - req = engine2.validateSTORKAuthnRequest(req.getTokenSaml()); - assertTrue("The alias should match this value", req.getAlias().equals("local-demo-cert")); - - - - } - + /** * Test generating/validating request with signedDoc * @@ -908,8 +889,7 @@ public class StorkAuthRequestTest { * the STORKSAML engine exception */ @Test - public final void testGenerateAuthnRequestWithSignedDoc() - throws STORKSAMLEngineException { + public final void testGenerateAuthnRequestWithSignedDoc() throws STORKSAMLEngineException { String signedDocRequest = "VGVzdCB0ZXh0"; @@ -958,10 +938,7 @@ public class StorkAuthRequestTest { req = engine.generateSTORKAuthnRequest(request); req = engine.validateSTORKAuthnRequest(req.getTokenSaml()); - assertTrue("SignedDoc request should be the same: ", req - .getPersonalAttributeList().get("signedDoc").getValue().get(0) - .equals(signedDocRequest)); - + assertTrue("SignedDoc request should be the same: ", req.getPersonalAttributeList().get("signedDoc").getValue().get(0).equals(signedDocRequest)); } diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkLogoutRequestTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkLogoutRequestTest.java index 46904788f..e05c660ea 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkLogoutRequestTest.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkLogoutRequestTest.java @@ -15,75 +15,74 @@ import eu.stork.peps.auth.commons.STORKLogoutRequest; import eu.stork.peps.auth.engine.STORKSAMLEngine; import eu.stork.peps.exceptions.STORKSAMLEngineException; - public class StorkLogoutRequestTest { - - /** 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"); - - public StorkLogoutRequestTest() { - destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; - spUserId = "IS/IS/1234567890"; - } - - /** The destination. */ - private String destination; - - /** The user id. */ - private String spUserId; - - /** The logout request. */ - private static byte[] logoutRequest; - - /** The Constant LOG. */ - private static final Logger LOG = LoggerFactory - .getLogger(StorkLogoutRequestTest.class.getName()); - - /** Parser manager used to parse XML. */ - private static BasicParserPool parser; - - static { + + /** 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"); + + public StorkLogoutRequestTest() { + destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; + spUserId = "IS/IS/1234567890"; + } + + /** The destination. */ + private String destination; + + /** The user id. */ + private String spUserId; + + /** The logout request. */ + private static byte[] logoutRequest; + + /** The Constant LOG. */ + private static final Logger LOG = LoggerFactory.getLogger(StorkLogoutRequestTest.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 testGenerateLogoutRequest() throws STORKSAMLEngineException { - - final STORKLogoutRequest request = new STORKLogoutRequest(); - - request.setDestination(destination); - - request.setSpProvidedId(spUserId); - - STORKLogoutRequest req1 = engine0.generateSTORKLogoutRequest(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/LogoutRequest.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(); + + /** + * Test generate authentication request. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateLogoutRequest() throws STORKSAMLEngineException { + + final STORKLogoutRequest request = new STORKLogoutRequest(); + + request.setDestination(destination); + + request.setSpProvidedId(spUserId); + + STORKLogoutRequest req1 = engine0.generateSTORKLogoutRequest(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/LogoutRequest.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.generateSTORKLogoutRequest(request).getTokenSaml())); + + LOG.info("STORKAttrQueryRequest 2: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKLogoutRequest(request).getTokenSaml())); } - - LOG.info("STORKAttrQueryRequest 1: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKLogoutRequest(request).getTokenSaml())); - - LOG.info("STORKAttrQueryRequest 2: " + SSETestUtils.encodeSAMLToken(engine.generateSTORKLogoutRequest(request).getTokenSaml())); - } } diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkLogoutResponseTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkLogoutResponseTest.java index 2d05e04aa..b9907002a 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkLogoutResponseTest.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkLogoutResponseTest.java @@ -19,124 +19,123 @@ import eu.stork.peps.auth.commons.STORKLogoutResponse; import eu.stork.peps.auth.engine.STORKSAMLEngine; import eu.stork.peps.exceptions.STORKSAMLEngineException; - public class StorkLogoutResponseTest { - - /** 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"); - - public StorkLogoutResponseTest() { - destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; - spUserId = "IS/IS/1234567890"; - } - - /** The destination. */ - private String destination; - - /** The user id. */ - private String spUserId; - - /** The logout request. */ - private static byte[] logoutRequest; - - /** The logout response. */ - private static byte[] logoutResponse; - - /** The Constant LOG. */ - private static final Logger LOG = LoggerFactory - .getLogger(StorkLogoutResponseTest.class.getName()); - - /** Parser manager used to parse XML. */ - private static BasicParserPool parser; - - static { + + /** 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"); + + public StorkLogoutResponseTest() { + destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; + spUserId = "IS/IS/1234567890"; + } + + /** The destination. */ + private String destination; + + /** The user id. */ + private String spUserId; + + /** The logout request. */ + private static byte[] logoutRequest; + + /** The logout response. */ + private static byte[] logoutResponse; + + /** The Constant LOG. */ + private static final Logger LOG = LoggerFactory.getLogger(StorkLogoutResponseTest.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 testGenerateLogoutRequest() throws STORKSAMLEngineException { - - final STORKLogoutRequest request = new STORKLogoutRequest(); - - final STORKLogoutResponse response = new STORKLogoutResponse(); - - request.setDestination(destination); - response.setDestination(destination); - - request.setSpProvidedId(spUserId); - - STORKLogoutRequest req1 = engine0.generateSTORKLogoutRequest(request); - - STORKLogoutResponse res = engine0.generateSTORKLogoutResponse(req1, response); - - byte[] reqByte = res.getTokenSaml(); - FileOutputStream output = null; - - try { - output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/LogoutResponse.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(); } - - + + /** + * Test generate authentication request. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateLogoutRequest() throws STORKSAMLEngineException { + + final STORKLogoutRequest request = new STORKLogoutRequest(); + + final STORKLogoutResponse response = new STORKLogoutResponse(); + + request.setDestination(destination); + response.setDestination(destination); + + request.setSpProvidedId(spUserId); + + STORKLogoutRequest req1 = engine0.generateSTORKLogoutRequest(request); + + STORKLogoutResponse res = engine0.generateSTORKLogoutResponse(req1, response); + + byte[] reqByte = res.getTokenSaml(); + FileOutputStream output = null; + + try { + output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/LogoutResponse.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(); + } + assertNotNull(reqByte); - } - - /** - * Test generate authentication request. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testGenerateLogoutRequestFail() throws STORKSAMLEngineException { - - final STORKLogoutRequest request = new STORKLogoutRequest(); - - final STORKLogoutResponse response = new STORKLogoutResponse(); - - request.setDestination(destination); - response.setDestination(destination); - response.setStatusMessage("User not found."); - response.setStatusCode("1234"); - request.setSpProvidedId(spUserId); - - STORKLogoutRequest req1 = engine0.generateSTORKLogoutRequest(request); - - STORKLogoutResponse res = engine0.generateSTORKLogoutResponseFail(req1, response); - - byte[] reqByte = res.getTokenSaml(); - FileOutputStream output = null; - - try { - output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/LogoutResponseFail.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(); } - + + /** + * Test generate authentication request. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateLogoutRequestFail() throws STORKSAMLEngineException { + + final STORKLogoutRequest request = new STORKLogoutRequest(); + + final STORKLogoutResponse response = new STORKLogoutResponse(); + + request.setDestination(destination); + response.setDestination(destination); + response.setStatusMessage("User not found."); + response.setStatusCode("1234"); + request.setSpProvidedId(spUserId); + + STORKLogoutRequest req1 = engine0.generateSTORKLogoutRequest(request); + + STORKLogoutResponse res = engine0.generateSTORKLogoutResponseFail(req1, response); + + byte[] reqByte = res.getTokenSaml(); + FileOutputStream output = null; + + try { + output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/LogoutResponseFail.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(); + } + assertNotNull(reqByte); - } + } } diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkNewResponseTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkNewResponseTest.java index 62e9cfb18..876c2c14d 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkNewResponseTest.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkNewResponseTest.java @@ -27,382 +27,370 @@ import eu.stork.peps.auth.commons.STORKStatusCode; import eu.stork.peps.auth.engine.STORKSAMLEngine; import eu.stork.peps.exceptions.STORKSAMLEngineException; - public class StorkNewResponseTest { /** The engine. */ - private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); - private static STORKSAMLEngine engine0 = STORKSAMLEngine.getInstance("CONF0"); - - /** - * Gets the engine. - * - * @return the engine - */ - public static STORKSAMLEngine getEngine() { - return engine; - } - - public static STORKSAMLEngine getEngine2() { - return engine0; - } - - /** - * Sets the engine. - * - * @param newEngine the new engine - */ - public static void setEngine(final STORKSAMLEngine newEngine) { - StorkNewResponseTest.engine = newEngine; - } - - /** The destination. */ - private static String destination; - - /** The service provider name. */ - private static String spName; - - /** The service provider sector. */ - private static String spSector; - - /** The service provider institution. */ - private static String spInstitution; - - /** The service provider application. */ - private static String spApplication; - - /** The service provider country. */ - private static String spCountry; - - /** The service provider id. */ - private static String spId; - - /** The quality authentication assurance level. */ - private static final int QAAL = 3; - - /** The state. */ - private static String state = "ES"; - - /** The town. */ - private static String town = "Madrid"; - - /** The municipality code. */ - private static String municipalityCode = "MA001"; - - /** The postal code. */ - private static String postalCode = "28038"; - - /** The street name. */ - private static String streetName = "Marchamalo"; - - /** The street number. */ - private static String streetNumber = "3"; - - /** The apartament number. */ - private static String apartamentNumber = "5º E"; - - /** The List of Personal Attributes. */ - private static IPersonalAttributeList pal; - - /** The List of Personal Attributes. */ - private static IPersonalAttributeList pal2; - - /** The assertion consumer URL. */ - private static String assertConsumerUrl; - - /** The authentication request. */ - private static byte[] authRequest; - - /** The authentication response. */ - private static byte[] authResponse; - - /** The authentication request. */ - private static STORKAuthnRequest authenRequest; - - /** The authentication response. */ - private static STORKAuthnResponse authnResponse; - - /** The Constant LOG. */ - private static final Logger LOG = LoggerFactory - .getLogger(StorkResponseTest.class.getName()); - - /** - * Instantiates a new stork response test. - */ - public StorkNewResponseTest() { - super(); - } - - /** The IP address. */ - private static String ipAddress; - - /** The is hashing. */ - private final boolean isHashing = Boolean.TRUE; - - /** The is not hashing. */ - private final boolean isNotHashing = Boolean.FALSE; - - /** The ERROR text. */ - private static final String ERROR_TXT = "generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"; - - - /** Parser manager used to parse XML. */ - private static BasicParserPool parser; - - /** The attribute query request. */ - private static STORKAttrQueryRequest attrQueryenRequest; - - /** The attribute query response. */ - private static STORKAttrQueryResponse attrQeuryenResponse; - - /** The attribute query request. */ - private static byte[] attrQueryRequest; - - /** The attribute query response. */ - private static byte[] attrQueryResponse; - - - - static { - parser = new BasicParserPool(); - parser.setNamespaceAware(true); - - pal = new PersonalAttributeList(); - pal2 = new PersonalAttributeList(); - - PersonalAttribute isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(false); - ArrayList ages = new ArrayList(); - ages.add("16"); - ages.add("18"); - isAgeOver.setValue(ages); - pal.add(isAgeOver); - - PersonalAttribute dateOfBirth = new PersonalAttribute(); - dateOfBirth.setName("dateOfBirth"); - dateOfBirth.setIsRequired(false); - pal.add(dateOfBirth); - - PersonalAttribute eIDNumber = new PersonalAttribute(); - eIDNumber.setName("eIdentifier"); - eIDNumber.setIsRequired(true); - pal.add(eIDNumber); - - final PersonalAttribute givenName = new PersonalAttribute(); - givenName.setName("givenName"); - givenName.setIsRequired(true); - pal.add(givenName); - - PersonalAttribute canRessAddress = new PersonalAttribute(); - canRessAddress.setName("canonicalResidenceAddress"); - canRessAddress.setIsRequired(true); - pal.add(canRessAddress); - - PersonalAttribute newAttribute = new PersonalAttribute(); - newAttribute.setName("newAttribute2"); - newAttribute.setIsRequired(true); - pal.add(newAttribute); - - PersonalAttribute hasDegree = new PersonalAttribute(); - hasDegree.setName("hasDegree"); - List vals = new ArrayList(); - vals.add("Engineering"); - vals.add("Computer Science"); - hasDegree.setValue(vals); - pal2.add(hasDegree); - - PersonalAttribute mandate = new PersonalAttribute(); - mandate.setName("mandateContent"); - List manvalues = new ArrayList(); - manvalues.add("Powers"); - mandate.setValue(manvalues); - pal2.add(mandate); - - destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; - assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; - spName = "University Oxford"; - - spName = "University of Oxford"; - spSector = "EDU001"; - spInstitution = "OXF001"; - spApplication = "APP001"; - spCountry = "EN"; - - spId = "EDU001-APP001-APP001"; - - final STORKAuthnRequest request = new STORKAuthnRequest(); - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try { - authRequest = getEngine().generateSTORKAuthnRequest(request) - .getTokenSaml(); - - authenRequest = getEngine().validateSTORKAuthnRequest(authRequest); - - } catch (STORKSAMLEngineException e) { - fail("Error create STORKAuthnRequest"); + private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); + private static STORKSAMLEngine engine0 = STORKSAMLEngine.getInstance("CONF0"); + + /** + * Gets the engine. + * + * @return the engine + */ + public static STORKSAMLEngine getEngine() { + return engine; + } + + public static STORKSAMLEngine getEngine2() { + return engine0; } - ipAddress = "111.222.333.444"; - - pal = new PersonalAttributeList(); - - isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(true); - ages = new ArrayList(); - - ages.add("16"); - ages.add("18"); - - isAgeOver.setValue(ages); - isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(isAgeOver); - - dateOfBirth = new PersonalAttribute(); - dateOfBirth.setName("dateOfBirth"); - dateOfBirth.setIsRequired(false); - final ArrayList date = new ArrayList(); - date.add("16/12/2008"); - dateOfBirth.setValue(date); - dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(dateOfBirth); - - eIDNumber = new PersonalAttribute(); - eIDNumber.setName("eIdentifier"); - eIDNumber.setIsRequired(true); - final ArrayList idNumber = new ArrayList(); - idNumber.add("123456789PA"); - eIDNumber.setValue(idNumber); - eIDNumber.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(eIDNumber); - - canRessAddress = new PersonalAttribute(); - canRessAddress.setName("canonicalResidenceAddress"); - canRessAddress.setIsRequired(true); - canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - final HashMap address = new HashMap(); - - address.put("state", state); - address.put("municipalityCode", municipalityCode); - address.put("town", town); - address.put("postalCode", postalCode); - address.put("streetName", streetName); - address.put("streetNumber", streetNumber); - address.put("apartamentNumber", apartamentNumber); - - canRessAddress.setComplexValue(address); - pal.add(canRessAddress); - - newAttribute = new PersonalAttribute(); - newAttribute.setName("newAttribute2"); - newAttribute.setIsRequired(true); - newAttribute.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - final HashMap values = new HashMap(); - - values.put("value1", "value1"); - values.put("value2", "value2"); - values.put("value3", "value3"); - values.put("value4", "value4"); - - newAttribute.setComplexValue(values); - pal.add(newAttribute); - - final STORKAttrQueryRequest arequest = new STORKAttrQueryRequest(); - arequest.setDestination(destination); - //request.setProviderName(spName); - arequest.setQaa(QAAL); - arequest.setPersonalAttributeList(pal2); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - arequest.setSpSector(spSector); - arequest.setSpInstitution(spInstitution); - arequest.setSpApplication(spApplication); - arequest.setSpCountry(spCountry); - arequest.setSPID(spId); - arequest.setCitizenCountryCode("IS"); - arequest.setAssertionConsumerServiceURL(assertConsumerUrl); - - try { - attrQueryRequest = getEngine().generateSTORKAttrQueryRequest(arequest) - .getTokenSaml(); - - attrQueryenRequest = getEngine().validateSTORKAttrQueryRequest(attrQueryRequest); - - } catch (STORKSAMLEngineException e) { - fail("Error create STORKAuthnRequest"); + /** + * Sets the engine. + * + * @param newEngine + * the new engine + */ + public static void setEngine(final STORKSAMLEngine newEngine) { + StorkNewResponseTest.engine = newEngine; } - - } - - /** - * Test generate authentication request without errors. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testGenerateAuthnResponseWithSimpleRes() throws STORKSAMLEngineException { - - //Create the response holding pal + + /** The destination. */ + private static String destination; + + /** The service provider name. */ + private static String spName; + + /** The service provider sector. */ + private static String spSector; + + /** The service provider institution. */ + private static String spInstitution; + + /** The service provider application. */ + private static String spApplication; + + /** The service provider country. */ + private static String spCountry; + + /** The service provider id. */ + private static String spId; + + /** The quality authentication assurance level. */ + private static final int QAAL = 3; + + /** The state. */ + private static String state = "ES"; + + /** The town. */ + private static String town = "Madrid"; + + /** The municipality code. */ + private static String municipalityCode = "MA001"; + + /** The postal code. */ + private static String postalCode = "28038"; + + /** The street name. */ + private static String streetName = "Marchamalo"; + + /** The street number. */ + private static String streetNumber = "3"; + + /** The apartament number. */ + private static String apartamentNumber = "5º E"; + + /** The List of Personal Attributes. */ + private static IPersonalAttributeList pal; + + /** The List of Personal Attributes. */ + private static IPersonalAttributeList pal2; + + /** The assertion consumer URL. */ + private static String assertConsumerUrl; + + /** The authentication request. */ + private static byte[] authRequest; + + /** The authentication response. */ + private static byte[] authResponse; + + /** The authentication request. */ + private static STORKAuthnRequest authenRequest; + + /** The authentication response. */ + private static STORKAuthnResponse authnResponse; + + /** The Constant LOG. */ + private static final Logger LOG = LoggerFactory.getLogger(StorkResponseTest.class.getName()); + + /** + * Instantiates a new stork response test. + */ + public StorkNewResponseTest() { + super(); + } + + /** The IP address. */ + private static String ipAddress; + + /** The is hashing. */ + private final boolean isHashing = Boolean.TRUE; + + /** The is not hashing. */ + private final boolean isNotHashing = Boolean.FALSE; + + /** The ERROR text. */ + private static final String ERROR_TXT = "generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"; + + /** Parser manager used to parse XML. */ + private static BasicParserPool parser; + + /** The attribute query request. */ + private static STORKAttrQueryRequest attrQueryenRequest; + + /** The attribute query response. */ + private static STORKAttrQueryResponse attrQeuryenResponse; + + /** The attribute query request. */ + private static byte[] attrQueryRequest; + + /** The attribute query response. */ + private static byte[] attrQueryResponse; + + static { + parser = new BasicParserPool(); + parser.setNamespaceAware(true); + + pal = new PersonalAttributeList(); + pal2 = new PersonalAttributeList(); + + PersonalAttribute isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(false); + ArrayList ages = new ArrayList(); + ages.add("16"); + ages.add("18"); + isAgeOver.setValue(ages); + pal.add(isAgeOver); + + PersonalAttribute dateOfBirth = new PersonalAttribute(); + dateOfBirth.setName("dateOfBirth"); + dateOfBirth.setIsRequired(false); + pal.add(dateOfBirth); + + PersonalAttribute eIDNumber = new PersonalAttribute(); + eIDNumber.setName("eIdentifier"); + eIDNumber.setIsRequired(true); + pal.add(eIDNumber); + + final PersonalAttribute givenName = new PersonalAttribute(); + givenName.setName("givenName"); + givenName.setIsRequired(true); + pal.add(givenName); + + PersonalAttribute canRessAddress = new PersonalAttribute(); + canRessAddress.setName("canonicalResidenceAddress"); + canRessAddress.setIsRequired(true); + pal.add(canRessAddress); + + PersonalAttribute newAttribute = new PersonalAttribute(); + newAttribute.setName("newAttribute2"); + newAttribute.setIsRequired(true); + pal.add(newAttribute); + + PersonalAttribute hasDegree = new PersonalAttribute(); + hasDegree.setName("hasDegree"); + List vals = new ArrayList(); + vals.add("Engineering"); + vals.add("Computer Science"); + hasDegree.setValue(vals); + pal2.add(hasDegree); + + PersonalAttribute mandate = new PersonalAttribute(); + mandate.setName("mandateContent"); + List manvalues = new ArrayList(); + manvalues.add("Powers"); + mandate.setValue(manvalues); + pal2.add(mandate); + + destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; + assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; + spName = "University Oxford"; + + spName = "University of Oxford"; + spSector = "EDU001"; + spInstitution = "OXF001"; + spApplication = "APP001"; + spCountry = "EN"; + + spId = "EDU001-APP001-APP001"; + + final STORKAuthnRequest request = new STORKAuthnRequest(); + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + authRequest = getEngine().generateSTORKAuthnRequest(request).getTokenSaml(); + + authenRequest = getEngine().validateSTORKAuthnRequest(authRequest); + + } catch (STORKSAMLEngineException e) { + fail("Error create STORKAuthnRequest"); + } + + ipAddress = "111.222.333.444"; + + pal = new PersonalAttributeList(); + + isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(true); + ages = new ArrayList(); + + ages.add("16"); + ages.add("18"); + + isAgeOver.setValue(ages); + isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(isAgeOver); + + dateOfBirth = new PersonalAttribute(); + dateOfBirth.setName("dateOfBirth"); + dateOfBirth.setIsRequired(false); + final ArrayList date = new ArrayList(); + date.add("16/12/2008"); + dateOfBirth.setValue(date); + dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(dateOfBirth); + + eIDNumber = new PersonalAttribute(); + eIDNumber.setName("eIdentifier"); + eIDNumber.setIsRequired(true); + final ArrayList idNumber = new ArrayList(); + idNumber.add("123456789PA"); + eIDNumber.setValue(idNumber); + eIDNumber.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(eIDNumber); + + canRessAddress = new PersonalAttribute(); + canRessAddress.setName("canonicalResidenceAddress"); + canRessAddress.setIsRequired(true); + canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + final HashMap address = new HashMap(); + + address.put("state", state); + address.put("municipalityCode", municipalityCode); + address.put("town", town); + address.put("postalCode", postalCode); + address.put("streetName", streetName); + address.put("streetNumber", streetNumber); + address.put("apartamentNumber", apartamentNumber); + + canRessAddress.setComplexValue(address); + pal.add(canRessAddress); + + newAttribute = new PersonalAttribute(); + newAttribute.setName("newAttribute2"); + newAttribute.setIsRequired(true); + newAttribute.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + final HashMap values = new HashMap(); + + values.put("value1", "value1"); + values.put("value2", "value2"); + values.put("value3", "value3"); + values.put("value4", "value4"); + + newAttribute.setComplexValue(values); + pal.add(newAttribute); + + final STORKAttrQueryRequest arequest = new STORKAttrQueryRequest(); + arequest.setDestination(destination); + // request.setProviderName(spName); + arequest.setQaa(QAAL); + arequest.setPersonalAttributeList(pal2); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + arequest.setSpSector(spSector); + arequest.setSpInstitution(spInstitution); + arequest.setSpApplication(spApplication); + arequest.setSpCountry(spCountry); + arequest.setSPID(spId); + arequest.setCitizenCountryCode("IS"); + arequest.setAssertionConsumerServiceURL(assertConsumerUrl); + + try { + attrQueryRequest = getEngine().generateSTORKAttrQueryRequest(arequest).getTokenSaml(); + + attrQueryenRequest = getEngine().validateSTORKAttrQueryRequest(attrQueryRequest); + + } catch (STORKSAMLEngineException e) { + fail("Error create STORKAuthnRequest"); + } + + } + + /** + * Test generate authentication request without errors. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateAuthnResponseWithSimpleRes() throws STORKSAMLEngineException { + + // Create the response holding pal final STORKAuthnResponse response = new STORKAuthnResponse(); response.setPersonalAttributeList(pal); - - //List of query responses + + // List of query responses List resList = new ArrayList(); - + final STORKAttrQueryResponse aResponse1 = new STORKAttrQueryResponse(); aResponse1.setPersonalAttributeList(pal2); - - final STORKAttrQueryResponse aStorkResponse1 = getEngine2() - .generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse1, ipAddress, - destination, isNotHashing); - + + final STORKAttrQueryResponse aStorkResponse1 = getEngine2().generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse1, ipAddress, destination, isNotHashing); + attrQueryResponse = aStorkResponse1.getTokenSaml(); - + resList.add(getEngine2().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress)); - + final STORKAttrQueryResponse aResponse2 = new STORKAttrQueryResponse(); aResponse2.setPersonalAttributeList(pal2); - - final STORKAttrQueryResponse aStorkResponse2 = getEngine() - .generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse2, ipAddress, - destination, isNotHashing); - + + final STORKAttrQueryResponse aStorkResponse2 = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse2, ipAddress, destination, isNotHashing); + attrQueryResponse = aStorkResponse2.getTokenSaml(); - + resList.add(getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress)); - - //Create the final response containing query responses - final STORKAuthnResponse storkResponse = getEngine() - .generateSTORKAuthnResponseAfterQuery(authenRequest, response, ipAddress, - isNotHashing, resList); + + // Create the final response containing query responses + final STORKAuthnResponse storkResponse = getEngine().generateSTORKAuthnResponseAfterQuery(authenRequest, response, ipAddress, isNotHashing, resList); authResponse = storkResponse.getTokenSaml(); - - //Validate, write out and print out the attribute lists a + + // Validate, write out and print out the attribute lists a STORKAuthnResponse finalResponse = getEngine().validateSTORKAuthnResponseWithQuery(authResponse, ipAddress); System.out.println("The original pal: " + finalResponse.getPersonalAttributeList().toString()); - for (int i = 0; i < finalResponse.getPersonalAttributeLists().size(); i++) - { - System.out.println("Pal "+ Integer.toString(i) + ": " + finalResponse.getPersonalAttributeLists().get(i).toString()); + for (int i = 0; i < finalResponse.getPersonalAttributeLists().size(); i++) { + System.out.println("Pal " + Integer.toString(i) + ": " + finalResponse.getPersonalAttributeLists().get(i).toString()); } System.out.println("The total pal: " + finalResponse.getTotalPersonalAttributeList().toString()); - + FileOutputStream output = null; - + try { output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/AuthAttrQResponse.xml")); } catch (FileNotFoundException e) { @@ -415,107 +403,96 @@ public class StorkNewResponseTest { // TODO Auto-generated catch block e.printStackTrace(); } - } - - /** - * Test generate authentication request without errors. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testGenerateAuthnResponseWithComplexRes() throws STORKSAMLEngineException { - - //Create the response holding pal + } + + /** + * Test generate authentication request without errors. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateAuthnResponseWithComplexRes() throws STORKSAMLEngineException { + + // Create the response holding pal final STORKAuthnResponse response = new STORKAuthnResponse(); response.setPersonalAttributeList(pal); - - //Create a list for the attribute query responses we have + + // Create a list for the attribute query responses we have List resList = new ArrayList(); - - //Create the first attribute query response + + // Create the first attribute query response final STORKAttrQueryResponse aResponse1 = new STORKAttrQueryResponse(); aResponse1.setPersonalAttributeList(pal2); - - //Generate the first response - final STORKAttrQueryResponse aStorkResponse1 = getEngine2() - .generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse1, ipAddress, - destination, isNotHashing); - + + // Generate the first response + final STORKAttrQueryResponse aStorkResponse1 = getEngine2().generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse1, ipAddress, destination, isNotHashing); + attrQueryResponse = aStorkResponse1.getTokenSaml(); - - //Validate it and add to the response list + + // Validate it and add to the response list resList.add(getEngine2().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress)); - - //Create a second response like the first + + // Create a second response like the first final STORKAttrQueryResponse aResponse2 = new STORKAttrQueryResponse(); aResponse2.setPersonalAttributeList(pal2); - - final STORKAttrQueryResponse aStorkResponse2 = getEngine() - .generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse2, ipAddress, - destination, isNotHashing); - + + final STORKAttrQueryResponse aStorkResponse2 = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse2, ipAddress, destination, isNotHashing); + attrQueryResponse = aStorkResponse2.getTokenSaml(); - + resList.add(getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress)); - - //Create a attribute query response which contains multiple assertions from an AP + + // Create a attribute query response which contains multiple assertions from an AP final STORKAttrQueryResponse aResponseMulti = new STORKAttrQueryResponse(); aResponseMulti.setPersonalAttributeList(pal2); - - //Create a list for the responses which the multiple assertion response will hold + + // Create a list for the responses which the multiple assertion response will hold List multiResponses = new ArrayList(); - - //Create two more simple responses which the multi assertion response will hold + + // Create two more simple responses which the multi assertion response will hold final STORKAttrQueryResponse aResponse3 = new STORKAttrQueryResponse(); aResponse3.setPersonalAttributeList(pal2); - - final STORKAttrQueryResponse aStorkResponse3 = getEngine2() - .generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse3, ipAddress, - destination, isNotHashing); - + + final STORKAttrQueryResponse aStorkResponse3 = getEngine2().generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse3, ipAddress, destination, isNotHashing); + attrQueryResponse = aStorkResponse3.getTokenSaml(); - //Validate and add to the multi response + // Validate and add to the multi response multiResponses.add(getEngine2().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress)); - + final STORKAttrQueryResponse aResponse4 = new STORKAttrQueryResponse(); aResponse4.setPersonalAttributeList(pal2); - - final STORKAttrQueryResponse aStorkResponse4 = getEngine() - .generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse4, ipAddress, - destination, isNotHashing); - + + final STORKAttrQueryResponse aStorkResponse4 = getEngine().generateSTORKAttrQueryResponse(attrQueryenRequest, aResponse4, ipAddress, destination, isNotHashing); + attrQueryResponse = aStorkResponse4.getTokenSaml(); - + multiResponses.add(getEngine2().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress)); - - //Generate the multi assertion query response - final STORKAttrQueryResponse aStorkResponseMulti = getEngine() - .generateSTORKAttrQueryResponseWithAssertions(attrQueryenRequest, aResponseMulti, multiResponses, - ipAddress, destination, isNotHashing); - + + // Generate the multi assertion query response + final STORKAttrQueryResponse aStorkResponseMulti = getEngine().generateSTORKAttrQueryResponseWithAssertions(attrQueryenRequest, aResponseMulti, multiResponses, ipAddress, destination, + isNotHashing); + attrQueryResponse = aStorkResponseMulti.getTokenSaml(); - - //Add to the list of query responses + + // Add to the list of query responses resList.add(getEngine().validateSTORKAttrQueryResponse(attrQueryResponse, ipAddress)); - - //Generate the stork response with all the query responses - final STORKAuthnResponse storkResponse = getEngine() - .generateSTORKAuthnResponseAfterQuery(authenRequest, response, ipAddress, - isNotHashing, resList); + + // Generate the stork response with all the query responses + final STORKAuthnResponse storkResponse = getEngine().generateSTORKAuthnResponseAfterQuery(authenRequest, response, ipAddress, isNotHashing, resList); authResponse = storkResponse.getTokenSaml(); - - //Validate it, write out and print out the personal attribute lists + + // Validate it, write out and print out the personal attribute lists STORKAuthnResponse finalResponse = getEngine().validateSTORKAuthnResponseWithQuery(authResponse, ipAddress); System.out.println("The original pal: " + finalResponse.getPersonalAttributeList().toString()); - for (int i = 0; i < finalResponse.getPersonalAttributeLists().size(); i++) - { - System.out.println("Pal "+ Integer.toString(i) + ": " + finalResponse.getPersonalAttributeLists().get(i).toString()); + for (int i = 0; i < finalResponse.getPersonalAttributeLists().size(); i++) { + System.out.println("Pal " + Integer.toString(i) + ": " + finalResponse.getPersonalAttributeLists().get(i).toString()); } System.out.println("The total pal: " + finalResponse.getTotalPersonalAttributeList().toString()); - + FileOutputStream output = null; - + try { output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/AuthAttrQMultiAssertResponse.xml")); } catch (FileNotFoundException e) { @@ -529,5 +506,5 @@ public class StorkNewResponseTest { e.printStackTrace(); } assertNotNull(finalResponse); - } + } } diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkResponseTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkResponseTest.java index fe6fcd4f6..d09ed7648 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkResponseTest.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkResponseTest.java @@ -49,839 +49,783 @@ import eu.stork.peps.exceptions.STORKSAMLEngineException; * The Class AuthRequestTest. */ public class StorkResponseTest { - - /** The engine. */ - private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); - - /** - * Gets the engine. - * - * @return the engine - */ - public static STORKSAMLEngine getEngine() { - return engine; - } - - /** - * Sets the engine. - * - * @param newEngine the new engine - */ - public static void setEngine(final STORKSAMLEngine newEngine) { - StorkResponseTest.engine = newEngine; - } - - /** The destination. */ - private static String destination; - - /** The service provider name. */ - private static String spName; - - /** The service provider sector. */ - private static String spSector; - - /** The service provider institution. */ - private static String spInstitution; - - /** The service provider application. */ - private static String spApplication; - - /** The service provider country. */ - private static String spCountry; - - /** The service provider id. */ - private static String spId; - - /** The quality authentication assurance level. */ - private static final int QAAL = 3; - - /** The state. */ - private static String state = "ES"; - - /** The town. */ - private static String town = "Madrid"; - - /** The municipality code. */ - private static String municipalityCode = "MA001"; - - /** The postal code. */ - private static String postalCode = "28038"; - - /** The street name. */ - private static String streetName = "Marchamalo"; - - /** The street number. */ - private static String streetNumber = "3"; - - /** The apartament number. */ - private static String apartamentNumber = "5º E"; - - /** The List of Personal Attributes. */ - private static IPersonalAttributeList pal; - - /** The assertion consumer URL. */ - private static String assertConsumerUrl; - - /** The authentication request. */ - private static byte[] authRequest; - - /** The authentication response. */ - private static byte[] authResponse; - - /** The authentication request. */ - private static STORKAuthnRequest authenRequest; - - /** The authentication response. */ - private static STORKAuthnResponse authnResponse; - - /** The Constant LOG. */ - private static final Logger LOG = LoggerFactory - .getLogger(StorkResponseTest.class.getName()); - - /** - * Instantiates a new stork response test. - */ - public StorkResponseTest() { - super(); - } - - /** The IP address. */ - private static String ipAddress; - - /** The is hashing. */ - private final boolean isHashing = Boolean.TRUE; - - /** The is not hashing. */ - private final boolean isNotHashing = Boolean.FALSE; - - /** The ERROR text. */ - private static final String ERROR_TXT = "generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"; - - - /** Parser manager used to parse XML. */ - private static BasicParserPool parser; - - static { - parser = new BasicParserPool(); - parser.setNamespaceAware(true); - - pal = new PersonalAttributeList(); - - PersonalAttribute isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(false); - ArrayList ages = new ArrayList(); - ages.add("16"); - ages.add("18"); - isAgeOver.setValue(ages); - pal.add(isAgeOver); - - PersonalAttribute dateOfBirth = new PersonalAttribute(); - dateOfBirth.setName("dateOfBirth"); - dateOfBirth.setIsRequired(false); - pal.add(dateOfBirth); - - PersonalAttribute eIDNumber = new PersonalAttribute(); - eIDNumber.setName("eIdentifier"); - eIDNumber.setIsRequired(true); - pal.add(eIDNumber); - - final PersonalAttribute givenName = new PersonalAttribute(); - givenName.setName("givenName"); - givenName.setIsRequired(true); - pal.add(givenName); - - PersonalAttribute canRessAddress = new PersonalAttribute(); - canRessAddress.setName("canonicalResidenceAddress"); - canRessAddress.setIsRequired(true); - pal.add(canRessAddress); - - PersonalAttribute newAttribute = new PersonalAttribute(); - newAttribute.setName("newAttribute2"); - newAttribute.setIsRequired(true); - pal.add(newAttribute); - - destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; - assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; - spName = "University Oxford"; - - spName = "University of Oxford"; - spSector = "EDU001"; - spInstitution = "OXF001"; - spApplication = "APP001"; - spCountry = "EN"; - - spId = "EDU001-APP001-APP001"; - - final STORKAuthnRequest request = new STORKAuthnRequest(); - request.setDestination(destination); - request.setProviderName(spName); - request.setQaa(QAAL); - request.setPersonalAttributeList(pal); - request.setAssertionConsumerServiceURL(assertConsumerUrl); - - // news parameters - request.setSpSector(spSector); - request.setSpInstitution(spInstitution); - request.setSpApplication(spApplication); - request.setSpCountry(spCountry); - request.setSPID(spId); - request.setCitizenCountryCode("ES"); - - try { - authRequest = getEngine().generateSTORKAuthnRequest(request) - .getTokenSaml(); - - authenRequest = getEngine().validateSTORKAuthnRequest(authRequest); - - } catch (STORKSAMLEngineException e) { - fail("Error create STORKAuthnRequest"); + + /** The engine. */ + private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); + + /** + * Gets the engine. + * + * @return the engine + */ + public static STORKSAMLEngine getEngine() { + return engine; + } + + /** + * Sets the engine. + * + * @param newEngine + * the new engine + */ + public static void setEngine(final STORKSAMLEngine newEngine) { + StorkResponseTest.engine = newEngine; + } + + /** The destination. */ + private static String destination; + + /** The service provider name. */ + private static String spName; + + /** The service provider sector. */ + private static String spSector; + + /** The service provider institution. */ + private static String spInstitution; + + /** The service provider application. */ + private static String spApplication; + + /** The service provider country. */ + private static String spCountry; + + /** The service provider id. */ + private static String spId; + + /** The quality authentication assurance level. */ + private static final int QAAL = 3; + + /** The state. */ + private static String state = "ES"; + + /** The town. */ + private static String town = "Madrid"; + + /** The municipality code. */ + private static String municipalityCode = "MA001"; + + /** The postal code. */ + private static String postalCode = "28038"; + + /** The street name. */ + private static String streetName = "Marchamalo"; + + /** The street number. */ + private static String streetNumber = "3"; + + /** The apartament number. */ + private static String apartamentNumber = "5º E"; + + /** The List of Personal Attributes. */ + private static IPersonalAttributeList pal; + + /** The assertion consumer URL. */ + private static String assertConsumerUrl; + + /** The authentication request. */ + private static byte[] authRequest; + + /** The authentication response. */ + private static byte[] authResponse; + + /** The authentication request. */ + private static STORKAuthnRequest authenRequest; + + /** The authentication response. */ + private static STORKAuthnResponse authnResponse; + + /** The Constant LOG. */ + private static final Logger LOG = LoggerFactory.getLogger(StorkResponseTest.class.getName()); + + /** + * Instantiates a new stork response test. + */ + public StorkResponseTest() { + super(); + } + + /** The IP address. */ + private static String ipAddress; + + /** The is hashing. */ + private final boolean isHashing = Boolean.TRUE; + + /** The is not hashing. */ + private final boolean isNotHashing = Boolean.FALSE; + + /** The ERROR text. */ + private static final String ERROR_TXT = "generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"; + + /** Parser manager used to parse XML. */ + private static BasicParserPool parser; + + static { + parser = new BasicParserPool(); + parser.setNamespaceAware(true); + + pal = new PersonalAttributeList(); + + PersonalAttribute isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(false); + ArrayList ages = new ArrayList(); + ages.add("16"); + ages.add("18"); + isAgeOver.setValue(ages); + pal.add(isAgeOver); + + PersonalAttribute dateOfBirth = new PersonalAttribute(); + dateOfBirth.setName("dateOfBirth"); + dateOfBirth.setIsRequired(false); + pal.add(dateOfBirth); + + PersonalAttribute eIDNumber = new PersonalAttribute(); + eIDNumber.setName("eIdentifier"); + eIDNumber.setIsRequired(true); + pal.add(eIDNumber); + + final PersonalAttribute givenName = new PersonalAttribute(); + givenName.setName("givenName"); + givenName.setIsRequired(true); + pal.add(givenName); + + PersonalAttribute canRessAddress = new PersonalAttribute(); + canRessAddress.setName("canonicalResidenceAddress"); + canRessAddress.setIsRequired(true); + pal.add(canRessAddress); + + PersonalAttribute newAttribute = new PersonalAttribute(); + newAttribute.setName("newAttribute2"); + newAttribute.setIsRequired(true); + pal.add(newAttribute); + + destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; + assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; + spName = "University Oxford"; + + spName = "University of Oxford"; + spSector = "EDU001"; + spInstitution = "OXF001"; + spApplication = "APP001"; + spCountry = "EN"; + + spId = "EDU001-APP001-APP001"; + + final STORKAuthnRequest request = new STORKAuthnRequest(); + request.setDestination(destination); + request.setProviderName(spName); + request.setQaa(QAAL); + request.setPersonalAttributeList(pal); + request.setAssertionConsumerServiceURL(assertConsumerUrl); + + // news parameters + request.setSpSector(spSector); + request.setSpInstitution(spInstitution); + request.setSpApplication(spApplication); + request.setSpCountry(spCountry); + request.setSPID(spId); + request.setCitizenCountryCode("ES"); + + try { + authRequest = getEngine().generateSTORKAuthnRequest(request).getTokenSaml(); + + authenRequest = getEngine().validateSTORKAuthnRequest(authRequest); + + } catch (STORKSAMLEngineException e) { + fail("Error create STORKAuthnRequest"); + } + + ipAddress = "111.222.333.444"; + + pal = new PersonalAttributeList(); + + isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(true); + ages = new ArrayList(); + + ages.add("16"); + ages.add("18"); + + isAgeOver.setValue(ages); + isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(isAgeOver); + + dateOfBirth = new PersonalAttribute(); + dateOfBirth.setName("dateOfBirth"); + dateOfBirth.setIsRequired(false); + final ArrayList date = new ArrayList(); + date.add("16/12/2008"); + dateOfBirth.setValue(date); + dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(dateOfBirth); + + eIDNumber = new PersonalAttribute(); + eIDNumber.setName("eIdentifier"); + eIDNumber.setIsRequired(true); + final ArrayList idNumber = new ArrayList(); + idNumber.add("123456789PÑ"); + eIDNumber.setValue(idNumber); + eIDNumber.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + pal.add(eIDNumber); + + canRessAddress = new PersonalAttribute(); + canRessAddress.setName("canonicalResidenceAddress"); + canRessAddress.setIsRequired(true); + canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + final HashMap address = new HashMap(); + + address.put("state", state); + address.put("municipalityCode", municipalityCode); + address.put("town", town); + address.put("postalCode", postalCode); + address.put("streetName", streetName); + address.put("streetNumber", streetNumber); + address.put("apartamentNumber", apartamentNumber); + + canRessAddress.setComplexValue(address); + pal.add(canRessAddress); + + newAttribute = new PersonalAttribute(); + newAttribute.setName("newAttribute2"); + newAttribute.setIsRequired(true); + newAttribute.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + final HashMap values = new HashMap(); + + values.put("value1", "value1"); + values.put("value2", "value2"); + values.put("value3", "value3"); + values.put("value4", "value4"); + + newAttribute.setComplexValue(values); + pal.add(newAttribute); + + } + + /** + * Test generate authentication request without errors. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateAuthnResponse() throws STORKSAMLEngineException { + + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setPersonalAttributeList(pal); + + final STORKAuthnResponse storkResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing); + + authResponse = storkResponse.getTokenSaml(); + + LOG.info("RESPONSE: " + SSETestUtils.encodeSAMLToken(authResponse)); + } - ipAddress = "111.222.333.444"; - - pal = new PersonalAttributeList(); - - isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(true); - ages = new ArrayList(); - - ages.add("16"); - ages.add("18"); - - isAgeOver.setValue(ages); - isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(isAgeOver); - - dateOfBirth = new PersonalAttribute(); - dateOfBirth.setName("dateOfBirth"); - dateOfBirth.setIsRequired(false); - final ArrayList date = new ArrayList(); - date.add("16/12/2008"); - dateOfBirth.setValue(date); - dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(dateOfBirth); - - eIDNumber = new PersonalAttribute(); - eIDNumber.setName("eIdentifier"); - eIDNumber.setIsRequired(true); - final ArrayList idNumber = new ArrayList(); - idNumber.add("123456789PÑ"); - eIDNumber.setValue(idNumber); - eIDNumber.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - pal.add(eIDNumber); - - canRessAddress = new PersonalAttribute(); - canRessAddress.setName("canonicalResidenceAddress"); - canRessAddress.setIsRequired(true); - canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - final HashMap address = new HashMap(); - - address.put("state", state); - address.put("municipalityCode", municipalityCode); - address.put("town", town); - address.put("postalCode", postalCode); - address.put("streetName", streetName); - address.put("streetNumber", streetNumber); - address.put("apartamentNumber", apartamentNumber); - - canRessAddress.setComplexValue(address); - pal.add(canRessAddress); - - newAttribute = new PersonalAttribute(); - newAttribute.setName("newAttribute2"); - newAttribute.setIsRequired(true); - newAttribute.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - final HashMap values = new HashMap(); - - values.put("value1", "value1"); - values.put("value2", "value2"); - values.put("value3", "value3"); - values.put("value4", "value4"); - - newAttribute.setComplexValue(values); - pal.add(newAttribute); - - } - - /** - * Test generate authentication request without errors. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testGenerateAuthnResponse() throws STORKSAMLEngineException { - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setPersonalAttributeList(pal); - - final STORKAuthnResponse storkResponse = getEngine() - .generateSTORKAuthnResponse(authenRequest, response, ipAddress, - isNotHashing); - - authResponse = storkResponse.getTokenSaml(); - - LOG.info("RESPONSE: " + SSETestUtils.encodeSAMLToken(authResponse)); - - - } - - /** - * Test validation id parameter mandatory. - */ - @Test - public final void testResponseMandatoryId() { - final String identifier = authenRequest.getSamlId(); - authenRequest.setSamlId(null); - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setPersonalAttributeList(pal); - - try { - getEngine().generateSTORKAuthnResponse(authenRequest, response, - ipAddress, isHashing); - fail(ERROR_TXT); - } catch (STORKSAMLEngineException e) { - authenRequest.setSamlId(identifier); - LOG.error("Error"); + /** + * Test validation id parameter mandatory. + */ + @Test + public final void testResponseMandatoryId() { + final String identifier = authenRequest.getSamlId(); + authenRequest.setSamlId(null); + + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setPersonalAttributeList(pal); + + try { + getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isHashing); + fail(ERROR_TXT); + } catch (STORKSAMLEngineException e) { + authenRequest.setSamlId(identifier); + LOG.error("Error"); + } } - } - - /** - * Test generate authentication response in response to err1. - */ - @Test - public final void testResponseMandatoryIssuer() { - - final String issuer = authenRequest.getIssuer(); - authenRequest.setIssuer(null); - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setPersonalAttributeList(pal); - - try { - getEngine().generateSTORKAuthnResponse(authenRequest, response, - ipAddress, isHashing); - fail(ERROR_TXT); - } catch (STORKSAMLEngineException e) { - authenRequest.setIssuer(issuer); - LOG.error("Error"); + + /** + * Test generate authentication response in response to err1. + */ + @Test + public final void testResponseMandatoryIssuer() { + + final String issuer = authenRequest.getIssuer(); + authenRequest.setIssuer(null); + + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setPersonalAttributeList(pal); + + try { + getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isHashing); + fail(ERROR_TXT); + } catch (STORKSAMLEngineException e) { + authenRequest.setIssuer(issuer); + LOG.error("Error"); + } } - } - - /** - * Test generate authentication response assertion consumer null. - */ - @Test - public final void testResponseMandatoryAssertionConsumerServiceURL() { - final String asserConsumerUrl = authenRequest - .getAssertionConsumerServiceURL(); - authenRequest.setAssertionConsumerServiceURL(null); - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setPersonalAttributeList(pal); - try { - getEngine().generateSTORKAuthnResponse(authenRequest, response, - ipAddress, isHashing); - fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - authenRequest.setAssertionConsumerServiceURL(asserConsumerUrl); - LOG.error("Error"); + + /** + * Test generate authentication response assertion consumer null. + */ + @Test + public final void testResponseMandatoryAssertionConsumerServiceURL() { + final String asserConsumerUrl = authenRequest.getAssertionConsumerServiceURL(); + authenRequest.setAssertionConsumerServiceURL(null); + + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setPersonalAttributeList(pal); + try { + getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isHashing); + fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + authenRequest.setAssertionConsumerServiceURL(asserConsumerUrl); + LOG.error("Error"); + } } - } - - /** - * Test generate authentication response IP address null. - */ - @Test - public final void testResponseValidationIP() { - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setPersonalAttributeList(pal); - - try { - getEngine().generateSTORKAuthnResponse(authenRequest, response, null, - isHashing); - fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate authentication response IP address null. + */ + @Test + public final void testResponseValidationIP() { + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setPersonalAttributeList(pal); + + try { + getEngine().generateSTORKAuthnResponse(authenRequest, response, null, isHashing); + fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } + } + + /** + * Test generate authentication response with personal attribute list null. + */ + @Test + public final void testResponseMandatoryPersonalAttributeList() { + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setPersonalAttributeList(null); + + try { + getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isHashing); + fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } + } + + /** + * Test validate authentication response token null. + */ + @Test + public final void testResponseInvalidParametersToken() { + try { + getEngine().validateSTORKAuthnResponse(null, ipAddress); + fail(ERROR_TXT); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } + } + + /** + * Test validate authentication response IP null. + */ + @Test + public final void testResponseInvalidParametersIP() { + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setPersonalAttributeList(pal); + try { + authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAuthnResponse(authResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test generate authentication response with personal attribute list null. - */ - @Test - public final void testResponseMandatoryPersonalAttributeList() { - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setPersonalAttributeList(null); - - - try { - getEngine().generateSTORKAuthnResponse(authenRequest, response, - ipAddress, isHashing); - fail("generateAuthnResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response parameter name wrong. + */ + @Test + public final void testResponseInvalidParametersAttr() { + final STORKAuthnResponse response = new STORKAuthnResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("AttrWrong"); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAuthnResponse(authResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } + } + + /** + * Test validate authentication response set null value into attribute. + */ + @Test + public final void testResponseInvalidParametersAttrSimpleValue() { + final STORKAuthnResponse response = new STORKAuthnResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("isAgeOver"); + worngAttr.setValue(null); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAuthnResponse(authResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test validate authentication response token null. - */ - @Test - public final void testResponseInvalidParametersToken() { - try { - getEngine().validateSTORKAuthnResponse(null, ipAddress); - fail(ERROR_TXT); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response set null value into attribute. + */ + @Test + public final void testResponseInvalidParametersAttrNoValue() { + final STORKAuthnResponse response = new STORKAuthnResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("isAgeOver"); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAuthnResponse(authResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test validate authentication response IP null. - */ - @Test - public final void testResponseInvalidParametersIP() { - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setPersonalAttributeList(pal); - try { - authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAuthnResponse(authResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response set null value into attribute. + */ + @Test + public final void testResponseInvalidParametersAttrNoName() { + final STORKAuthnResponse response = new STORKAuthnResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAuthnResponse(authResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate authentication response parameter name wrong. - */ - @Test - public final void testResponseInvalidParametersAttr() { - final STORKAuthnResponse response = new STORKAuthnResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("AttrWrong"); - wrongList.add(worngAttr); - - - response.setPersonalAttributeList(wrongList); - try { - authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAuthnResponse(authResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response set null complex value into attribute. + */ + @Test + public final void testResponseInvalidParametersAttrComplexValue() { + final STORKAuthnResponse response = new STORKAuthnResponse(); + final IPersonalAttributeList wrongList = new PersonalAttributeList(); + + final PersonalAttribute worngAttr = new PersonalAttribute(); + worngAttr.setName("isAgeOver"); + worngAttr.setComplexValue(null); + wrongList.add(worngAttr); + + response.setPersonalAttributeList(wrongList); + try { + authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + // In Conf1 ipValidate is false + getEngine().validateSTORKAuthnResponse(authResponse, null); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate authentication response set null value into attribute. - */ - @Test - public final void testResponseInvalidParametersAttrSimpleValue() { - final STORKAuthnResponse response = new STORKAuthnResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("isAgeOver"); - worngAttr.setValue(null); - wrongList.add(worngAttr); - - response.setPersonalAttributeList(wrongList); - try { - authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAuthnResponse(authResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response IP distinct and disabled validation IP. + */ + @Test + public final void testResponseInvalidParametersIPDistinct() { + try { + // ipAddress origin "111.222.333.444" + // ipAddrValidation = false + // Subject Confirmation Bearer. + + getEngine().validateSTORKAuthnResponse(authResponse, "127.0.0.1"); + fail("validateAuthenticationResponse(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate authentication response set null value into attribute. - */ - @Test - public final void testResponseInvalidParametersAttrNoValue() { - final STORKAuthnResponse response = new STORKAuthnResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("isAgeOver"); - wrongList.add(worngAttr); - - response.setPersonalAttributeList(wrongList); - try { - authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAuthnResponse(authResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test response invalid parameters invalid token. + */ + @Test + public final void testResponseInvalidParametersTokenMsg() { + try { + // ipAddress origin "111.222.333.444" + // Subject Confirmation Bearer. + getEngine().validateSTORKAuthnResponse("errorMessage".getBytes(), ipAddress); + fail("validateAuthenticationResponse(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - - /** - * Test validate authentication response set null value into attribute. - */ - @Test - public final void testResponseInvalidParametersAttrNoName() { - final STORKAuthnResponse response = new STORKAuthnResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - wrongList.add(worngAttr); - - response.setPersonalAttributeList(wrongList); - try { - authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAuthnResponse(authResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response is fail. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAuthenticationResponseIsFail() throws STORKSAMLEngineException { + if (authResponse == null) + testGenerateAuthnResponse(); + + authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, ipAddress); + + assertFalse("Generate incorrect response: ", authnResponse.isFail()); } - } - - - /** - * Test validate authentication response set null complex value into attribute. - */ - @Test - public final void testResponseInvalidParametersAttrComplexValue() { - final STORKAuthnResponse response = new STORKAuthnResponse(); - final IPersonalAttributeList wrongList = new PersonalAttributeList(); - - final PersonalAttribute worngAttr = new PersonalAttribute(); - worngAttr.setName("isAgeOver"); - worngAttr.setComplexValue(null); - wrongList.add(worngAttr); - - response.setPersonalAttributeList(wrongList); - try { - authResponse = getEngine().generateSTORKAuthnResponse(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - // In Conf1 ipValidate is false - getEngine().validateSTORKAuthnResponse(authResponse, null); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response destination. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAuthenticationResponseDestination() throws STORKSAMLEngineException { + authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, ipAddress); + + assertEquals("Destination incorrect: ", authnResponse.getInResponseTo(), authenRequest.getSamlId()); } - } - - - - - /** - * Test validate authentication response IP distinct and disabled validation - * IP. - */ - @Test - public final void testResponseInvalidParametersIPDistinct() { - try { - // ipAddress origin "111.222.333.444" - // ipAddrValidation = false - // Subject Confirmation Bearer. - - getEngine().validateSTORKAuthnResponse(authResponse, "127.0.0.1"); - fail("validateAuthenticationResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response values. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + public final void testValidateAuthenticationResponseValuesComplex() throws STORKSAMLEngineException { + authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, ipAddress); + + assertEquals("Country incorrect:", authnResponse.getCountry(), "EN"); + + final Iterator iterator = authnResponse.getPersonalAttributeList().iterator(); + + while (iterator.hasNext()) { + final PersonalAttribute attribute = iterator.next(); + if (attribute.getName().equalsIgnoreCase("canonicalResidenceAddress")) { + assertEquals("State incorrect: ", state, attribute.getComplexValue().get("state")); + assertEquals("Municipality Code incorrect: ", municipalityCode, attribute.getComplexValue().get("municipalityCode")); + assertEquals("Town incorrect: ", town, attribute.getComplexValue().get("town")); + assertEquals("Postal code incorrect: ", postalCode, attribute.getComplexValue().get("postalCode")); + assertEquals("Street name incorrect: ", streetName, attribute.getComplexValue().get("streetName")); + assertEquals("Street number incorrect: ", streetNumber, attribute.getComplexValue().get("streetNumber")); + assertEquals("Apartament number incorrect: ", apartamentNumber, attribute.getComplexValue().get("apartamentNumber")); + } + } } - } - - /** - * Test response invalid parameters invalid token. - */ - @Test - public final void testResponseInvalidParametersTokenMsg() { - try { - // ipAddress origin "111.222.333.444" - // Subject Confirmation Bearer. - getEngine().validateSTORKAuthnResponse("errorMessage".getBytes(), - ipAddress); - fail("validateAuthenticationResponse(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test generate authenticate response fail in response to it's null. + * + * @throws STORKSAMLEngineException + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + // ( expected=STORKSAMLEngineException.class) + public final void testGenerateAuthnResponseFailInResponseToNull() throws STORKSAMLEngineException { + final String identifier = authenRequest.getSamlId(); + authenRequest.setSamlId(null); + + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); + response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); + response.setMessage(""); + + try { + authResponse = getEngine().generateSTORKAuthnResponseFail(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + fail(ERROR_TXT); + } catch (STORKSAMLEngineException e) { + authenRequest.setSamlId(identifier); + LOG.error("Error"); + // throw new STORKSAMLEngineException(e); + } } - } - - /** - * Test validate authentication response is fail. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthenticationResponseIsFail() - throws STORKSAMLEngineException { - if (authResponse == null) - testGenerateAuthnResponse(); - - authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, - ipAddress); - - assertFalse("Generate incorrect response: ", authnResponse.isFail()); - } - - /** - * Test validate authentication response destination. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthenticationResponseDestination() - throws STORKSAMLEngineException { - authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, - ipAddress); - - assertEquals("Destination incorrect: ", - authnResponse.getInResponseTo(), authenRequest.getSamlId()); - } - - /** - * Test validate authentication response values. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - public final void testValidateAuthenticationResponseValuesComplex() - throws STORKSAMLEngineException { - authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, - ipAddress); - - assertEquals("Country incorrect:", authnResponse.getCountry(), "EN"); - - final Iterator iterator = authnResponse - .getPersonalAttributeList().iterator(); - - while (iterator.hasNext()) { - final PersonalAttribute attribute = iterator.next(); - if (attribute.getName().equalsIgnoreCase( - "canonicalResidenceAddress")) { - assertEquals("State incorrect: ", state, attribute - .getComplexValue().get("state")); - assertEquals("Municipality Code incorrect: ", municipalityCode, - attribute.getComplexValue().get("municipalityCode")); - assertEquals("Town incorrect: ", town, attribute - .getComplexValue().get("town")); - assertEquals("Postal code incorrect: ", postalCode, attribute - .getComplexValue().get("postalCode")); - assertEquals("Street name incorrect: ", streetName, attribute - .getComplexValue().get("streetName")); - assertEquals("Street number incorrect: ", streetNumber, - attribute.getComplexValue().get("streetNumber")); - assertEquals("Apartament number incorrect: ", apartamentNumber, - attribute.getComplexValue().get("apartamentNumber")); - } + + /** + * Test generate authenticate response fail assertion consumer URL err1. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateAuthnResponseFailAssertionConsumerUrlNull() throws STORKSAMLEngineException { + + final String assertConsumerUrl = authenRequest.getAssertionConsumerServiceURL(); + authenRequest.setAssertionConsumerServiceURL(null); + + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); + response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); + response.setMessage(""); + + try { + authResponse = getEngine().generateSTORKAuthnResponseFail(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + fail("generateAuthnResponseFail(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + authenRequest.setAssertionConsumerServiceURL(assertConsumerUrl); + LOG.error("Error"); + } } - } - - /** - * Test generate authenticate response fail in response to it's null. - * @throws STORKSAMLEngineException - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test //( expected=STORKSAMLEngineException.class) - public final void testGenerateAuthnResponseFailInResponseToNull() throws STORKSAMLEngineException { - final String identifier = authenRequest.getSamlId(); - authenRequest.setSamlId(null); - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); - response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); - response.setMessage(""); - - try { - authResponse = getEngine().generateSTORKAuthnResponseFail(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - fail(ERROR_TXT); - } catch (STORKSAMLEngineException e) { - authenRequest.setSamlId(identifier); - LOG.error("Error"); - //throw new STORKSAMLEngineException(e); + + /** + * Test generate authentication response fail code error err1. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testGenerateAuthnResponseFailCodeErrorNull() throws STORKSAMLEngineException { + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setStatusCode(null); + response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); + response.setMessage(""); + + try { + authResponse = getEngine().generateSTORKAuthnResponseFail(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + fail("generateAuthnResponseFail(...) should've thrown an STORKSAMLEngineException!"); + } catch (STORKSAMLEngineException e) { + LOG.error("Error"); + } } - } - - /** - * Test generate authenticate response fail assertion consumer URL err1. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testGenerateAuthnResponseFailAssertionConsumerUrlNull() - throws STORKSAMLEngineException { - - final String assertConsumerUrl = authenRequest - .getAssertionConsumerServiceURL(); - authenRequest.setAssertionConsumerServiceURL(null); - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); - response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); - response.setMessage(""); - - try { - authResponse = getEngine().generateSTORKAuthnResponseFail(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - fail("generateAuthnResponseFail(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - authenRequest.setAssertionConsumerServiceURL(assertConsumerUrl); - LOG.error("Error"); + + /** + * Test generate authentication request without errors. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAuthnResponse() throws STORKSAMLEngineException { + + IPersonalAttributeList palist = new PersonalAttributeList(); + + PersonalAttribute isAgeOver = new PersonalAttribute(); + isAgeOver.setName("isAgeOver"); + isAgeOver.setIsRequired(true); + ArrayList ages = new ArrayList(); + ages.add("16"); + ages.add("18"); + isAgeOver.setValue(ages); + isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + palist.add(isAgeOver); + + PersonalAttribute dateOfBirth = new PersonalAttribute(); + dateOfBirth.setName("dateOfBirth"); + dateOfBirth.setIsRequired(false); + final ArrayList date = new ArrayList(); + date.add("16/12/2008"); + dateOfBirth.setValue(date); + dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + palist.add(dateOfBirth); + + PersonalAttribute eIDNumber = new PersonalAttribute(); + eIDNumber.setName("eIdentifier"); + eIDNumber.setIsRequired(true); + + final ArrayList idNumber = new ArrayList(); + idNumber.add("123456789PÑ"); + + final HashMap complex = new HashMap(); + complex.put("one", "two"); + + // eIDNumber.setValue(null); + // eIDNumber.setValue(idNumber); + // eIDNumber.setComplexValue(complex); + + eIDNumber.setStatus(STORKStatusCode.STATUS_NOT_AVAILABLE.toString()); + palist.add(eIDNumber); + + PersonalAttribute canRessAddress = new PersonalAttribute(); + canRessAddress.setName("canonicalResidenceAddress"); + canRessAddress.setIsRequired(true); + canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); + final HashMap address = new HashMap(); + + address.put("state", state); + address.put("municipalityCode", municipalityCode); + address.put("town", town); + address.put("postalCode", postalCode); + address.put("streetName", streetName); + address.put("streetNumber", streetNumber); + address.put("apartamentNumber", apartamentNumber); + + canRessAddress.setComplexValue(address); + palist.add(canRessAddress); + + final STORKAuthnResponse response = new STORKAuthnResponse(); + + response.setPersonalAttributeList(palist); + + final STORKAuthnResponse storkResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing); + + authResponse = storkResponse.getTokenSaml(); + LOG.info("Request id: " + authenRequest.getSamlId()); + + LOG.info("RESPONSE: " + SSETestUtils.encodeSAMLToken(authResponse)); + + authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, ipAddress); + + LOG.info("RESPONSE ID: " + authnResponse.getSamlId()); + LOG.info("RESPONSE IN_RESPONSE_TO: " + authnResponse.getInResponseTo()); + LOG.info("RESPONSE COUNTRY: " + authnResponse.getCountry()); + } - } - - /** - * Test generate authentication response fail code error err1. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testGenerateAuthnResponseFailCodeErrorNull() - throws STORKSAMLEngineException { - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setStatusCode(null); - response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); - response.setMessage(""); - - try { - authResponse = getEngine().generateSTORKAuthnResponseFail(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - fail("generateAuthnResponseFail(...) should've thrown an STORKSAMLEngineException!"); - } catch (STORKSAMLEngineException e) { - LOG.error("Error"); + + /** + * Test validate authentication response fail is fail. + * + * @throws STORKSAMLEngineException + * the STORKSAML engine exception + */ + @Test + public final void testValidateAuthenticationResponseFailIsFail() throws STORKSAMLEngineException { + + final STORKAuthnResponse response = new STORKAuthnResponse(); + response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); + response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); + response.setMessage("message"); + + authResponse = getEngine().generateSTORKAuthnResponseFail(authenRequest, response, ipAddress, isNotHashing).getTokenSaml(); + + LOG.error("ERROR_FAIL: " + PEPSUtil.encodeSAMLToken(authResponse)); + + authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, ipAddress); + + LOG.info("COUNTRY: " + authnResponse.getCountry()); + assertTrue("Generate incorrect response: ", authnResponse.isFail()); } - } - - - - - /** - * Test generate authentication request without errors. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthnResponse() throws STORKSAMLEngineException { - - IPersonalAttributeList palist = new PersonalAttributeList(); - - PersonalAttribute isAgeOver = new PersonalAttribute(); - isAgeOver.setName("isAgeOver"); - isAgeOver.setIsRequired(true); - ArrayList ages = new ArrayList(); - ages.add("16"); - ages.add("18"); - isAgeOver.setValue(ages); - isAgeOver.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - palist.add(isAgeOver); - - PersonalAttribute dateOfBirth = new PersonalAttribute(); - dateOfBirth.setName("dateOfBirth"); - dateOfBirth.setIsRequired(false); - final ArrayList date = new ArrayList(); - date.add("16/12/2008"); - dateOfBirth.setValue(date); - dateOfBirth.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - palist.add(dateOfBirth); - - - PersonalAttribute eIDNumber = new PersonalAttribute(); - eIDNumber.setName("eIdentifier"); - eIDNumber.setIsRequired(true); - - final ArrayList idNumber = new ArrayList(); - idNumber.add("123456789PÑ"); - - final HashMap complex = new HashMap(); - complex.put("one", "two"); - - //eIDNumber.setValue(null); - //eIDNumber.setValue(idNumber); - //eIDNumber.setComplexValue(complex); - - eIDNumber.setStatus(STORKStatusCode.STATUS_NOT_AVAILABLE.toString()); - palist.add(eIDNumber); - - PersonalAttribute canRessAddress = new PersonalAttribute(); - canRessAddress.setName("canonicalResidenceAddress"); - canRessAddress.setIsRequired(true); - canRessAddress.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString()); - final HashMap address = new HashMap(); - - address.put("state", state); - address.put("municipalityCode", municipalityCode); - address.put("town", town); - address.put("postalCode", postalCode); - address.put("streetName", streetName); - address.put("streetNumber", streetNumber); - address.put("apartamentNumber", apartamentNumber); - - canRessAddress.setComplexValue(address); - palist.add(canRessAddress); - - - final STORKAuthnResponse response = new STORKAuthnResponse(); - - response.setPersonalAttributeList(palist); - - final STORKAuthnResponse storkResponse = getEngine() - .generateSTORKAuthnResponse(authenRequest, response, ipAddress, - isNotHashing); - - authResponse = storkResponse.getTokenSaml(); - LOG.info("Request id: " + authenRequest.getSamlId()); - - LOG.info("RESPONSE: " + SSETestUtils.encodeSAMLToken(authResponse)); - - - authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, - ipAddress); - - LOG.info("RESPONSE ID: " + authnResponse.getSamlId()); - LOG.info("RESPONSE IN_RESPONSE_TO: " + authnResponse.getInResponseTo()); - LOG.info("RESPONSE COUNTRY: " + authnResponse.getCountry()); - - } - - - - - - /** - * Test validate authentication response fail is fail. - * - * @throws STORKSAMLEngineException the STORKSAML engine exception - */ - @Test - public final void testValidateAuthenticationResponseFailIsFail() - throws STORKSAMLEngineException { - - final STORKAuthnResponse response = new STORKAuthnResponse(); - response.setStatusCode(STORKStatusCode.REQUESTER_URI.toString()); - response.setSubStatusCode(STORKSubStatusCode.AUTHN_FAILED_URI.toString()); - response.setMessage("message"); - - authResponse = getEngine().generateSTORKAuthnResponseFail(authenRequest, - response, ipAddress, isNotHashing).getTokenSaml(); - - LOG.error("ERROR_FAIL: " + PEPSUtil.encodeSAMLToken(authResponse)); - - authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, - ipAddress); - - LOG.info("COUNTRY: " + authnResponse.getCountry()); - assertTrue("Generate incorrect response: ", authnResponse.isFail()); - } - + /** * Test generate/validate response with signedDoc * @@ -889,8 +833,7 @@ public class StorkResponseTest { * the STORKSAML engine exception */ @Test - public final void testGenerateAuthenResponseWithSignedDoc() - throws STORKSAMLEngineException { + public final void testGenerateAuthenResponseWithSignedDoc() throws STORKSAMLEngineException { String signedDocResponse = " urn:oasis:names:tc:dss:1.0:resultmajor:Success PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48ZHM6U2lnbmF0dXJlIHhtbG5zOmRzPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwLzA5L3htbGRzaWcjIiBJZD0iU2lnbmF0dXJlLThlYWJkMGE1LTY2MGQtNGFmZC05OTA1LTBhYmM3NTUzZDE5Mi1TaWduYXR1cmUiPjxkczpTaWduZWRJbmZvPjxkczpDYW5vbmlj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ybWF0PjwveGFkZXM6U2lnbmVkRGF0YU9iamVjdFByb3BlcnRpZXM+PC94YWRlczpTaWduZWRQcm9wZXJ0aWVzPjwveGFkZXM6UXVhbGlmeWluZ1Byb3BlcnRpZXM+PC9kczpPYmplY3Q+PC9kczpTaWduYXR1cmU+ "; @@ -919,17 +862,12 @@ public class StorkResponseTest { response.setPersonalAttributeList(palist); - final STORKAuthnResponse storkResponse = getEngine() - .generateSTORKAuthnResponse(authenRequest, response, ipAddress, - isNotHashing); + final STORKAuthnResponse storkResponse = getEngine().generateSTORKAuthnResponse(authenRequest, response, ipAddress, isNotHashing); authResponse = storkResponse.getTokenSaml(); - authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, - ipAddress); + authnResponse = getEngine().validateSTORKAuthnResponse(authResponse, ipAddress); - assertTrue("SignedDoc response should be the same: ", authnResponse - .getPersonalAttributeList().get("signedDoc").getValue().get(0) - .equals(signedDocResponse)); + assertTrue("SignedDoc response should be the same: ", authnResponse.getPersonalAttributeList().get("signedDoc").getValue().get(0).equals(signedDocResponse)); - } + } } -- cgit v1.2.3 From 496ba9bb6e150ad67c5c628c1c97f30d6da81dfb Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Mon, 10 Aug 2015 16:35:14 +0200 Subject: approved changes --- .../eu/stork/peps/test/simple/StorkAttrQueryRequestTest.java | 12 ++++++++++++ .../java/eu/stork/peps/test/simple/StorkAuthRequestTest.java | 12 +++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'id/server/stork2-saml-engine/src/test/java/eu') 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 index 502e0e461..4f22df7fb 100644 --- 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 @@ -59,6 +59,18 @@ public class StorkAttrQueryRequestTest { givenName.setValue(Arrays.asList("Sveinbjorn")); pal.add(givenName); + final PersonalAttribute fiscalNumber = new PersonalAttribute(); + fiscalNumber.setName("fiscalNumber"); + fiscalNumber.setIsRequired(true); + fiscalNumber.setValue(Arrays.asList("fiscalNumber")); + pal.add(fiscalNumber); + + final PersonalAttribute LPFiscalNumber = new PersonalAttribute(); + LPFiscalNumber.setName("LPFiscalNumber"); + LPFiscalNumber.setIsRequired(true); + LPFiscalNumber.setValue(Arrays.asList("LPFiscalNumber")); + pal.add(LPFiscalNumber); + destination = "http://A-PEPS.gov.xx/PEPS/AttributeColleagueRequest"; assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; // spName = "University of Oxford"; diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAuthRequestTest.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAuthRequestTest.java index beca213ac..d476ad26e 100644 --- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAuthRequestTest.java +++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/StorkAuthRequestTest.java @@ -21,15 +21,12 @@ import java.util.ArrayList; 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.STORKAuthnRequest; +import eu.stork.peps.*; +import eu.stork.peps.auth.commons.*; import eu.stork.peps.auth.engine.STORKSAMLEngine; import eu.stork.peps.exceptions.STORKSAMLEngineException; @@ -68,6 +65,11 @@ public class StorkAuthRequestTest { eIDNumber.setIsRequired(true); pal.add(eIDNumber); + final PersonalAttribute LPFiscalNumber = new PersonalAttribute(); + LPFiscalNumber.setName("LPFiscalNumber"); + LPFiscalNumber.setIsRequired(true); + pal.add(LPFiscalNumber); + destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; assertConsumerUrl = "http://S-PEPS.gov.xx/PEPS/ColleagueResponse"; -- cgit v1.2.3