[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Moving util-relevant tests under the u
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Moving util-relevant tests under the util package. |
Date: |
Tue, 28 Jan 2020 18:13:07 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new e20a3d7 Moving util-relevant tests under the util package.
e20a3d7 is described below
commit e20a3d72b4c4c33e04dafab49892605f74292c63
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Jan 28 18:12:35 2020 +0100
Moving util-relevant tests under the util package.
---
nexus/src/test/kotlin/ImportTest.kt | 12 -
.../tech/libeufin/sandbox/EbicsProtocolBackend.kt | 10 +-
sandbox/src/test/kotlin/EbicsMessagesTest.kt | 353 ---------------------
.../HEVresponse-from-official-documentation.xml | 10 -
sandbox/src/test/resources/hev_resp3.0.xml | 10 -
sandbox/src/test/resources/hev_resp_libeufin.xml | 9 -
util/src/main/kotlin/CryptoUtil.kt | 1 -
util/src/main/kotlin/ImportTest.kt | 3 -
util/src/main/kotlin/XMLUtil.kt | 9 +
.../src/test/kotlin/CryptoUtilTest.kt | 2 -
.../src/test/kotlin/EbicsOrderUtilTest.kt | 2 -
{sandbox => util}/src/test/kotlin/LogTest.kt | 2 -
.../src/test/kotlin/SignatureDataTest.kt | 12 +-
.../src/test/kotlin/XmlCombinatorsTest.kt | 2 -
{sandbox => util}/src/test/kotlin/XmlUtilTest.kt | 7 +-
util/src/test/resources/EbicsMessagesTest.kt | 350 ++++++++++++++++++++
{sandbox => util}/src/test/resources/ebics_hev.xml | 0
.../src/test/resources/ebics_ini_inner_key.xml | 0
.../test/resources/ebics_ini_request_sample.xml | 0
.../src/test/resources/hia_request.xml | 0
.../src/test/resources/hia_request_order_data.xml | 0
.../src/test/resources/hpb_request.xml | 0
.../src/test/resources/signature1/doc.xml | 0
.../src/test/resources/signature1/public_key.txt | 0
24 files changed, 369 insertions(+), 425 deletions(-)
diff --git a/nexus/src/test/kotlin/ImportTest.kt
b/nexus/src/test/kotlin/ImportTest.kt
deleted file mode 100644
index 2f200b7..0000000
--- a/nexus/src/test/kotlin/ImportTest.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package tech.libeufin.nexus
-
-import org.junit.Test
-import tech.libeufin.util.IMPORT
-
-class ImportTest {
-
- @Test
- fun importTest() {
- println(IMPORT)
- }
-}
\ No newline at end of file
diff --git
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 4d32d56..6c25249 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -39,6 +39,7 @@ import tech.libeufin.util.CryptoUtil
import tech.libeufin.util.EbicsOrderUtil
import tech.libeufin.util.XMLUtil
import tech.libeufin.util.*
+import tech.libeufin.util.XMLUtil.Companion.signEbicsResponse
import java.awt.List
import java.math.BigDecimal
import java.security.interfaces.RSAPrivateCrtKey
@@ -628,13 +629,6 @@ fun handleEbicsHkd(): ByteArray {
}
-fun signEbicsResponseX002(ebicsResponse: EbicsResponse, privateKey:
RSAPrivateCrtKey): String {
- val doc = XMLUtil.convertJaxbToDocument(ebicsResponse)
- XMLUtil.signEbicsDocument(doc, privateKey)
- val signedDoc = XMLUtil.convertDomToString(doc)
- println("response: $signedDoc")
- return signedDoc
-}
suspend fun ApplicationCall.ebicsweb() {
val requestDocument = receiveEbicsXml()
@@ -900,7 +894,7 @@ suspend fun ApplicationCall.ebicsweb() {
EbicsResponse.createForDownloadReceiptPhase(requestTransactionID, receiptCode
== 0)
}
}
- signEbicsResponseX002(ebicsResponse, hostAuthPriv)
+ signEbicsResponse(ebicsResponse, hostAuthPriv)
}
respondText(responseXmlStr, ContentType.Application.Xml,
HttpStatusCode.OK)
}
diff --git a/sandbox/src/test/kotlin/EbicsMessagesTest.kt
b/sandbox/src/test/kotlin/EbicsMessagesTest.kt
deleted file mode 100644
index e7f2cf1..0000000
--- a/sandbox/src/test/kotlin/EbicsMessagesTest.kt
+++ /dev/null
@@ -1,353 +0,0 @@
-package tech.libeufin.sandbox
-
-import junit.framework.TestCase.assertEquals
-import org.apache.xml.security.binding.xmldsig.SignatureType
-import org.junit.Test
-import org.w3c.dom.Element
-import tech.libeufin.util.ebics_h004.*
-import tech.libeufin.util.ebics_hev.HEVResponse
-import tech.libeufin.util.ebics_hev.SystemReturnCodeType
-import tech.libeufin.util.ebics_s001.SignatureTypes
-import tech.libeufin.util.CryptoUtil
-import tech.libeufin.util.XMLUtil
-import tech.libeufin.util.ebics_h004.*
-import javax.xml.datatype.DatatypeFactory
-import kotlin.test.assertNotNull
-import kotlin.test.assertTrue
-
-class EbicsMessagesTest {
- /**
- * Tests the JAXB instantiation of non-XmlRootElement documents,
- * as notably are the inner XML strings carrying keys in INI/HIA
- * messages.
- */
- @Test
- fun testImportNonRoot() {
- val classLoader = ClassLoader.getSystemClassLoader()
- val ini = classLoader.getResource("ebics_ini_inner_key.xml")
- val jaxb =
XMLUtil.convertStringToJaxb<SignatureTypes.SignaturePubKeyOrderData>(ini.readText())
- assertEquals("A006", jaxb.value.signaturePubKeyInfo.signatureVersion)
- }
-
- /**
- * Test string -> JAXB
- */
- @Test
- fun testStringToJaxb() {
- val classLoader = ClassLoader.getSystemClassLoader()
- val ini = classLoader.getResource("ebics_ini_request_sample.xml")
- val jaxb =
XMLUtil.convertStringToJaxb<EbicsUnsecuredRequest>(ini.readText())
- println("jaxb loaded")
- assertEquals(
- "INI",
- jaxb.value.header.static.orderDetails.orderType
- )
- }
-
- /**
- * Test JAXB -> string
- */
- @Test
- fun testJaxbToString() {
- val hevResponseJaxb = HEVResponse().apply {
- this.systemReturnCode = SystemReturnCodeType().apply {
- this.reportText = "[EBICS_OK]"
- this.returnCode = "000000"
- }
- this.versionNumber =
listOf(HEVResponse.VersionNumber.create("H004", "02.50"))
- }
- XMLUtil.convertJaxbToString(hevResponseJaxb)
- }
-
- /**
- * Test DOM -> JAXB
- */
- @Test
- fun testDomToJaxb() {
- val classLoader = ClassLoader.getSystemClassLoader()
- val ini = classLoader.getResource("ebics_ini_request_sample.xml")!!
- val iniDom = XMLUtil.parseStringIntoDom(ini.readText())
- XMLUtil.convertDomToJaxb<EbicsUnsecuredRequest>(
- EbicsUnsecuredRequest::class.java,
- iniDom
- )
- }
-
- @Test
- fun testKeyMgmgResponse() {
- val responseXml = EbicsKeyManagementResponse().apply {
- header = EbicsKeyManagementResponse.Header().apply {
- mutable = EbicsKeyManagementResponse.MutableHeaderType().apply
{
- reportText = "foo"
- returnCode = "bar"
- }
- _static = EbicsKeyManagementResponse.EmptyStaticHeader()
- }
- version = "H004"
- body = EbicsKeyManagementResponse.Body().apply {
- returnCode = EbicsKeyManagementResponse.ReturnCode().apply {
- authenticate = true
- value = "000000"
- }
- }
- }
- val text = XMLUtil.convertJaxbToString(responseXml)
- assertTrue(text.isNotEmpty())
- }
-
- @Test
- fun testParseHiaRequestOrderData() {
- val classLoader = ClassLoader.getSystemClassLoader()
- val hia =
classLoader.getResource("hia_request_order_data.xml")!!.readText()
- XMLUtil.convertStringToJaxb<HIARequestOrderData>(hia)
- }
-
- @Test
- fun testHiaLoad() {
- val classLoader = ClassLoader.getSystemClassLoader()
- val hia = classLoader.getResource("hia_request.xml")!!
- val hiaDom = XMLUtil.parseStringIntoDom(hia.readText())
- val x: Element = hiaDom.getElementsByTagNameNS(
- "urn:org:ebics:H004",
- "OrderDetails"
- )?.item(0) as Element
-
- x.setAttributeNS(
- "http://www.w3.org/2001/XMLSchema-instance",
- "type",
- "UnsecuredReqOrderDetailsType"
- )
-
- XMLUtil.convertDomToJaxb<EbicsUnsecuredRequest>(
- EbicsUnsecuredRequest::class.java,
- hiaDom
- )
- }
-
- @Test
- fun testLoadInnerKey() {
- val jaxbKey = run {
- val classLoader = ClassLoader.getSystemClassLoader()
- val file = classLoader.getResource(
- "ebics_ini_inner_key.xml"
- )
- assertNotNull(file)
-
XMLUtil.convertStringToJaxb<SignatureTypes.SignaturePubKeyOrderData>(file.readText())
- }
-
- val modulus =
jaxbKey.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.modulus
- val exponent =
jaxbKey.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.exponent
- CryptoUtil.loadRsaPublicKeyFromComponents(modulus, exponent)
- }
-
- @Test
- fun testLoadIniMessage() {
- val classLoader = ClassLoader.getSystemClassLoader()
- val text =
classLoader.getResource("ebics_ini_request_sample.xml")!!.readText()
- XMLUtil.convertStringToJaxb<EbicsUnsecuredRequest>(text)
- }
-
- @Test
- fun testLoadResponse() {
- val response = EbicsResponse().apply {
- version = "H004"
- header = EbicsResponse.Header().apply {
- _static = EbicsResponse.StaticHeaderType()
- mutable = EbicsResponse.MutableHeaderType().apply {
- this.reportText = "foo"
- this.returnCode = "bar"
- this.transactionPhase =
EbicsTypes.TransactionPhaseType.INITIALISATION
- }
- }
- authSignature = SignatureType()
- body = EbicsResponse.Body().apply {
- returnCode = EbicsResponse.ReturnCode().apply {
- authenticate = true
- value = "asdf"
- }
- }
- }
- print(XMLUtil.convertJaxbToString(response))
- }
-
- @Test
- fun testLoadHpb() {
- val classLoader = ClassLoader.getSystemClassLoader()
- val text = classLoader.getResource("hpb_request.xml")!!.readText()
- XMLUtil.convertStringToJaxb<EbicsNpkdRequest>(text)
- }
-
- @Test
- fun testHtd() {
- val htd = HTDResponseOrderData().apply {
- this.partnerInfo = EbicsTypes.PartnerInfo().apply {
- this.accountInfoList = listOf(
- EbicsTypes.AccountInfo().apply {
- this.id = "acctid1"
- this.accountHolder = "Mina Musterfrau"
- this.accountNumberList = listOf(
- EbicsTypes.GeneralAccountNumber().apply {
- this.international = true
- this.value = "AT411100000237571500"
- }
- )
- this.currency = "EUR"
- this.description = "some account"
- this.bankCodeList = listOf(
- EbicsTypes.GeneralBankCode().apply {
- this.international = true
- this.value = "ABAGATWWXXX"
- }
- )
- }
- )
- this.addressInfo = EbicsTypes.AddressInfo().apply {
- this.name = "Foo"
- }
- this.bankInfo = EbicsTypes.BankInfo().apply {
- this.hostID = "MYHOST"
- }
- this.orderInfoList = listOf(
- EbicsTypes.AuthOrderInfoType().apply {
- this.description = "foo"
- this.orderType = "CCC"
- this.orderFormat = "foo"
- this.transferType = "Upload"
- }
- )
- }
- this.userInfo = EbicsTypes.UserInfo().apply {
- this.name = "Some User"
- this.userID = EbicsTypes.UserIDType().apply {
- this.status = 2
- this.value = "myuserid"
- }
- this.permissionList = listOf(
- EbicsTypes.UserPermission().apply {
- this.orderTypes = "CCC ABC"
- }
- )
- }
- }
-
- val str = XMLUtil.convertJaxbToString(htd)
- println(str)
- assert(XMLUtil.validateFromString(str))
- }
-
-
- @Test
- fun testHkd() {
- val hkd = HKDResponseOrderData().apply {
- this.partnerInfo = EbicsTypes.PartnerInfo().apply {
- this.accountInfoList = listOf(
- EbicsTypes.AccountInfo().apply {
- this.id = "acctid1"
- this.accountHolder = "Mina Musterfrau"
- this.accountNumberList = listOf(
- EbicsTypes.GeneralAccountNumber().apply {
- this.international = true
- this.value = "AT411100000237571500"
- }
- )
- this.currency = "EUR"
- this.description = "some account"
- this.bankCodeList = listOf(
- EbicsTypes.GeneralBankCode().apply {
- this.international = true
- this.value = "ABAGATWWXXX"
- }
- )
- }
- )
- this.addressInfo = EbicsTypes.AddressInfo().apply {
- this.name = "Foo"
- }
- this.bankInfo = EbicsTypes.BankInfo().apply {
- this.hostID = "MYHOST"
- }
- this.orderInfoList = listOf(
- EbicsTypes.AuthOrderInfoType().apply {
- this.description = "foo"
- this.orderType = "CCC"
- this.orderFormat = "foo"
- this.transferType = "Upload"
- }
- )
- }
- this.userInfoList = listOf(
- EbicsTypes.UserInfo().apply {
- this.name = "Some User"
- this.userID = EbicsTypes.UserIDType().apply {
- this.status = 2
- this.value = "myuserid"
- }
- this.permissionList = listOf(
- EbicsTypes.UserPermission().apply {
- this.orderTypes = "CCC ABC"
- }
- )
- })
- }
-
- val str = XMLUtil.convertJaxbToString(hkd)
- println(str)
- assert(XMLUtil.validateFromString(str))
- }
-
- @Test
- fun testEbicsRequestInitializationPhase() {
- val ebicsRequestObj = EbicsRequest().apply {
- this.version = "H004"
- this.revision = 1
- this.authSignature = SignatureType()
- this.header = EbicsRequest.Header().apply {
- this.authenticate = true
- this.mutable = EbicsRequest.MutableHeader().apply {
- this.transactionPhase =
EbicsTypes.TransactionPhaseType.INITIALISATION
- }
- this.static = EbicsRequest.StaticHeaderType().apply {
- this.hostID = "myhost"
- this.nonce = ByteArray(16)
- this.timestamp =
-
DatatypeFactory.newDefaultInstance().newXMLGregorianCalendar(2019, 5, 5, 5, 5,
5, 0, 0)
- this.partnerID = "mypid01"
- this.userID = "myusr01"
- this.product = EbicsTypes.Product().apply {
- this.instituteID = "test"
- this.language = "en"
- this.value = "test"
- }
- this.orderDetails = EbicsRequest.OrderDetails().apply {
- this.orderAttribute = "DZHNN"
- this.orderID = "OR01"
- this.orderType = "BLA"
- this.orderParams = EbicsRequest.StandardOrderParams()
- }
- this.bankPubKeyDigests =
EbicsRequest.BankPubKeyDigests().apply {
- this.authentication = EbicsTypes.PubKeyDigest().apply {
- this.algorithm = "foo"
- this.value = ByteArray(32)
- this.version = "X002"
- }
- this.encryption = EbicsTypes.PubKeyDigest().apply {
- this.algorithm = "foo"
- this.value = ByteArray(32)
- this.version = "E002"
- }
- }
- this.securityMedium = "0000"
- }
- }
- this.body = EbicsRequest.Body().apply {
- }
- }
-
- val str = XMLUtil.convertJaxbToString(ebicsRequestObj)
- val doc = XMLUtil.parseStringIntoDom(str)
- val pair = CryptoUtil.generateRsaKeyPair(1024)
- XMLUtil.signEbicsDocument(doc, pair.private)
- val finalStr = XMLUtil.convertDomToString(doc)
- assert(XMLUtil.validateFromString(finalStr))
- }
-}
\ No newline at end of file
diff --git
a/sandbox/src/test/resources/HEVresponse-from-official-documentation.xml
b/sandbox/src/test/resources/HEVresponse-from-official-documentation.xml
deleted file mode 100644
index cbe94f7..0000000
--- a/sandbox/src/test/resources/HEVresponse-from-official-documentation.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ebics:ebicsHEVResponse xsi:schemaLocation="http://www.ebics.org/H000
ebics_hev.xsd"
-xmlns:ebics="http://www.ebics.org/H000"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <ebics:SystemReturnCode>
- <ebics:ReturnCode>000000</ebics:ReturnCode>
- <ebics:ReportText>EBICS_OK</ebics:ReportText>
- </ebics:SystemReturnCode>
- <ebics:VersionNumber ProtocolVersion="H003">02.40</ebics:VersionNumber>
- <ebics:VersionNumber ProtocolVersion="H004">02.50</ebics:VersionNumber>
-</ebics:ebicsHEVResponse>
diff --git a/sandbox/src/test/resources/hev_resp3.0.xml
b/sandbox/src/test/resources/hev_resp3.0.xml
deleted file mode 100644
index 72997ae..0000000
--- a/sandbox/src/test/resources/hev_resp3.0.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ebicsHEVResponse xmlns="http://www.ebics.org/H000"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ebics.org/H000
http://www.ebics.org/H000/ebics_hev.xsd">
- <SystemReturnCode>
- <ReturnCode>000000</ReturnCode>
- <ReportText>[EBICS_OK] OK</ReportText>
- </SystemReturnCode>
- <VersionNumber ProtocolVersion="H003">02.40</VersionNumber>
- <VersionNumber ProtocolVersion="H004">02.50</VersionNumber>
- <VersionNumber ProtocolVersion="H005">03.00</VersionNumber>
-</ebicsHEVResponse>
\ No newline at end of file
diff --git a/sandbox/src/test/resources/hev_resp_libeufin.xml
b/sandbox/src/test/resources/hev_resp_libeufin.xml
deleted file mode 100644
index c9ff162..0000000
--- a/sandbox/src/test/resources/hev_resp_libeufin.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<ns2:ebicsHEVResponse xmlns:ns2="http://www.ebics.org/H000">
- <ns2:SystemReturnCode>
- <ns2:ReturnCode>000000</ns2:ReturnCode>
- <ns2:ReportText>EBICS_OK</ns2:ReportText>
- </ns2:SystemReturnCode>
- <ns2:VersionNumber ProtocolVersion="H003">02.40</ns2:VersionNumber>
- <ns2:VersionNumber ProtocolVersion="H004">02.50</ns2:VersionNumber>
-</ns2:ebicsHEVResponse>
diff --git a/util/src/main/kotlin/CryptoUtil.kt
b/util/src/main/kotlin/CryptoUtil.kt
index 0d7d86f..f15784b 100644
--- a/util/src/main/kotlin/CryptoUtil.kt
+++ b/util/src/main/kotlin/CryptoUtil.kt
@@ -237,7 +237,6 @@ object CryptoUtil {
fun decryptKey(data: EncryptedPrivateKeyInfo, passphrase: String):
RSAPrivateCrtKey {
-
/* make key out of passphrase */
val pbeKeySpec = PBEKeySpec(passphrase.toCharArray())
val keyFactory = SecretKeyFactory.getInstance(data.algName)
diff --git a/util/src/main/kotlin/ImportTest.kt
b/util/src/main/kotlin/ImportTest.kt
deleted file mode 100644
index c4f0bd6..0000000
--- a/util/src/main/kotlin/ImportTest.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package tech.libeufin.util
-
-const val IMPORT = "third party"
\ No newline at end of file
diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt
index 20e7c05..af504e6 100644
--- a/util/src/main/kotlin/XMLUtil.kt
+++ b/util/src/main/kotlin/XMLUtil.kt
@@ -30,9 +30,11 @@ import org.xml.sax.ErrorHandler
import org.xml.sax.InputSource
import org.xml.sax.SAXException
import org.xml.sax.SAXParseException
+import tech.libeufin.util.ebics_h004.EbicsResponse
import java.io.*
import java.security.PrivateKey
import java.security.PublicKey
+import java.security.interfaces.RSAPrivateCrtKey
import javax.xml.XMLConstants
import javax.xml.bind.JAXBContext
import javax.xml.bind.JAXBElement
@@ -308,6 +310,13 @@ class XMLUtil private constructor() {
return builder.parse(InputSource(xmlInputStream))
}
+ fun signEbicsResponse(ebicsResponse: EbicsResponse, privateKey:
RSAPrivateCrtKey): String {
+ val doc = convertJaxbToDocument(ebicsResponse)
+ signEbicsDocument(doc, privateKey)
+ val signedDoc = XMLUtil.convertDomToString(doc)
+ println("response: $signedDoc")
+ return signedDoc
+ }
/**
* Sign an EBICS document with the authentication and identity
signature.
diff --git a/sandbox/src/test/kotlin/CryptoUtilTest.kt
b/util/src/test/kotlin/CryptoUtilTest.kt
similarity index 99%
rename from sandbox/src/test/kotlin/CryptoUtilTest.kt
rename to util/src/test/kotlin/CryptoUtilTest.kt
index 0891c18..9422a91 100644
--- a/sandbox/src/test/kotlin/CryptoUtilTest.kt
+++ b/util/src/test/kotlin/CryptoUtilTest.kt
@@ -17,8 +17,6 @@
* <http://www.gnu.org/licenses/>
*/
-package tech.libeufin.sandbox
-
import org.junit.Test
import tech.libeufin.util.CryptoUtil
import java.security.KeyPairGenerator
diff --git a/sandbox/src/test/kotlin/EbicsOrderUtilTest.kt
b/util/src/test/kotlin/EbicsOrderUtilTest.kt
similarity index 93%
rename from sandbox/src/test/kotlin/EbicsOrderUtilTest.kt
rename to util/src/test/kotlin/EbicsOrderUtilTest.kt
index 9020ad6..2186f2f 100644
--- a/sandbox/src/test/kotlin/EbicsOrderUtilTest.kt
+++ b/util/src/test/kotlin/EbicsOrderUtilTest.kt
@@ -1,5 +1,3 @@
-package tech.libeufin.sandbox
-
import org.junit.Test
import tech.libeufin.util.EbicsOrderUtil
import kotlin.test.assertEquals
diff --git a/sandbox/src/test/kotlin/LogTest.kt
b/util/src/test/kotlin/LogTest.kt
similarity index 95%
rename from sandbox/src/test/kotlin/LogTest.kt
rename to util/src/test/kotlin/LogTest.kt
index c8a9479..fae69f8 100644
--- a/sandbox/src/test/kotlin/LogTest.kt
+++ b/util/src/test/kotlin/LogTest.kt
@@ -1,5 +1,3 @@
-package tech.libeufin.sandbox
-
import org.junit.Assert
import org.junit.Test
import org.junit.Assert.*
diff --git a/nexus/src/test/kotlin/SignatureDataTest.kt
b/util/src/test/kotlin/SignatureDataTest.kt
similarity index 94%
rename from nexus/src/test/kotlin/SignatureDataTest.kt
rename to util/src/test/kotlin/SignatureDataTest.kt
index 7a81c3f..323b6bd 100644
--- a/nexus/src/test/kotlin/SignatureDataTest.kt
+++ b/util/src/test/kotlin/SignatureDataTest.kt
@@ -1,14 +1,11 @@
-package tech.libeufin.nexus
-
-import tech.libeufin.util.XMLUtil
import org.apache.xml.security.binding.xmldsig.SignatureType
import org.junit.Test
-import tech.libeufin.nexus.getNonce
import tech.libeufin.util.CryptoUtil
+import tech.libeufin.util.XMLUtil
import tech.libeufin.util.ebics_h004.EbicsRequest
import tech.libeufin.util.ebics_h004.EbicsTypes
-import java.math.BigInteger
import tech.libeufin.util.getGregorianDate
+import java.math.BigInteger
class SignatureDataTest {
@@ -24,7 +21,7 @@ class SignatureDataTest {
authenticate = true
static = EbicsRequest.StaticHeaderType().apply {
hostID = "some host ID"
- nonce = getNonce(128)
+ nonce = "nonce".toByteArray()
timestamp = getGregorianDate()
partnerID = "some partner ID"
userID = "some user ID"
@@ -64,7 +61,8 @@ class SignatureDataTest {
encryptionPubKeyDigest =
EbicsTypes.PubKeyDigest().apply {
algorithm =
"http://www.w3.org/2001/04/xmlenc#sha256"
version = "E002"
- value =
CryptoUtil.getEbicsPublicKeyHash(pair.public)
+ value =
+
CryptoUtil.getEbicsPublicKeyHash(pair.public)
}
}
hostId = "a host ID"
diff --git a/sandbox/src/test/kotlin/XmlCombinatorsTest.kt
b/util/src/test/kotlin/XmlCombinatorsTest.kt
similarity index 98%
rename from sandbox/src/test/kotlin/XmlCombinatorsTest.kt
rename to util/src/test/kotlin/XmlCombinatorsTest.kt
index f55dc70..a5706ec 100644
--- a/sandbox/src/test/kotlin/XmlCombinatorsTest.kt
+++ b/util/src/test/kotlin/XmlCombinatorsTest.kt
@@ -17,8 +17,6 @@
* <http://www.gnu.org/licenses/>
*/
-package tech.libeufin.sandbox
-
import org.junit.Test
import tech.libeufin.util.XmlElementBuilder
import tech.libeufin.util.constructXml
diff --git a/sandbox/src/test/kotlin/XmlUtilTest.kt
b/util/src/test/kotlin/XmlUtilTest.kt
similarity index 97%
rename from sandbox/src/test/kotlin/XmlUtilTest.kt
rename to util/src/test/kotlin/XmlUtilTest.kt
index 26ec798..67c35e1 100644
--- a/sandbox/src/test/kotlin/XmlUtilTest.kt
+++ b/util/src/test/kotlin/XmlUtilTest.kt
@@ -1,9 +1,6 @@
-package tech.libeufin.sandbox
-
import org.apache.xml.security.binding.xmldsig.SignatureType
import org.junit.Test
import org.junit.Assert.*
-import org.junit.Ignore
import tech.libeufin.util.ebics_h004.EbicsKeyManagementResponse
import tech.libeufin.util.ebics_h004.EbicsResponse
import tech.libeufin.util.ebics_h004.EbicsTypes
@@ -13,6 +10,8 @@ import tech.libeufin.util.XMLUtil
import java.security.KeyPairGenerator
import java.util.*
import javax.xml.transform.stream.StreamSource
+import tech.libeufin.util.LOGGER
+import tech.libeufin.util.XMLUtil.Companion.signEbicsResponse
class XmlUtilTest {
@@ -135,7 +134,7 @@ class XmlUtilTest {
}
}
- val signature = signEbicsResponseX002(response, pair.private)
+ val signature = signEbicsResponse(response, pair.private)
val signatureJaxb =
XMLUtil.convertStringToJaxb<EbicsResponse>(signature)
assertTrue(
diff --git a/util/src/test/resources/EbicsMessagesTest.kt
b/util/src/test/resources/EbicsMessagesTest.kt
new file mode 100644
index 0000000..f748fbb
--- /dev/null
+++ b/util/src/test/resources/EbicsMessagesTest.kt
@@ -0,0 +1,350 @@
+import junit.framework.TestCase.assertEquals
+import org.apache.xml.security.binding.xmldsig.SignatureType
+import org.junit.Test
+import org.w3c.dom.Element
+import tech.libeufin.util.ebics_h004.*
+import tech.libeufin.util.ebics_hev.HEVResponse
+import tech.libeufin.util.ebics_hev.SystemReturnCodeType
+import tech.libeufin.util.ebics_s001.SignatureTypes
+import tech.libeufin.util.CryptoUtil
+import tech.libeufin.util.XMLUtil
+import javax.xml.datatype.DatatypeFactory
+import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
+
+class EbicsMessagesTest {
+ /**
+ * Tests the JAXB instantiation of non-XmlRootElement documents,
+ * as notably are the inner XML strings carrying keys in INI/HIA
+ * messages.
+ */
+ @Test
+ fun testImportNonRoot() {
+ val classLoader = ClassLoader.getSystemClassLoader()
+ val ini = classLoader.getResource("<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n<SignaturePubKeyOrderData
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.ebics.org/S001
http://www.ebics.org/S001/ebics_signature.xsd\"
xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"
xmlns=\"http://www.ebics.org/S001\">\n <SignaturePubKeyInfo>\n
<PubKeyValue>\n <ds:RSAKeyValue>\n
<ds:Modulus>s5ktpg3xGjbZZgVTYtW+0e6xsWg142UwvoM3mfuM+qrkIa5bPUGQLH [...]
+ val jaxb =
XMLUtil.convertStringToJaxb<SignatureTypes.SignaturePubKeyOrderData>(ini.readText())
+ assertEquals("A006", jaxb.value.signaturePubKeyInfo.signatureVersion)
+ }
+
+ /**
+ * Test string -> JAXB
+ */
+ @Test
+ fun testStringToJaxb() {
+ val classLoader = ClassLoader.getSystemClassLoader()
+ val ini = classLoader.getResource("<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n<ebicsUnsecuredRequest Revision=\"1\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n
xsi:schemaLocation=\"urn:org:ebics:H004 ebics_keymgmt_request_H004.xsd\"
Version=\"H004\"\n xmlns=\"urn:org:ebics:H004\">\n
<header authenticate=\"true\">\n <static>\n
<HostID>myhost</HostID>\n <PartnerID>k1</PartnerID>\n
[...]
+ val jaxb =
XMLUtil.convertStringToJaxb<EbicsUnsecuredRequest>(ini.readText())
+ println("jaxb loaded")
+ assertEquals(
+ "INI",
+ jaxb.value.header.static.orderDetails.orderType
+ )
+ }
+
+ /**
+ * Test JAXB -> string
+ */
+ @Test
+ fun testJaxbToString() {
+ val hevResponseJaxb = HEVResponse().apply {
+ this.systemReturnCode = SystemReturnCodeType().apply {
+ this.reportText = "[EBICS_OK]"
+ this.returnCode = "000000"
+ }
+ this.versionNumber =
listOf(HEVResponse.VersionNumber.create("H004", "02.50"))
+ }
+ XMLUtil.convertJaxbToString(hevResponseJaxb)
+ }
+
+ /**
+ * Test DOM -> JAXB
+ */
+ @Test
+ fun testDomToJaxb() {
+ val classLoader = ClassLoader.getSystemClassLoader()
+ val ini = classLoader.getResource("<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n<ebicsUnsecuredRequest Revision=\"1\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n
xsi:schemaLocation=\"urn:org:ebics:H004 ebics_keymgmt_request_H004.xsd\"
Version=\"H004\"\n xmlns=\"urn:org:ebics:H004\">\n
<header authenticate=\"true\">\n <static>\n
<HostID>myhost</HostID>\n <PartnerID>k1</PartnerID>\n
[...]
+ val iniDom = XMLUtil.parseStringIntoDom(ini.readText())
+ XMLUtil.convertDomToJaxb<EbicsUnsecuredRequest>(
+ EbicsUnsecuredRequest::class.java,
+ iniDom
+ )
+ }
+
+ @Test
+ fun testKeyMgmgResponse() {
+ val responseXml = EbicsKeyManagementResponse().apply {
+ header = EbicsKeyManagementResponse.Header().apply {
+ mutable = EbicsKeyManagementResponse.MutableHeaderType().apply
{
+ reportText = "foo"
+ returnCode = "bar"
+ }
+ _static = EbicsKeyManagementResponse.EmptyStaticHeader()
+ }
+ version = "H004"
+ body = EbicsKeyManagementResponse.Body().apply {
+ returnCode = EbicsKeyManagementResponse.ReturnCode().apply {
+ authenticate = true
+ value = "000000"
+ }
+ }
+ }
+ val text = XMLUtil.convertJaxbToString(responseXml)
+ assertTrue(text.isNotEmpty())
+ }
+
+ @Test
+ fun testParseHiaRequestOrderData() {
+ val classLoader = ClassLoader.getSystemClassLoader()
+ val hia = classLoader.getResource("<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n<HIARequestOrderData
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"urn:org:ebics:H004 ebics_orders_H004.xsd\"
xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" xmlns=\"urn:org:ebics:H004\">\n
<AuthenticationPubKeyInfo>\n <PubKeyValue>\n
<ds:RSAKeyValue>\n
<ds:Modulus>0Ekicvrcj2+8tsF+DZsWihl9W7AyVwtMLxq3qefSWagpfnV7BVsKYIJ/OhiWpvr3dz6K5lHS
[...]
+ XMLUtil.convertStringToJaxb<HIARequestOrderData>(hia)
+ }
+
+ @Test
+ fun testHiaLoad() {
+ val classLoader = ClassLoader.getSystemClassLoader()
+ val hia = classLoader.getResource("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n<ebicsUnsecuredRequest xmlns=\"urn:org:ebics:H004\"\n
xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"\n
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n
xsi:schemaLocation=\"urn:org:ebics:H004
ebics_keymgmt_request_H004.xsd\"\n Version=\"H004\"\n
Revision=\"1\">\n <header authenticate [...]
+ val hiaDom = XMLUtil.parseStringIntoDom(hia.readText())
+ val x: Element = hiaDom.getElementsByTagNameNS(
+ "urn:org:ebics:H004",
+ "OrderDetails"
+ )?.item(0) as Element
+
+ x.setAttributeNS(
+ "http://www.w3.org/2001/XMLSchema-instance",
+ "type",
+ "UnsecuredReqOrderDetailsType"
+ )
+
+ XMLUtil.convertDomToJaxb<EbicsUnsecuredRequest>(
+ EbicsUnsecuredRequest::class.java,
+ hiaDom
+ )
+ }
+
+ @Test
+ fun testLoadInnerKey() {
+ val jaxbKey = run {
+ val classLoader = ClassLoader.getSystemClassLoader()
+ val file = classLoader.getResource(
+ "<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n<SignaturePubKeyOrderData
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.ebics.org/S001
http://www.ebics.org/S001/ebics_signature.xsd\"
xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"
xmlns=\"http://www.ebics.org/S001\">\n <SignaturePubKeyInfo>\n
<PubKeyValue>\n <ds:RSAKeyValue>\n
<ds:Modulus>s5ktpg3xGjbZZgVTYtW+0e6xsWg142UwvoM3mfuM+qrkIa5bPUGQLH6BRL9IejYosPhoA6jwMBSxO8Lf
[...]
+ )
+ assertNotNull(file)
+
XMLUtil.convertStringToJaxb<SignatureTypes.SignaturePubKeyOrderData>(file.readText())
+ }
+
+ val modulus =
jaxbKey.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.modulus
+ val exponent =
jaxbKey.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.exponent
+ CryptoUtil.loadRsaPublicKeyFromComponents(modulus, exponent)
+ }
+
+ @Test
+ fun testLoadIniMessage() {
+ val classLoader = ClassLoader.getSystemClassLoader()
+ val text = classLoader.getResource("<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n<ebicsUnsecuredRequest Revision=\"1\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n
xsi:schemaLocation=\"urn:org:ebics:H004 ebics_keymgmt_request_H004.xsd\"
Version=\"H004\"\n xmlns=\"urn:org:ebics:H004\">\n
<header authenticate=\"true\">\n <static>\n
<HostID>myhost</HostID>\n <PartnerID>k1</PartnerID>\n
[...]
+ XMLUtil.convertStringToJaxb<EbicsUnsecuredRequest>(text)
+ }
+
+ @Test
+ fun testLoadResponse() {
+ val response = EbicsResponse().apply {
+ version = "H004"
+ header = EbicsResponse.Header().apply {
+ _static = EbicsResponse.StaticHeaderType()
+ mutable = EbicsResponse.MutableHeaderType().apply {
+ this.reportText = "foo"
+ this.returnCode = "bar"
+ this.transactionPhase =
EbicsTypes.TransactionPhaseType.INITIALISATION
+ }
+ }
+ authSignature = SignatureType()
+ body = EbicsResponse.Body().apply {
+ returnCode = EbicsResponse.ReturnCode().apply {
+ authenticate = true
+ value = "asdf"
+ }
+ }
+ }
+ print(XMLUtil.convertJaxbToString(response))
+ }
+
+ @Test
+ fun testLoadHpb() {
+ val classLoader = ClassLoader.getSystemClassLoader()
+ val text = classLoader.getResource("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n<ebics:ebicsNoPubKeyDigestsRequest
xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"
xmlns:ebics=\"urn:org:ebics:H004\" xmlns=\"http://www.w3.org/2001/XMLSchema\"
Version=\"H004\" Revision=\"1\">\n <ebics:header authenticate=\"true\">\n
<ebics:static>\n <ebics:HostID>EBIXQUAL</ebics:HostID>\n
<ebics:Nonce>0749134D19E160DA4ACA366180113D44</ebics:Nonce>\n
<ebics:Timestamp>2018-11-01T11: [...]
+ XMLUtil.convertStringToJaxb<EbicsNpkdRequest>(text)
+ }
+
+ @Test
+ fun testHtd() {
+ val htd = HTDResponseOrderData().apply {
+ this.partnerInfo = EbicsTypes.PartnerInfo().apply {
+ this.accountInfoList = listOf(
+ EbicsTypes.AccountInfo().apply {
+ this.id = "acctid1"
+ this.accountHolder = "Mina Musterfrau"
+ this.accountNumberList = listOf(
+ EbicsTypes.GeneralAccountNumber().apply {
+ this.international = true
+ this.value = "AT411100000237571500"
+ }
+ )
+ this.currency = "EUR"
+ this.description = "some account"
+ this.bankCodeList = listOf(
+ EbicsTypes.GeneralBankCode().apply {
+ this.international = true
+ this.value = "ABAGATWWXXX"
+ }
+ )
+ }
+ )
+ this.addressInfo = EbicsTypes.AddressInfo().apply {
+ this.name = "Foo"
+ }
+ this.bankInfo = EbicsTypes.BankInfo().apply {
+ this.hostID = "MYHOST"
+ }
+ this.orderInfoList = listOf(
+ EbicsTypes.AuthOrderInfoType().apply {
+ this.description = "foo"
+ this.orderType = "CCC"
+ this.orderFormat = "foo"
+ this.transferType = "Upload"
+ }
+ )
+ }
+ this.userInfo = EbicsTypes.UserInfo().apply {
+ this.name = "Some User"
+ this.userID = EbicsTypes.UserIDType().apply {
+ this.status = 2
+ this.value = "myuserid"
+ }
+ this.permissionList = listOf(
+ EbicsTypes.UserPermission().apply {
+ this.orderTypes = "CCC ABC"
+ }
+ )
+ }
+ }
+
+ val str = XMLUtil.convertJaxbToString(htd)
+ println(str)
+ assert(XMLUtil.validateFromString(str))
+ }
+
+
+ @Test
+ fun testHkd() {
+ val hkd = HKDResponseOrderData().apply {
+ this.partnerInfo = EbicsTypes.PartnerInfo().apply {
+ this.accountInfoList = listOf(
+ EbicsTypes.AccountInfo().apply {
+ this.id = "acctid1"
+ this.accountHolder = "Mina Musterfrau"
+ this.accountNumberList = listOf(
+ EbicsTypes.GeneralAccountNumber().apply {
+ this.international = true
+ this.value = "AT411100000237571500"
+ }
+ )
+ this.currency = "EUR"
+ this.description = "some account"
+ this.bankCodeList = listOf(
+ EbicsTypes.GeneralBankCode().apply {
+ this.international = true
+ this.value = "ABAGATWWXXX"
+ }
+ )
+ }
+ )
+ this.addressInfo = EbicsTypes.AddressInfo().apply {
+ this.name = "Foo"
+ }
+ this.bankInfo = EbicsTypes.BankInfo().apply {
+ this.hostID = "MYHOST"
+ }
+ this.orderInfoList = listOf(
+ EbicsTypes.AuthOrderInfoType().apply {
+ this.description = "foo"
+ this.orderType = "CCC"
+ this.orderFormat = "foo"
+ this.transferType = "Upload"
+ }
+ )
+ }
+ this.userInfoList = listOf(
+ EbicsTypes.UserInfo().apply {
+ this.name = "Some User"
+ this.userID = EbicsTypes.UserIDType().apply {
+ this.status = 2
+ this.value = "myuserid"
+ }
+ this.permissionList = listOf(
+ EbicsTypes.UserPermission().apply {
+ this.orderTypes = "CCC ABC"
+ }
+ )
+ })
+ }
+
+ val str = XMLUtil.convertJaxbToString(hkd)
+ println(str)
+ assert(XMLUtil.validateFromString(str))
+ }
+
+ @Test
+ fun testEbicsRequestInitializationPhase() {
+ val ebicsRequestObj = EbicsRequest().apply {
+ this.version = "H004"
+ this.revision = 1
+ this.authSignature = SignatureType()
+ this.header = EbicsRequest.Header().apply {
+ this.authenticate = true
+ this.mutable = EbicsRequest.MutableHeader().apply {
+ this.transactionPhase =
EbicsTypes.TransactionPhaseType.INITIALISATION
+ }
+ this.static = EbicsRequest.StaticHeaderType().apply {
+ this.hostID = "myhost"
+ this.nonce = ByteArray(16)
+ this.timestamp =
+
DatatypeFactory.newDefaultInstance().newXMLGregorianCalendar(2019, 5, 5, 5, 5,
5, 0, 0)
+ this.partnerID = "mypid01"
+ this.userID = "myusr01"
+ this.product = EbicsTypes.Product().apply {
+ this.instituteID = "test"
+ this.language = "en"
+ this.value = "test"
+ }
+ this.orderDetails = EbicsRequest.OrderDetails().apply {
+ this.orderAttribute = "DZHNN"
+ this.orderID = "OR01"
+ this.orderType = "BLA"
+ this.orderParams = EbicsRequest.StandardOrderParams()
+ }
+ this.bankPubKeyDigests =
EbicsRequest.BankPubKeyDigests().apply {
+ this.authentication = EbicsTypes.PubKeyDigest().apply {
+ this.algorithm = "foo"
+ this.value = ByteArray(32)
+ this.version = "X002"
+ }
+ this.encryption = EbicsTypes.PubKeyDigest().apply {
+ this.algorithm = "foo"
+ this.value = ByteArray(32)
+ this.version = "E002"
+ }
+ }
+ this.securityMedium = "0000"
+ }
+ }
+ this.body = EbicsRequest.Body().apply {
+ }
+ }
+
+ val str = XMLUtil.convertJaxbToString(ebicsRequestObj)
+ val doc = XMLUtil.parseStringIntoDom(str)
+ val pair = CryptoUtil.generateRsaKeyPair(1024)
+ XMLUtil.signEbicsDocument(doc, pair.private)
+ val finalStr = XMLUtil.convertDomToString(doc)
+ assert(XMLUtil.validateFromString(finalStr))
+ }
+}
\ No newline at end of file
diff --git a/sandbox/src/test/resources/ebics_hev.xml
b/util/src/test/resources/ebics_hev.xml
similarity index 100%
rename from sandbox/src/test/resources/ebics_hev.xml
rename to util/src/test/resources/ebics_hev.xml
diff --git a/sandbox/src/test/resources/ebics_ini_inner_key.xml
b/util/src/test/resources/ebics_ini_inner_key.xml
similarity index 100%
rename from sandbox/src/test/resources/ebics_ini_inner_key.xml
rename to util/src/test/resources/ebics_ini_inner_key.xml
diff --git a/sandbox/src/test/resources/ebics_ini_request_sample.xml
b/util/src/test/resources/ebics_ini_request_sample.xml
similarity index 100%
rename from sandbox/src/test/resources/ebics_ini_request_sample.xml
rename to util/src/test/resources/ebics_ini_request_sample.xml
diff --git a/sandbox/src/test/resources/hia_request.xml
b/util/src/test/resources/hia_request.xml
similarity index 100%
rename from sandbox/src/test/resources/hia_request.xml
rename to util/src/test/resources/hia_request.xml
diff --git a/sandbox/src/test/resources/hia_request_order_data.xml
b/util/src/test/resources/hia_request_order_data.xml
similarity index 100%
rename from sandbox/src/test/resources/hia_request_order_data.xml
rename to util/src/test/resources/hia_request_order_data.xml
diff --git a/sandbox/src/test/resources/hpb_request.xml
b/util/src/test/resources/hpb_request.xml
similarity index 100%
rename from sandbox/src/test/resources/hpb_request.xml
rename to util/src/test/resources/hpb_request.xml
diff --git a/sandbox/src/test/resources/signature1/doc.xml
b/util/src/test/resources/signature1/doc.xml
similarity index 100%
rename from sandbox/src/test/resources/signature1/doc.xml
rename to util/src/test/resources/signature1/doc.xml
diff --git a/sandbox/src/test/resources/signature1/public_key.txt
b/util/src/test/resources/signature1/public_key.txt
similarity index 100%
rename from sandbox/src/test/resources/signature1/public_key.txt
rename to util/src/test/resources/signature1/public_key.txt
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Moving util-relevant tests under the util package.,
gnunet <=