commit 0b14507fe0609b0ca317318f11234d6d8c35bdc8 parent 7906ded0616aac733ab0795aa6e29e1fdf3279c2 Author: MS <ms@taler.net> Date: Thu, 11 Jun 2020 14:11:12 +0200 Tolerating "noise data" into subject lines. Diffstat:
| M | nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt | | | 10 | +++++++--- |
| M | nexus/src/test/kotlin/SubjectNormalization.kt | | | 1 | + |
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt @@ -221,10 +221,14 @@ fun paymentFailed(entry: RawBankTransactionEntity): Boolean { return false } -// Tries to extract a valid PUB from the raw subject -// line, as that was communicated by the originating bank. +// Tries to extract a valid PUB from the raw subject line fun normalizeSubject(rawSubject: String): String { - return rawSubject + val re = "\\b[a-z0-9A-Z]{52}\\b".toRegex() + val result = re.find("1ENVZ6EYGB6Z509KRJ6E59GK1EQXZF8XXNY9SN33C2KDGSHV9KA0") + if (result == null) throw NexusError( + HttpStatusCode.BadRequest, "Reserve pub not found in subject: ${rawSubject}" + ) + return result.value } fun getTalerFacadeState(fcid: String): TalerFacadeStateEntity { diff --git a/nexus/src/test/kotlin/SubjectNormalization.kt b/nexus/src/test/kotlin/SubjectNormalization.kt @@ -8,5 +8,6 @@ class SubjectNormalization { fun testBeforeAndAfter() { val mereValue = "1ENVZ6EYGB6Z509KRJ6E59GK1EQXZF8XXNY9SN33C2KDGSHV9KA0" assert(mereValue == normalizeSubject(mereValue)) + assert(mereValue == normalizeSubject("noise before ${mereValue} noise after")) } } \ No newline at end of file