Skip to content

Commit 7a01ff6

Browse files
committed
ECWID-172338 Option and attribute names are masked in logs - added new test for secure pattern with name parametr, changed the previous tests using the createSecurePatterns() method, updated the expected result since the unmaskedLength was modified to the default value of 6
1 parent e2d4061 commit 7a01ff6

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/test/kotlin/com/ecwid/apiclient/v3/MaskUtilsUnitTest.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ecwid.apiclient.v3
22

3-
import com.ecwid.apiclient.v3.util.SecurePattern
3+
4+
import com.ecwid.apiclient.v3.util.createSecurePatterns
45
import com.ecwid.apiclient.v3.util.maskLogString
56
import com.ecwid.apiclient.v3.util.maskSensitive
67
import org.junit.jupiter.api.Assertions.assertEquals
@@ -11,35 +12,36 @@ class MaskUtilsUnitTest {
1112
@Test
1213
fun testMaskLogKeyValueString() {
1314
val logString =
14-
"token=secret_RandomToken0jwOrgYc5sSKBYcvO0DbP; PasswordCredentials([email protected], password=123456)"
15-
val securePatterns = listOf(
16-
SecurePattern(Regex("token=(?:secret_|public_|)([^;,)]+)"), 6),
17-
SecurePattern(Regex("email=([^;,)]+)"), 4),
18-
SecurePattern(Regex("password=([^;,)]+)"), 2),
19-
)
15+
"token=secret_RandomToken0jwOrgYc5sSKBYcvO0DbP; PasswordCredentials([email protected], password=1234567890)"
16+
val securePatterns = createSecurePatterns()
2017

2118
val maskedLogString = logString.maskLogString(securePatterns)
22-
val expectedMaskedLogString = "token=secret_Ran***DbP; PasswordCredentials(email=te***om, password=1***6)"
19+
val expectedMaskedLogString = "token=sec***DbP; PasswordCredentials(email=tes***com, password=12***890)"
2320
assertEquals(expectedMaskedLogString, maskedLogString)
2421
}
2522

2623
@Test
2724
fun testMaskLogJsonString() {
2825
val logString =
2926
"""{"billingPerson":{"email":"[email protected]","firstName":"John","lastName":"Smith","phone":"123467890"}}"""
30-
val securePatterns = listOf(
31-
SecurePattern(Regex(""""email":\s*"([^"]*)""""), 6),
32-
SecurePattern(Regex(""""firstName":\s*"([^"]*)""""), 6),
33-
SecurePattern(Regex(""""lastName":\s*"([^"]*)""""), 6),
34-
SecurePattern(Regex(""""phone":\s*"([^"]*)""""), 6),
35-
)
27+
val securePatterns = createSecurePatterns()
3628

3729
val maskedLogString = logString.maskLogString(securePatterns)
3830
val expectedMaskedLogString =
3931
"""{"billingPerson":{"email":"ale***com","firstName":"***","lastName":"***","phone":"***"}}"""
4032
assertEquals(expectedMaskedLogString, maskedLogString)
4133
}
4234

35+
@Test
36+
fun testMaskLogKeyValueStringWithNameParameter() {
37+
val logString =
38+
"UpdatedProduct(name={unmasked}, attributes=[AttributeValue(name={unmasked})], options=[RadioOption(name={unmasked})], billingPerson=BillingPerson(name={unmasked}), shippingAddresses=[ShippingAddress(name={unmasked}), ShippingAddress(name={unmasked})], personInfo=PersonInfo(name={unmasked}))"
39+
val securePatterns = createSecurePatterns()
40+
val maskedLogString = logString.maskLogString(securePatterns)
41+
val expectedMaskedLogString = "UpdatedProduct(name={unmasked}, attributes=[AttributeValue(name={unmasked})], options=[RadioOption(name={unmasked})], billingPerson=BillingPerson(name={u***ed}), shippingAddresses=[ShippingAddress(name={u***ed}), ShippingAddress(name={u***ed})], personInfo=PersonInfo(name={u***ed}))"
42+
assertEquals(expectedMaskedLogString, maskedLogString)
43+
}
44+
4345
@Test
4446
fun testMaskSensitive() {
4547
assertEquals("te***ng", "test string".maskSensitive(4))

0 commit comments

Comments
 (0)