commit b0a2953609cb0303ea7d071296e87e6e62834112
parent 6e2bf1a4b94a2ca07429a816e4059ef538240af0
Author: MS <ms@taler.net>
Date: Tue, 26 Sep 2023 22:49:11 +0200
Testing /admin/add-incoming with deflated request.
Diffstat:
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
@@ -181,6 +181,7 @@ val corebankDecompressionPlugin = createApplicationPlugin("RequestingBodyDecompr
onCallReceive { call ->
transformBody { data ->
if (call.request.headers[HttpHeaders.ContentEncoding] == "deflate") {
+ logger.debug("Inflating request..")
val brc = try {
withContext(Dispatchers.IO) {
val inflated = InflaterInputStream(data.toInputStream())
diff --git a/bank/src/test/kotlin/Common.kt b/bank/src/test/kotlin/Common.kt
@@ -18,7 +18,8 @@
*/
import tech.libeufin.bank.*
-import tech.libeufin.util.execCommand
+import java.io.ByteArrayOutputStream
+import java.util.zip.DeflaterOutputStream
/**
* Init the database and sets the currency to KUDOS.
@@ -47,4 +48,12 @@ fun getTestContext(
suggestedWithdrawalExchange = suggestedExchange,
spaCaptchaURL = null,
)
+}
+
+fun deflater(reqBody: String): ByteArray {
+ val bos = ByteArrayOutputStream()
+ val ios = DeflaterOutputStream(bos)
+ ios.write(reqBody.toByteArray())
+ ios.finish()
+ return bos.toByteArray()
}
\ No newline at end of file
diff --git a/bank/src/test/kotlin/TalerApiTest.kt b/bank/src/test/kotlin/TalerApiTest.kt
@@ -180,12 +180,13 @@ class TalerApiTest {
expectSuccess = true
contentType(ContentType.Application.Json)
basicAuth("foo", "pw")
- setBody("""
+ headers.set("Content-Encoding", "deflate")
+ setBody(deflater("""
{"amount": "KUDOS:44",
"reserve_pub": "RESERVE-PUB-TEST",
"debit_account": "BAR-IBAN-ABC"
}
- """.trimIndent())
+ """.trimIndent()))
}
}
}