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,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