Skip to content

Commit af4c190

Browse files
committed
Deduplicate regexes in tests
1 parent 6d2d554 commit af4c190

File tree

1 file changed

+1
-39
lines changed

1 file changed

+1
-39
lines changed

client_test.go

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,45 +1035,7 @@ func TestClient_prepareXMLForLogging_ReDoSPrevention(t *testing.T) {
10351035
func TestClient_redactSensitiveData_XPathFilters(t *testing.T) {
10361036
// Create a client with the full set of redaction patterns (matching NewClient)
10371037
client := &Client{
1038-
redactionPatterns: []*regexp.Regexp{
1039-
// Element content
1040-
regexp.MustCompile(`<password>.*?</password>`),
1041-
regexp.MustCompile(`<secret>.*?</secret>`),
1042-
regexp.MustCompile(`<key>.*?</key>`),
1043-
regexp.MustCompile(`<community>.*?</community>`),
1044-
// CDATA sections
1045-
regexp.MustCompile(`<password><!\[CDATA\[.*?\]\]></password>`),
1046-
regexp.MustCompile(`<secret><!\[CDATA\[.*?\]\]></secret>`),
1047-
regexp.MustCompile(`<key><!\[CDATA\[.*?\]\]></key>`),
1048-
regexp.MustCompile(`<community><!\[CDATA\[.*?\]\]></community>`),
1049-
// Namespace-aware elements
1050-
regexp.MustCompile(`<[a-zA-Z0-9_-]+:password[^>]*>.*?</[a-zA-Z0-9_-]+:password>`),
1051-
regexp.MustCompile(`<[a-zA-Z0-9_-]+:secret[^>]*>.*?</[a-zA-Z0-9_-]+:secret>`),
1052-
regexp.MustCompile(`<[a-zA-Z0-9_-]+:key[^>]*>.*?</[a-zA-Z0-9_-]+:key>`),
1053-
regexp.MustCompile(`<[a-zA-Z0-9_-]+:community[^>]*>.*?</[a-zA-Z0-9_-]+:community>`),
1054-
// Namespaced CDATA sections
1055-
regexp.MustCompile(`<[a-zA-Z0-9_-]+:password[^>]*><!\[CDATA\[.*?\]\]></[a-zA-Z0-9_-]+:password>`),
1056-
regexp.MustCompile(`<[a-zA-Z0-9_-]+:secret[^>]*><!\[CDATA\[.*?\]\]></[a-zA-Z0-9_-]+:secret>`),
1057-
regexp.MustCompile(`<[a-zA-Z0-9_-]+:key[^>]*><!\[CDATA\[.*?\]\]></[a-zA-Z0-9_-]+:key>`),
1058-
regexp.MustCompile(`<[a-zA-Z0-9_-]+:community[^>]*><!\[CDATA\[.*?\]\]></[a-zA-Z0-9_-]+:community>`),
1059-
// Attribute values (double quotes)
1060-
regexp.MustCompile(`password="[^"]*"`),
1061-
regexp.MustCompile(`secret="[^"]*"`),
1062-
regexp.MustCompile(`key="[^"]*"`),
1063-
regexp.MustCompile(`community="[^"]*"`),
1064-
// Attribute values (single quotes)
1065-
regexp.MustCompile(`password='[^']*'`),
1066-
regexp.MustCompile(`secret='[^']*'`),
1067-
regexp.MustCompile(`key='[^']*'`),
1068-
regexp.MustCompile(`community='[^']*'`),
1069-
// XPath predicates (within square brackets)
1070-
regexp.MustCompile(`\[password="[^"]*"\]`),
1071-
regexp.MustCompile(`\[password='[^']*'\]`),
1072-
regexp.MustCompile(`\[secret="[^"]*"\]`),
1073-
regexp.MustCompile(`\[secret='[^']*'\]`),
1074-
regexp.MustCompile(`\[key="[^"]*"\]`),
1075-
regexp.MustCompile(`\[key='[^']*'\]`),
1076-
},
1038+
redactionPatterns: defaultRedactionPatterns,
10771039
}
10781040

10791041
tests := []struct {

0 commit comments

Comments
 (0)