From 41c2c1097be879dd28585934f5f5e85a0676245c Mon Sep 17 00:00:00 2001 From: jsuchal Date: Mon, 21 Nov 2022 12:36:34 +0100 Subject: [PATCH 1/4] Fix signing, refs #74 --- pom.xml | 38 ++++++++++++------- .../communication/document/XMLDocument.java | 5 --- .../document/XMLDocumentTest.java | 20 ++++++++++ 3 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 src/test/java/com/octosign/whitelabel/communication/document/XMLDocumentTest.java diff --git a/pom.xml b/pom.xml index aec521f5f..21f0e7f1f 100644 --- a/pom.xml +++ b/pom.xml @@ -18,8 +18,6 @@ 2.8.9 4.5.13 2.10.377 - 10.6 - 2.12.1 com.octosign.whitelabel.ui.Main @@ -79,19 +77,27 @@ ${apache.httpcomponents.version} - net.sf.saxon - Saxon-HE - ${saxon.version} + org.junit.jupiter + junit-jupiter + 5.9.0 + test - xerces - xercesImpl - ${xerces.version} + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + org.apache.maven.plugins maven-compiler-plugin @@ -108,7 +114,7 @@ org.codehaus.mojo - versions-maven-plugin + versions-maven-plugin 2.9.0 @@ -186,7 +192,8 @@ https://cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjs.version} cmaps - ${project.resources[0].directory}/com/octosign/whitelabel/ui/vendor/pdfjs/cmaps + ${project.resources[0].directory}/com/octosign/whitelabel/ui/vendor/pdfjs/cmaps + @@ -308,13 +315,18 @@ 3.0.0 bash - ${project.build.scriptSourceDirectory}${file.separator}resources + ${project.build.scriptSourceDirectory}${file.separator}resources + ${project.build.scriptSourceDirectory}${file.separator}package.sh ${jlink.jdk.path}${file.separator}bin${file.separator}jpackage - ${project.build.directory}${file.separator}${project.artifactId}-${project.version}-${platform} + + ${project.build.directory}${file.separator}${project.artifactId}-${project.version}-${platform} + ${project.build.directory}${file.separator}preparedJDK - ${project.basedir}${file.separator}src${file.separator}main${file.separator}resources${file.separator}com${file.separator}octosign${file.separator}whitelabel + + ${project.basedir}${file.separator}src${file.separator}main${file.separator}resources${file.separator}com${file.separator}octosign${file.separator}whitelabel + ${platform} ${project.version} ${project.build.directory} diff --git a/src/main/java/com/octosign/whitelabel/communication/document/XMLDocument.java b/src/main/java/com/octosign/whitelabel/communication/document/XMLDocument.java index 8c4bd021a..a3ea1f7aa 100644 --- a/src/main/java/com/octosign/whitelabel/communication/document/XMLDocument.java +++ b/src/main/java/com/octosign/whitelabel/communication/document/XMLDocument.java @@ -25,11 +25,6 @@ public XMLDocument(Document document) { super(document); } - static { - System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); - System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); - } - public String getTransformed(String transformation) { if (isNullOrBlank(transformation)) throw new IntegrationException(Code.MISSING_INPUT, "body.parameters.transformation missing!"); diff --git a/src/test/java/com/octosign/whitelabel/communication/document/XMLDocumentTest.java b/src/test/java/com/octosign/whitelabel/communication/document/XMLDocumentTest.java new file mode 100644 index 000000000..61f3945d2 --- /dev/null +++ b/src/test/java/com/octosign/whitelabel/communication/document/XMLDocumentTest.java @@ -0,0 +1,20 @@ +package com.octosign.whitelabel.communication.document; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class XMLDocumentTest { + + @Test + void testTransformsXMLFormToXdc() { +// doc = new XMLDocument(...); +// doc.getTransformed(transformation); + assertTrue(false); + } + + @Test + void testTransformsPlainHtmlInXMLFormToXdc() { + assertTrue(false); + } +} From aa60c9c9a845a75741e35a3ed96193585523a724 Mon Sep 17 00:00:00 2001 From: jsuchal Date: Mon, 21 Nov 2022 12:36:51 +0100 Subject: [PATCH 2/4] Add preliminary support for github testing --- .github/workflows/test.yaml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 000000000..45018a061 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,36 @@ +name: Tests + +on: [push] + +jobs: + build: + runs-on: ${{ matrix.config.os }} + strategy: + matrix: + config: + - os: ubuntu-latest + - os: macos-latest + - os: windows-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'liberica' + java-package: 'jdk+fx' + + - name: Cache local Maven repository and JDK cache + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository + target/jdkCache + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Run test + run: ./mvnw test From 2748e6147a2498311488b513afe1fd4ffd30a85c Mon Sep 17 00:00:00 2001 From: jsuchal Date: Wed, 30 Nov 2022 22:53:15 +0100 Subject: [PATCH 3/4] Fix empty namespaces in datacontainer & fix signing xml with plain html elements --- pom.xml | 11 + .../preprocessing/XDCTransformer.java | 15 +- .../document/XMLDocumentTest.java | 19 +- .../whitelabel/communication/document/abc.xml | 9 + .../communication/document/abc.xslt | 223 ++++++++++++++++++ 5 files changed, 259 insertions(+), 18 deletions(-) create mode 100644 src/test/resources/com/octosign/whitelabel/communication/document/abc.xml create mode 100644 src/test/resources/com/octosign/whitelabel/communication/document/abc.xslt diff --git a/pom.xml b/pom.xml index 21f0e7f1f..7a3452f8f 100644 --- a/pom.xml +++ b/pom.xml @@ -88,9 +88,20 @@ 3.0.0-M7 maven-plugin + + net.sf.saxon + Saxon-HE + 11.4 + + + + ${project.basedir}/src/test/resources + + + org.apache.maven.plugins diff --git a/src/main/java/com/octosign/whitelabel/preprocessing/XDCTransformer.java b/src/main/java/com/octosign/whitelabel/preprocessing/XDCTransformer.java index 4129c35ad..5174f8e09 100644 --- a/src/main/java/com/octosign/whitelabel/preprocessing/XDCTransformer.java +++ b/src/main/java/com/octosign/whitelabel/preprocessing/XDCTransformer.java @@ -152,24 +152,21 @@ private String getDocumentContent() throws TransformerException { var xmlSource = new DOMSource(document); var outputTarget = new StreamResult(new StringWriter()); - var transformerFactory= TransformerFactory.newInstance(); + var transformerFactory = TransformerFactory.newInstance(); transformerFactory.newTransformer().transform(xmlSource, outputTarget); return outputTarget.getWriter().toString(); } private Element createXMLDataContainer() { - var element = document.createElement("XMLDataContainer"); + var element = document.createElementNS(containerXmlns, "XMLDataContainer"); element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - if (containerXmlns != null) - element.setAttribute("xmlns", containerXmlns); - return element; } private Element createXMLData() { - var element = document.createElement("XMLData"); + var element = document.createElementNS(containerXmlns, "XMLData"); element.setAttribute("ContentType", "application/xml; charset=UTF-8"); element.setAttribute("Identifier", identifierUri); element.setAttribute("Version", identifierVersion); @@ -178,7 +175,7 @@ private Element createXMLData() { } private Element createUsedSchemasReferenced() { - var element = document.createElement("UsedSchemasReferenced"); + var element = document.createElementNS(containerXmlns, "UsedSchemasReferenced"); if (isPresent(xsdSchema) || isPresent(xsltSchema)) { var documentXmlnsNode = document.getFirstChild().getAttributes().getNamedItem("xmlns"); if (documentXmlnsNode != null) @@ -224,7 +221,7 @@ private static String toURIString(String xmlns, String suffix) { } private Element createUsedXSDReference() { - var element = document.createElement("UsedXSDReference"); + var element = document.createElementNS(containerXmlns,"UsedXSDReference"); element.setAttribute("TransformAlgorithm", canonicalizationMethod); element.setAttribute("DigestMethod", toNamespacedString(digestAlgorithm)); element.setAttribute("DigestValue", computeDigest(xsdSchema)); @@ -234,7 +231,7 @@ private Element createUsedXSDReference() { } private Element createUsedPresentationSchemaReference() { - var element = document.createElement("UsedPresentationSchemaReference"); + var element = document.createElementNS(containerXmlns, "UsedPresentationSchemaReference"); element.setAttribute("TransformAlgorithm", canonicalizationMethod); element.setAttribute("DigestMethod", toNamespacedString(digestAlgorithm)); element.setAttribute("DigestValue", computeDigest(xsltSchema)); diff --git a/src/test/java/com/octosign/whitelabel/communication/document/XMLDocumentTest.java b/src/test/java/com/octosign/whitelabel/communication/document/XMLDocumentTest.java index 61f3945d2..bf4e102b8 100644 --- a/src/test/java/com/octosign/whitelabel/communication/document/XMLDocumentTest.java +++ b/src/test/java/com/octosign/whitelabel/communication/document/XMLDocumentTest.java @@ -1,20 +1,21 @@ package com.octosign.whitelabel.communication.document; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; +import java.io.IOException; + import static org.junit.jupiter.api.Assertions.*; class XMLDocumentTest { - @Test - void testTransformsXMLFormToXdc() { -// doc = new XMLDocument(...); -// doc.getTransformed(transformation); - assertTrue(false); - } + void testTransformsPlainHtmlWithoutAddingNamespaces() throws IOException { + var input = this.getClass().getResourceAsStream("abc.xml").readAllBytes(); + var transformation = new String(this.getClass().getResourceAsStream("abc.xslt").readAllBytes()); - @Test - void testTransformsPlainHtmlInXMLFormToXdc() { - assertTrue(false); + XMLDocument doc = new XMLDocument(new Document("id1", "test.xml", input)); + String transformed = doc.getTransformed(transformation); + + assertEquals(-1, transformed.lastIndexOf(":p>")); } } diff --git a/src/test/resources/com/octosign/whitelabel/communication/document/abc.xml b/src/test/resources/com/octosign/whitelabel/communication/document/abc.xml new file mode 100644 index 000000000..66434cb16 --- /dev/null +++ b/src/test/resources/com/octosign/whitelabel/communication/document/abc.xml @@ -0,0 +1,9 @@ + + + + +

Úrad pre dohľad nad zdravotnou starostlivosťou, právny odbor (ďalej len „úrad“), ako orgán príslušný na vydanie povolenia podľa § 18 ods. 1 písm. u) zákona č. 581/2004 Z.z. o zdravotných poisťovniach, dohľade nad zdravotnou starostlivosťou a o zmene a doplnení niektorých zákonov v znení neskorších predpisov (ďalej len „zákon č. 581/2004 Z.z.“), § 11 ods. 3 a § 21 ods. 1 zákona č. 578/2004 Z.z. o poskytovateľoch zdravotnej starostlivosti, zdravotníckych pracovníkoch, stavovských organizáciách v zdravotníctve a o zmene a doplnení niektorých zákonov v znení neskorších predpisov (ďalej len „zákon č. 578/2004 Z.z.“) a § 5 a § 6 ods. 2 zákona č. 71/1967 Zb. o správnom konaní (správny poriadok) v znení neskorších predpisov (ďalej len „Správny poriadok“) v súlade s § 46 a § 47 Správneho poriadku a § 25 ods. 1 zákona č. 578/2004 Z.z. rozhodol t a k t o:

+

Na základe žiadosti zo dňa XXXXXXX žiadateľa XXXXXXX, XXXXX, právna forma spoločnosť s ručením obmedzeným, IČO: XXXXX, zastúpenej štatutárnym orgánom XXXXXXXXXX (ďalej len „žiadateľ“) o vydanie povolenia na prevádzkovanie ambulancie záchrannej zdravotnej služby (ďalej len „ZZS“), a to ambulancie XXXXXXX v sídle stanice XXXXXX, podľa § 18 ods. 1 písm. u) zákona č. 581/2004 Z.z., § 11 ods. 3 písm. d), § 21 ods. 1 zákona č. 578/2004 Z.z. v súlade s § 12 ods. 4 a 5, § 14 ods. 11 a § 15 ods. 1 a 2 zákona č. 578/2004 Z.z.

+
+
+
\ No newline at end of file diff --git a/src/test/resources/com/octosign/whitelabel/communication/document/abc.xslt b/src/test/resources/com/octosign/whitelabel/communication/document/abc.xslt new file mode 100644 index 000000000..01afbd25e --- /dev/null +++ b/src/test/resources/com/octosign/whitelabel/communication/document/abc.xslt @@ -0,0 +1,223 @@ + + + + http://www.w3.org/1999/xhtml + + + <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + + + + + + + +
+ +
+ +
+
+
+ + +
+ + <br/> + + + + + + + + + , + + + + + + + + + <br/> + + + <br/> + + <br/> + + + + + + , + + + + + + +   + + + + + + + + + + + + +   + + + / + + + + + +   + + + + + + + + + + + + + + + + + + + + + + + pt + + + + + + + + + + + table-border + + + + + + + + + + + + + + + + + + + + . + + . + + + + { + + } + + + + + + / + + + + + + + + . + + + + januára + + + februára + + + marca + + + apríla + + + mája + + + júna + + + júla + + + augusta + + + septembra + + + októbra + + + novembra + + + decembra + + +   + + + + { + + } + + + + + + + + + +
From cdc9e75d848812dc3e83880a6dffca5f6b4e9940 Mon Sep 17 00:00:00 2001 From: jsuchal Date: Fri, 2 Dec 2022 17:35:23 +0100 Subject: [PATCH 4/4] Remove tests flow, already present in packaging --- .github/workflows/test.yaml | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 45018a061..000000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: Tests - -on: [push] - -jobs: - build: - runs-on: ${{ matrix.config.os }} - strategy: - matrix: - config: - - os: ubuntu-latest - - os: macos-latest - - os: windows-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'liberica' - java-package: 'jdk+fx' - - - name: Cache local Maven repository and JDK cache - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository - target/jdkCache - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: Run test - run: ./mvnw test