fix: IBANs im Logbuch maskieren
This commit is contained in:
55
backend/tests/historySanitization.test.ts
Normal file
55
backend/tests/historySanitization.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import test from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
|
||||
import {
|
||||
maskIban,
|
||||
sanitizeHistoryItem,
|
||||
sanitizeHistoryText,
|
||||
sanitizeHistoryValue,
|
||||
} from "../src/utils/historySanitization"
|
||||
|
||||
const IBAN = "DE89370400440532013000"
|
||||
|
||||
test("masks all but the first and last four IBAN characters", () => {
|
||||
assert.equal(maskIban(IBAN), "DE89 **** **** 3000")
|
||||
assert.equal(maskIban("DE89 3704 0044 0532 0130 00"), "DE89 **** **** 3000")
|
||||
})
|
||||
|
||||
test("masks IBAN values in nested history data", () => {
|
||||
const sanitized = sanitizeHistoryValue({
|
||||
name: "Beispielkunde",
|
||||
infoData: {
|
||||
bankingIban: IBAN,
|
||||
bankingIbans: [IBAN, "AT61 1904 3002 3457 3201"],
|
||||
},
|
||||
})
|
||||
|
||||
assert.deepEqual(sanitized, {
|
||||
name: "Beispielkunde",
|
||||
infoData: {
|
||||
bankingIban: "DE89 **** **** 3000",
|
||||
bankingIbans: ["DE89 **** **** 3000", "AT61 **** **** 3201"],
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test("masks IBANs embedded in generated history text", () => {
|
||||
const text = `Kunden: Info Daten geändert von "{\"bankingIbans\":[\"${IBAN}\"]}"`
|
||||
const sanitized = sanitizeHistoryText(text)
|
||||
|
||||
assert.equal(sanitized.includes(IBAN), false)
|
||||
assert.equal(sanitized.includes("DE89 **** **** 3000"), true)
|
||||
})
|
||||
|
||||
test("sanitizes existing history items before they are returned", () => {
|
||||
const sanitized = sanitizeHistoryItem({
|
||||
text: `IBAN: ${IBAN}.`,
|
||||
oldVal: JSON.stringify({ bankingIban: IBAN }),
|
||||
newVal: { iban: IBAN },
|
||||
config: null,
|
||||
})
|
||||
|
||||
assert.equal(sanitized.text, "IBAN: DE89 **** **** 3000.")
|
||||
assert.equal(sanitized.oldVal.includes(IBAN), false)
|
||||
assert.deepEqual(sanitized.newVal, { iban: "DE89 **** **** 3000" })
|
||||
})
|
||||
Reference in New Issue
Block a user