diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/Nachrichtenteil.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/Nachrichtenteil.kt index 9aff09ef..181f8cd8 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/Nachrichtenteil.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/Nachrichtenteil.kt @@ -8,7 +8,7 @@ abstract class Nachrichtenteil(protected val messageUtils: MessageUtils = Messag abstract fun format(): String - open fun maskMessagePart(messagePart: String, separator: String): String { + open fun maskMessagePart(messagePart: String, separators: List): String { var maskedMessagePart = messagePart val binaryDataRanges = messageUtils.findBinaryDataRanges(messagePart) @@ -20,9 +20,24 @@ abstract class Nachrichtenteil(protected val messageUtils: MessageUtils = Messag .maskCharacterAtIndices(maskedMessagePart, Separators.MaskingCharacter, unmaskedMaskingCharacterIndices) - val separatorIndices = messageUtils.findSeparatorIndices(maskedMessagePart, separator, binaryDataRanges) + separators.forEach { separator -> + maskedMessagePart = maskSeparators(maskedMessagePart, separator, binaryDataRanges) + } - return messageUtils.maskCharacterAtIndices(maskedMessagePart, separator, separatorIndices) + maskedMessagePart = maskSeparators(maskedMessagePart, Separators.DataElementGroupsSeparator, binaryDataRanges) + + return maskedMessagePart + } + + protected open fun maskSeparators(unmaskedMessagePart: String, separator: String, binaryDataRanges: List): String { + + val separatorIndices = messageUtils.findSeparatorIndices(unmaskedMessagePart, separator, binaryDataRanges) + + if (separatorIndices.isNotEmpty()) { + return messageUtils.maskCharacterAtIndices(unmaskedMessagePart, separator, separatorIndices) + } + + return unmaskedMessagePart } } \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/datenelemente/basisformate/TextDatenelement.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/datenelemente/basisformate/TextDatenelement.kt index 04ad4da0..eb6f3feb 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/datenelemente/basisformate/TextDatenelement.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/datenelemente/basisformate/TextDatenelement.kt @@ -25,7 +25,7 @@ abstract class TextDatenelement(val value: String?, existenzstatus: Existenzstat } protected open fun formatValue(value: String): String { - return maskMessagePart(value, Separators.DataElementsSeparator) // may overwritten in sub classes + return maskMessagePart(value, Separators.AllSeparators) // may overwritten in sub classes } diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/datenelemente/basisformate/TextDatenelementTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/datenelemente/basisformate/TextDatenelementTest.kt index 4bbad140..b128b09f 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/datenelemente/basisformate/TextDatenelementTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/datenelemente/basisformate/TextDatenelementTest.kt @@ -1,6 +1,8 @@ package net.dankito.fints.messages.datenelemente.basisformate import net.dankito.fints.messages.Existenzstatus +import net.dankito.fints.messages.datenelementgruppen.implementierte.signatur.SicherheitsidentifikationDetails +import org.assertj.core.api.Assertions.assertThat import org.junit.Test @@ -59,6 +61,80 @@ class TextDatenelementTest { } + @Test + fun maskDataElementsSeparator() { + + // given + val customerSystemIdWithDataElementsSeparator = "f8Clj:x3BG4BAACI/459llkXrAQA" + + val expected = "1::" + customerSystemIdWithDataElementsSeparator.replace(":", "?:") + + val underTest = SicherheitsidentifikationDetails(customerSystemIdWithDataElementsSeparator) + + // when + val result = underTest.format() + + + // then + assertThat(result).isEqualTo(expected) + } + + @Test + fun maskDataElementGroupsSeparator() { + + // given + val customerSystemIdWithDataElementGroupsSeparator = "f8Clj+x3BG4BAACI/459llkXrAQA" + + val expected = "1::" + customerSystemIdWithDataElementGroupsSeparator.replace("+", "?+") + + val underTest = SicherheitsidentifikationDetails(customerSystemIdWithDataElementGroupsSeparator) + + // when + val result = underTest.format() + + + // then + assertThat(result).isEqualTo(expected) + } + + @Test + fun maskSegmentsSeparator() { + + // given + val customerSystemIdWithSegmentsSeparator = "f8Clj\'x3BG4BAACI/459llkXrAQA" + + val expected = "1::" + customerSystemIdWithSegmentsSeparator.replace("'", "?'") + + val underTest = SicherheitsidentifikationDetails(customerSystemIdWithSegmentsSeparator) + + // when + val result = underTest.format() + + + // then + assertThat(result).isEqualTo(expected) + } + + @Test + fun maskMaskingCharacter() { + + // given + val customerSystemIdWithMaskingCharacter = "f8Clj?x3BG4BAACI/459llkXrAQA" + + val expected = "1::" + customerSystemIdWithMaskingCharacter.replace("?", "??") + + val underTest = SicherheitsidentifikationDetails(customerSystemIdWithMaskingCharacter) + + + // when + val result = underTest.format() + + + // then + assertThat(result).isEqualTo(expected) + } + + private fun createTextDatenelement(text: String): TextDatenelement { return object : TextDatenelement(text, Existenzstatus.Mandatory) { } }