11package com.ecwid.apiclient.v3
22
3- import com.ecwid.apiclient.v3.util.SecurePattern
3+
4+ import com.ecwid.apiclient.v3.util.createSecurePatterns
45import com.ecwid.apiclient.v3.util.maskLogString
56import com.ecwid.apiclient.v3.util.maskSensitive
67import org.junit.jupiter.api.Assertions.assertEquals
@@ -11,35 +12,49 @@ 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}, " +
39+ " attributes=[AttributeValue(name={unmasked})], " +
40+ " options=[RadioOption(name={unmasked})], " +
41+ " billingPerson=BillingPerson(name={unmasked}), " +
42+ " shippingAddresses=[ShippingAddress(name={unmasked}), " +
43+ " ShippingAddress(name={unmasked})], " +
44+ " personInfo=PersonInfo(name={unmasked}))"
45+ val securePatterns = createSecurePatterns()
46+ val maskedLogString = logString.maskLogString(securePatterns)
47+ val expectedMaskedLogString =
48+ " UpdatedProduct(name={unmasked}, " +
49+ " attributes=[AttributeValue(name={unmasked})], " +
50+ " options=[RadioOption(name={unmasked})], " +
51+ " billingPerson=BillingPerson(name={u***ed}), " +
52+ " shippingAddresses=[ShippingAddress(name={u***ed}), " +
53+ " ShippingAddress(name={u***ed})], " +
54+ " personInfo=PersonInfo(name={u***ed}))"
55+ assertEquals(expectedMaskedLogString, maskedLogString)
56+ }
57+
4358 @Test
4459 fun testMaskSensitive () {
4560 assertEquals(" te***ng" , " test string" .maskSensitive(4 ))
0 commit comments