56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
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" })
|
|
})
|