gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Fetch files as streams, and fix HEV re


From: gnunet
Subject: [libeufin] branch master updated: Fetch files as streams, and fix HEV response..
Date: Wed, 29 Jan 2020 10:16:04 +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 9d4859c  Fetch files as streams, and fix HEV response..
9d4859c is described below

commit 9d4859c76ca787678f7f2388aba1e51cd47d94a0
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Jan 29 10:14:54 2020 +0100

    Fetch files as streams, and fix HEV response..
    
    .. rendering from the Nexus.
---
 nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt  |  8 ++++-
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt  | 37 +++++++++++-----------
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  |  1 +
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 10 ------
 util/src/main/kotlin/XMLUtil.kt                    |  4 +--
 util/src/test/kotlin/EbicsMessagesTest.kt          | 20 ++++++------
 6 files changed, 39 insertions(+), 41 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
index d80e06c..d3d5af9 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -55,6 +55,12 @@ data class EbicsSubscribersResponse(
     val ebicsSubscribers: MutableList<EbicsSubscriberInfoResponse> = 
mutableListOf()
 )
 
+data class ProtocolAndVersion(
+    val protocol: String,
+    val version: String,
+    val host: String
+)
+
 data class EbicsHevResponse(
-    val versions: List<String>
+    val versions: List<ProtocolAndVersion>
 )
\ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index cc4bec5..e770021 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -39,6 +39,7 @@ import io.ktor.routing.*
 import io.ktor.server.engine.embeddedServer
 import io.ktor.server.netty.Netty
 import org.jetbrains.exposed.dao.EntityID
+import org.jetbrains.exposed.exceptions.ExposedSQLException
 import org.jetbrains.exposed.sql.StdOutSqlLogger
 import org.jetbrains.exposed.sql.addLogger
 import org.jetbrains.exposed.sql.transactions.transaction
@@ -63,22 +64,24 @@ import java.util.zip.DeflaterInputStream
 import javax.crypto.EncryptedPrivateKeyInfo
 
 fun testData() {
-
     val pairA = CryptoUtil.generateRsaKeyPair(2048)
     val pairB = CryptoUtil.generateRsaKeyPair(2048)
     val pairC = CryptoUtil.generateRsaKeyPair(2048)
-
-    transaction {
-        addLogger(StdOutSqlLogger)
-        EbicsSubscriberEntity.new(id = "default-customer") {
-            ebicsURL = "http://localhost:5000/ebicsweb";
-            userID = "USER1"
-            partnerID = "PARTNER1"
-            hostID = "host01"
-            signaturePrivateKey = SerialBlob(pairA.private.encoded)
-            encryptionPrivateKey = SerialBlob(pairB.private.encoded)
-            authenticationPrivateKey = SerialBlob(pairC.private.encoded)
+    try {
+        transaction {
+            addLogger(StdOutSqlLogger)
+            EbicsSubscriberEntity.new(id = "default-customer") {
+                ebicsURL = "http://localhost:5000/ebicsweb";
+                userID = "USER1"
+                partnerID = "PARTNER1"
+                hostID = "host01"
+                signaturePrivateKey = SerialBlob(pairA.private.encoded)
+                encryptionPrivateKey = SerialBlob(pairB.private.encoded)
+                authenticationPrivateKey = SerialBlob(pairC.private.encoded)
+            }
         }
+    } catch (e: ExposedSQLException) {
+        LOGGER.info("Likely primary key collision for sample data: accepted")
     }
 }
 
@@ -100,17 +103,13 @@ fun main() {
     val client = HttpClient(){
         expectSuccess = false // this way, it does not throw exceptions on != 
200 responses.
     }
-
     val logger = LoggerFactory.getLogger("tech.libeufin.nexus")
-
     val server = embeddedServer(Netty, port = 5001) {
-
         install(CallLogging) {
             this.level = Level.DEBUG
             this.logger = LOGGER
 
         }
-
         install(ContentNegotiation) {
             moshi {
             }
@@ -119,7 +118,6 @@ fun main() {
                 setPrettyPrinting()
             }
         }
-
         install(StatusPages) {
             exception<Throwable> { cause ->
                 logger.error("Exception while handling '${call.request.uri}'", 
cause)
@@ -182,7 +180,6 @@ fun main() {
                 )
             }
         }
-
         intercept(ApplicationCallPipeline.Fallback) {
             if (this.call.response.status() == null) {
                 call.respondText("Not found (no route matched).\n", 
ContentType.Text.Plain, HttpStatusCode.NotFound)
@@ -505,9 +502,11 @@ fun main() {
                     hostId = hostID
                 }
                 val response = client.postToBankUnsigned<HEVRequest, 
HEVResponse>(ebicsUrl, request)
+                // here, response is gueranteed to be successful, no need to 
check the status code.
                 call.respond(
                     HttpStatusCode.OK,
-                    EbicsHevResponse(response.value.versionNumber as 
List<String>)
+                    EbicsHevResponse(response.value.versionNumber!!.map {
+                        ProtocolAndVersion(it.value, it.protocolVersion, 
hostID) })
                 )
                 return@get
             }
diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 6c25249..162353c 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -659,6 +659,7 @@ suspend fun ApplicationCall.ebicsweb() {
             }
 
             val strResp = XMLUtil.convertJaxbToString(hevResponse)
+            LOGGER.debug("HEV response: $strResp")
             respondText(strResp, ContentType.Application.Xml, 
HttpStatusCode.OK)
         }
         "ebicsNoPubKeyDigestsRequest" -> {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 4e68623..5736f63 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -62,9 +62,7 @@ class BadAmount(badValue: Any?) : Exception("Value 
'${badValue}' is not a valid
 class UnacceptableFractional(badNumber: BigDecimal) : Exception(
     "Unacceptable fractional part ${badNumber}"
 )
-
 val LOGGER: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
-
 fun findCustomer(id: String?): BankCustomerEntity {
 
     val idN = try {
@@ -94,7 +92,6 @@ fun findEbicsSubscriber(partnerID: String, userID: String, 
systemID: String?): E
     }.firstOrNull()
 }
 
-
 data class Subscriber(
     val partnerID: String,
     val userID: String,
@@ -108,14 +105,12 @@ data class SubscriberKeys(
     val signaturePublicKey: RSAPublicKey
 )
 
-
 data class EbicsHostPublicInfo(
     val hostID: String,
     val encryptionPublicKey: RSAPublicKey,
     val authenticationPublicKey: RSAPublicKey
 )
 
-
 inline fun <reified T> Document.toObject(): T {
     val jc = JAXBContext.newInstance(T::class.java)
     val m = jc.createUnmarshaller()
@@ -129,7 +124,6 @@ fun BigDecimal.signToString(): String {
 }
 
 fun sampleData() {
-
     transaction {
         val pairA = CryptoUtil.generateRsaKeyPair(2048)
         val pairB = CryptoUtil.generateRsaKeyPair(2048)
@@ -141,14 +135,11 @@ fun sampleData() {
             encryptionPrivateKey = SerialBlob(pairB.private.encoded)
             signaturePrivateKey = SerialBlob(pairC.private.encoded)
         }
-
         val customerEntity = BankCustomerEntity.new {
             addLogger(StdOutSqlLogger)
             customerName = "Mina"
         }
-
         LOGGER.debug("Creating customer number: ${customerEntity.id}")
-
         EbicsSubscriberEntity.new {
             partnerId = "PARTNER1"
             userId = "USER1"
@@ -158,7 +149,6 @@ fun sampleData() {
             nextOrderID = 1
             bankCustomer = customerEntity
         }
-
         for (i in listOf<Amount>(Amount("-0.44"), Amount("6.02"))) {
             BankTransactionEntity.new {
                 counterpart = "IBAN"
diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt
index af504e6..e7fef95 100644
--- a/util/src/main/kotlin/XMLUtil.kt
+++ b/util/src/main/kotlin/XMLUtil.kt
@@ -152,8 +152,8 @@ class XMLUtil private constructor() {
                 }
             }
             val schemaInputs: Array<Source> = listOf("xsd/ebics_H004.xsd", 
"xsd/ebics_hev.xsd").map {
-                val resUrl = classLoader.getResource(it) ?: throw 
FileNotFoundException("Schema file $it not found.")
-                StreamSource(File(resUrl.toURI()))
+                val stream = classLoader.getResourceAsStream(it) ?: throw 
FileNotFoundException("Schema file $it not found.")
+                StreamSource(stream)
             }.toTypedArray()
             val bundle = sf.newSchema(schemaInputs)
             val newValidator = bundle.newValidator()
diff --git a/util/src/test/kotlin/EbicsMessagesTest.kt 
b/util/src/test/kotlin/EbicsMessagesTest.kt
index a8b5ab6..e7f2cf1 100644
--- a/util/src/test/kotlin/EbicsMessagesTest.kt
+++ b/util/src/test/kotlin/EbicsMessagesTest.kt
@@ -1,3 +1,5 @@
+package tech.libeufin.sandbox
+
 import junit.framework.TestCase.assertEquals
 import org.apache.xml.security.binding.xmldsig.SignatureType
 import org.junit.Test
@@ -8,6 +10,7 @@ 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
@@ -21,8 +24,7 @@ class EbicsMessagesTest {
     @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 [...]
-        assert(ini != null)
+        val ini = classLoader.getResource("ebics_ini_inner_key.xml")
         val jaxb = 
XMLUtil.convertStringToJaxb<SignatureTypes.SignaturePubKeyOrderData>(ini.readText())
         assertEquals("A006", jaxb.value.signaturePubKeyInfo.signatureVersion)
     }
@@ -33,7 +35,7 @@ class EbicsMessagesTest {
     @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 ini = classLoader.getResource("ebics_ini_request_sample.xml")
         val jaxb = 
XMLUtil.convertStringToJaxb<EbicsUnsecuredRequest>(ini.readText())
         println("jaxb loaded")
         assertEquals(
@@ -63,7 +65,7 @@ class EbicsMessagesTest {
     @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 ini = classLoader.getResource("ebics_ini_request_sample.xml")!!
         val iniDom = XMLUtil.parseStringIntoDom(ini.readText())
         XMLUtil.convertDomToJaxb<EbicsUnsecuredRequest>(
             EbicsUnsecuredRequest::class.java,
@@ -96,14 +98,14 @@ class EbicsMessagesTest {
     @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
 [...]
+        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("<?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 hia = classLoader.getResource("hia_request.xml")!!
         val hiaDom = XMLUtil.parseStringIntoDom(hia.readText())
         val x: Element = hiaDom.getElementsByTagNameNS(
             "urn:org:ebics:H004",
@@ -127,7 +129,7 @@ class EbicsMessagesTest {
         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
 [...]
+                "ebics_ini_inner_key.xml"
             )
             assertNotNull(file)
             
XMLUtil.convertStringToJaxb<SignatureTypes.SignaturePubKeyOrderData>(file.readText())
@@ -141,7 +143,7 @@ class EbicsMessagesTest {
     @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            
[...]
+        val text = 
classLoader.getResource("ebics_ini_request_sample.xml")!!.readText()
         XMLUtil.convertStringToJaxb<EbicsUnsecuredRequest>(text)
     }
 
@@ -171,7 +173,7 @@ class EbicsMessagesTest {
     @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: [...]
+        val text = classLoader.getResource("hpb_request.xml")!!.readText()
         XMLUtil.convertStringToJaxb<EbicsNpkdRequest>(text)
     }
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]