aboutsummaryrefslogtreecommitdiff
path: root/DocumentService/src/eu/stork/documentservice/tests
diff options
context:
space:
mode:
Diffstat (limited to 'DocumentService/src/eu/stork/documentservice/tests')
-rw-r--r--DocumentService/src/eu/stork/documentservice/tests/AttrQueryRequestSdoc.xml15
-rw-r--r--DocumentService/src/eu/stork/documentservice/tests/DatabaseTests.java265
-rw-r--r--DocumentService/src/eu/stork/documentservice/tests/DocumentServiceTests.java123
-rw-r--r--DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java63
4 files changed, 466 insertions, 0 deletions
diff --git a/DocumentService/src/eu/stork/documentservice/tests/AttrQueryRequestSdoc.xml b/DocumentService/src/eu/stork/documentservice/tests/AttrQueryRequestSdoc.xml
new file mode 100644
index 000000000..01dbf7317
--- /dev/null
+++ b/DocumentService/src/eu/stork/documentservice/tests/AttrQueryRequestSdoc.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?><saml2p:AttributeQuery xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:stork="urn:eu:stork:names:tc:STORK:1.0:assertion" xmlns:storkp="urn:eu:stork:names:tc:STORK:1.0:protocol" xmlns:xs="http://www.w3.org/2001/XMLSchema" AssertionConsumerServiceURL="http://S-PEPS.gov.xx/PEPS/ColleagueResponse" Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified" Destination="http://A-PEPS.gov.xx/PEPS/AttributeColleagueRequest" ID="_502bc4db31bb07e54a8b59c6b738dcfc" IssueInstant="2014-01-29T14:04:32.188Z" Version="2.0"><saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">http://S-PEPS.gov.xx</saml2:Issuer><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><ds:Reference URI="#_502bc4db31bb07e54a8b59c6b738dcfc"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="xs"/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>3F4d8+UWhFgV+WjA3SnBH1xp3k8=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>elOYmXMcuith/nZoqF7NNpBNt8KbUHBVleRcxgMEQwqn4fsebriUFhlbesnIWmJcSKSJetlsVNm+1ZydGjxasTAsz1Nm3K9IVm2gyhXWOqisTfSRcGavJzJuS2MpLvz+O3aa/RbNvDJvDqTD3eGhvfBB/8M/eWNhgQFI5xFFH2DcsW96YtMNafaocHt4lh35+8C4htV3bd8AAD6jzVwN1itBOKivlB048OA3BI9PXdnzLKOfBOXH3TrXpqI06BJpBITFB/teOWLys4p7YH+FejQZgo0mS8+srrRbx+eILqXy+GCujJ8eCJXo2d3JQMcMLqoHaT0Jgj18+QagVkWmiA==</ds:SignatureValue><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIIDIjCCAgqgAwIBAgIES6idsjANBgkqhkiG9w0BAQUFADBTMQswCQYDVQQGEwJFUzEOMAwGA1UE
+CAwFU3BhaW4xDzANBgNVBAcMBk1hZHJpZDEOMAwGA1UECgwFSW5kcmExEzARBgNVBAMMCmxvY2Fs
+LWRlbW8wHhcNMTMwODI4MTY0NzM1WhcNMTUwODI4MTY0NzM1WjBTMQswCQYDVQQGEwJFUzEOMAwG
+A1UECAwFU3BhaW4xDzANBgNVBAcMBk1hZHJpZDEOMAwGA1UECgwFSW5kcmExEzARBgNVBAMMCmxv
+Y2FsLWRlbW8wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCx+7zEQUbt8Ot9dByR5TuY
+NPmTwaKhECtnkxYAx9tl+Ga3kFiv+dOSeDoQOhxkICG1ZMaG0Gtk0EQWjscC1cLwDXpAOdhOm5xh
+ndFHxa3V3Y3zomFZA7A3nwP8wt17wDrc1xi2Ye8VrwO7Vjb/F8Rgutlcrvq+LF4g9nQLoRiKUq8w
+NFvDlvhBbLr8hMVBMY/jY7tSQ85qLqKUkWRcoDttJjgWZoO1vpBS4m+FywtYdOoHnN6fv4Dvf1r2
+rNLgebgBvSfwznxiulwW6FBLasYX0rYKP7RfwG8TJ+FumOgAjADj2LdwK25RZNg44XU2V1z1Fp37
+fNXhfo08LpdD1ueFAgMBAAEwDQYJKoZIhvcNAQEFBQADggEBADMRGTWOmadZyCoJNluV+M7LopjC
+9WpFUj76X0cAoNXmt12zYqYe8hjRmBr6l2V/FXT3/TyWET1nILG46zwwAxslw3b2LvkhU+9QcuB8
+yC8TCJJ0kgsTZ/EUZPSbwUG7Nn2jkMiyjlyKcjSCQOzEKQyR1xYwyZG40+BPeGbYjmRgm6kcmCxY
+USWoPwNyfke9gNT80f0pUj7wJ9YwWbTIz1rhf/h7rxoMYypXo+JXwaXW/Ra8v1uDcwfKpE5ZgwAU
+nubLXF4A+H7/N7ZvB5XDwJ4W+99nuPsKfwacD8m1sflTXcEPzzhOq6iQ9anJT94/pMctnp827zXA
+y66jvDrin5I=</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature><saml2p:Extensions><stork:QualityAuthenticationAssuranceLevel>3</stork:QualityAuthenticationAssuranceLevel><stork:spCountry>IS</stork:spCountry><storkp:eIDSectorShare>false</storkp:eIDSectorShare><storkp:eIDCrossSectorShare>false</storkp:eIDCrossSectorShare><storkp:eIDCrossBorderShare>false</storkp:eIDCrossBorderShare><storkp:RequestedAttributes><stork:RequestedAttribute Name="http://www.stork.gov.eu/1.0/docRequest" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true"><stork:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:anyType">IS/IS/fbea6e68-0393-401b-b616-f767fff9418c</stork:AttributeValue></stork:RequestedAttribute></storkp:RequestedAttributes></saml2p:Extensions><saml2:Subject><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"/></saml2:Subject></saml2p:AttributeQuery> \ No newline at end of file
diff --git a/DocumentService/src/eu/stork/documentservice/tests/DatabaseTests.java b/DocumentService/src/eu/stork/documentservice/tests/DatabaseTests.java
new file mode 100644
index 000000000..a888f0737
--- /dev/null
+++ b/DocumentService/src/eu/stork/documentservice/tests/DatabaseTests.java
@@ -0,0 +1,265 @@
+package eu.stork.documentservice.tests;
+
+import static org.junit.Assert.*;
+
+import java.util.Date;
+import java.util.UUID;
+
+import org.junit.Test;
+
+import eu.stork.documentservice.data.DatabaseConnector;
+import eu.stork.documentservice.data.DatabaseConnectorMySQLImpl;
+import eu.stork.documentservice.exceptions.DatabaseException;
+import eu.stork.documentservice.model.DocumentModel;
+import eu.stork.documentservice.model.RequestModel;
+import eu.stork.documentservice.model.TempDocumentModel;
+import eu.stork.documentservice.utils.Utils;
+
+public class DatabaseTests {
+
+ private String user = "stork";
+ private String password = "stork";
+ private String database = "stork";
+ private String server = "localhost:3306";
+ private String pdfLoc = "C:/Temp/temp.pdf";
+ private String destCountry = "AT";
+ private String spCountry = "IS";
+ private String spId = "Demo-SP";
+ private String xmlrequest = "<xml><data>foo</data>";
+ private String xmlresponse = "<xml><data>foo_signed</data>";
+ private static String docId = "";
+ private static String docId2 = "";
+ private static String reqId = "";
+
+ public DatabaseTests()
+ {
+ if (docId.isEmpty())
+ docId = UUID.randomUUID().toString();
+ if (docId2.isEmpty())
+ docId2 = UUID.randomUUID().toString();
+ if (reqId.isEmpty())
+ reqId = UUID.randomUUID().toString();
+ }
+
+ @Test
+ //Test adding document
+ public void test1() {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ DocumentModel document = new DocumentModel();
+ document.setDocid(docId);
+ document.setDocument(Utils.readData(pdfLoc));
+ document.setFilename("pdfdoc.pdf");
+ document.setMimetype("application/pdf");
+
+ try
+ {
+ boolean ok = conn.addDocument(document);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test getting document
+ public void test2()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ try
+ {
+ DocumentModel document = conn.getDocument(docId);
+ assertNotNull(document);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test updating document
+ public void test3()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ try
+ {
+ DocumentModel document = conn.getDocument(docId);
+ boolean ok = conn.updateDocument(document);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test deleting document
+ public void test4()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ try
+ {
+ boolean ok = conn.deleteDocument(docId);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test adding new request
+ public void test5()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ RequestModel request = new RequestModel();
+ request.setRequestid(reqId);
+ request.setDestcountry(destCountry);
+ request.setSpcountry(spCountry);
+ request.setSpid(spId);
+ request.setXmlrequest(xmlrequest);
+
+ try
+ {
+ boolean ok = conn.addRequest(request);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test getting request
+ public void test6()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+
+ try
+ {
+ RequestModel request = conn.getRequest(reqId);
+ assertNotNull(request);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test updating request
+ public void test7()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+
+ try
+ {
+ RequestModel request = conn.getRequest(reqId);
+ request.setDocid(docId);
+ boolean ok = conn.updateRequest(request);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test getting new request
+ public void test8()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+
+ try
+ {
+ RequestModel request = conn.getRequest(reqId);
+ request.setXmlresponse(xmlresponse);
+ request.setRestimestamp(new Date());
+ boolean ok = conn.updateRequest(request);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+
+ @Test
+ //Test add temp document
+ public void test10()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ TempDocumentModel document = new TempDocumentModel();
+ document.setDocid(docId2);
+ document.setDocument(Utils.readData(pdfLoc));
+ document.setSpid(spId);
+ //document.setFilename("pdfdoc.pdf");
+ document.setMimetype("application/pdf");
+
+ try
+ {
+ boolean ok = conn.addTempDocument(document);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test getting temp document
+ public void test11()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ try
+ {
+ TempDocumentModel document = conn.getTempDocument(docId2);
+ assertNotNull(document);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test updating temp document
+ public void test12()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ try
+ {
+ TempDocumentModel document = conn.getTempDocument(docId2);
+ boolean ok = conn.updateTempDocument(document);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test delete temp document
+ public void test13()
+ {
+ DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database);
+ try
+ {
+ boolean ok = conn.deleteTempDocument(docId2);
+ assertTrue(ok);
+ }
+ catch (DatabaseException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/DocumentService/src/eu/stork/documentservice/tests/DocumentServiceTests.java b/DocumentService/src/eu/stork/documentservice/tests/DocumentServiceTests.java
new file mode 100644
index 000000000..0d27cf044
--- /dev/null
+++ b/DocumentService/src/eu/stork/documentservice/tests/DocumentServiceTests.java
@@ -0,0 +1,123 @@
+package eu.stork.documentservice.tests;
+
+import static org.junit.Assert.*;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.junit.Test;
+
+import eu.stork.documentservice.DocumentService;
+import eu.stork.documentservice.exceptions.DocumentServiceException;
+import eu.stork.documentservice.utils.Utils;
+import eu.stork.documentservice.utils.XmlHelper;
+
+public class DocumentServiceTests {
+
+ private static String xmlrequest = "<dss:SignRequest xmlns:dss=\"urn:oasis:names:tc:dss:1.0:core:schema\" RequestID=\"_d96b62a87d18f1095180b1f44c90b5fd\"><dss:InputDocuments><dss:Document><dss:Base64Data MimeType=\"text/plain\">VGVzdCB0ZXh0</dss:Base64Data></dss:Document></dss:InputDocuments></dss:SignRequest>";
+ private static String docRequstLoc = "C:/Temp/AttrQueryRequestSdoc.xml";
+ private static String docRequstLocMod = "C:/Temp/AttrQueryRequestSdocMod.xml";
+ private static String destCountry = "AT";
+ private static String spID ="DEMO-SP";
+
+ @Test
+ public void testXmlParsing() {
+ String reqId = null;
+ try {
+ reqId = XmlHelper.getRequestId(xmlrequest);
+ } catch (DocumentServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertNotNull(reqId);
+ }
+
+ @Test
+ public void testXmlParsingDocument() {
+ String doc = null;
+ try {
+ doc = XmlHelper.getRequestDocumentData(xmlrequest);
+ } catch (DocumentServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertNotNull(doc);
+ }
+
+ @Test
+ public void testXmlParsingDocumentMime() {
+ String mime = null;
+ try {
+ mime = XmlHelper.getRequestDocumentMime(xmlrequest);
+ } catch (DocumentServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertNotNull(mime);
+ }
+
+ @Test
+ public void testCheckTransferrequest()
+ {
+ byte[] docBytes = Utils.readData(docRequstLoc);
+ try {
+ String docId = XmlHelper.verifyRequestByte(docBytes);
+ assertTrue(!docId.isEmpty());
+ } catch (DocumentServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testCheckTransferrequestMod()
+ {
+ byte[] docBytes = Utils.readData(docRequstLocMod);
+ try {
+ XmlHelper.verifyRequestByte(docBytes);
+ fail("testCheckTransferrequestMod(...) should've thrown an DocumentServiceException!");
+ } catch (DocumentServiceException e) {
+ e.printStackTrace();
+ //success("Exception thrown.");
+ }
+ }
+
+ @Test
+ public void testAddDocument()
+ {
+ URL url = null;
+ try {
+ url = new URL("http://localhost:8080/DocumentService/DocumentService?wsdl");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ QName qname = new QName("http://stork.eu",
+ "DocumentService");
+
+ Service service = Service.create(url, qname);
+ DocumentService docservice = service.getPort(DocumentService.class);
+
+ BindingProvider bp = (BindingProvider) docservice;
+ SOAPBinding binding = (SOAPBinding) bp.getBinding();
+ binding.setMTOMEnabled(true);
+
+ try
+ {
+ String doc = XmlHelper.getRequestDocumentData(xmlrequest);
+ byte[] docData = Utils.decodeBase64String(doc, false);
+ String mime = XmlHelper.getRequestDocumentMime(xmlrequest);
+ String docid = docservice.addDocument(docData, xmlrequest, destCountry, spID, mime, "");
+ assertNotNull(docid);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+}
diff --git a/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java b/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java
new file mode 100644
index 000000000..9ac0862cf
--- /dev/null
+++ b/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java
@@ -0,0 +1,63 @@
+package eu.stork.documentservice.tests;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+import eu.stork.documentservice.exceptions.EncryptionException;
+import eu.stork.documentservice.utils.EncryptionHelper;
+import eu.stork.documentservice.utils.Utils;
+
+public class EncryptionTests {
+
+ private String pdfLoc = "C:/Temp/temp.pdf";
+ private String certLocation = "C:/Temp/testcert.pem";
+ private static String encKey;
+ private static String encIv;
+
+ @Test
+ //Test encrypting some data
+ public void test1() {
+ try {
+ EncryptionHelper enc = new EncryptionHelper();
+ byte[] data = (Utils.readData(pdfLoc));
+ byte[] encdata = enc.encrypt(data);
+ assertNotNull(encdata);
+ } catch (EncryptionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test encrypting and decrypting some data
+ public void test2() {
+ try {
+ EncryptionHelper enc = new EncryptionHelper();
+ byte[] data = (Utils.readData(pdfLoc));
+ byte[] encdata = enc.encrypt(data);
+ encKey = enc.getKey();
+ encIv = enc.getIv();
+
+ EncryptionHelper enc1 = new EncryptionHelper(encKey, encIv);
+ byte[] decdata = enc1.decrypt(encdata);
+ assertTrue(Arrays.equals(data, decdata));
+ } catch (EncryptionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ //Test encrypting with a certificate
+ public void test3() {
+ try {
+ EncryptionHelper enc = new EncryptionHelper(encKey, encIv);
+ String certString = Utils.readString(certLocation);
+ String secret = enc.encryptWithCert(certString, encKey);
+ assertTrue((secret != null && !secret.isEmpty()));
+ } catch (EncryptionException e) {
+ e.printStackTrace();
+ }
+ }
+}