@@ -8,99 +8,99 @@ import (
88
99func TestSanitizeError (t * testing.T ) {
1010 tests := []struct {
11- name string
12- err error
13- token string
14- owner string
15- expectedParts []string // Parts that should be in the result
11+ name string
12+ err error
13+ token string
14+ owner string
15+ expectedParts []string // Parts that should be in the result
1616 forbiddenParts []string // Parts that should NOT be in the result
1717 }{
1818 {
19- name : "nil error returns nil" ,
20- err : nil ,
21- token : "ghp_1234567890" ,
22- owner : "testuser" ,
23- expectedParts : nil ,
19+ name : "nil error returns nil" ,
20+ err : nil ,
21+ token : "ghp_1234567890" ,
22+ owner : "testuser" ,
23+ expectedParts : nil ,
2424 forbiddenParts : nil ,
2525 },
2626 {
27- name : "token is redacted" ,
28- err : errors .New ("authentication failed with token ghp_1234567890" ),
29- token : "ghp_1234567890" ,
30- owner : "testuser" ,
31- expectedParts : []string {"[***]" },
27+ name : "token is redacted" ,
28+ err : errors .New ("authentication failed with token ghp_1234567890" ),
29+ token : "ghp_1234567890" ,
30+ owner : "testuser" ,
31+ expectedParts : []string {"[***]" },
3232 forbiddenParts : []string {"ghp_1234567890" },
3333 },
3434 {
35- name : "owner/username is redacted" ,
36- err : errors .New ("failed to push to testuser/repo" ),
37- token : "ghp_1234567890" ,
38- owner : "testuser" ,
39- expectedParts : []string {"[***]" },
35+ name : "owner/username is redacted" ,
36+ err : errors .New ("failed to push to testuser/repo" ),
37+ token : "ghp_1234567890" ,
38+ owner : "testuser" ,
39+ expectedParts : []string {"[***]" },
4040 forbiddenParts : []string {"testuser" },
4141 },
4242 {
43- name : "https URL is completely redacted" ,
44- err : errors .New ("failed to clone https://github.com/user/repo.git" ),
45- token : "" ,
46- owner : "" ,
47- expectedParts : []string {"[***]" },
43+ name : "https URL is completely redacted" ,
44+ err : errors .New ("failed to clone https://github.com/user/repo.git" ),
45+ token : "" ,
46+ owner : "" ,
47+ expectedParts : []string {"[***]" },
4848 forbiddenParts : []string {"https://github.com" , "github.com" , "/user/repo.git" },
4949 },
5050 {
51- name : "http URL is completely redacted" ,
52- err : errors .New ("failed to fetch http://example.com/path/to/resource" ),
53- token : "" ,
54- owner : "" ,
55- expectedParts : []string {"[***]" },
51+ name : "http URL is completely redacted" ,
52+ err : errors .New ("failed to fetch http://example.com/path/to/resource" ),
53+ token : "" ,
54+ owner : "" ,
55+ expectedParts : []string {"[***]" },
5656 forbiddenParts : []string {"http://example.com" , "example.com" , "/path/to/resource" },
5757 },
5858 {
59- name : "multiple URLs are redacted" ,
60- err : errors .New ("failed: https://github.com/repo1 and https://github.com/repo2" ),
61- token : "" ,
62- owner : "" ,
63- expectedParts : []string {"[***]" },
59+ name : "multiple URLs are redacted" ,
60+ err : errors .New ("failed: https://github.com/repo1 and https://github.com/repo2" ),
61+ token : "" ,
62+ owner : "" ,
63+ expectedParts : []string {"[***]" },
6464 forbiddenParts : []string {"github.com" , "repo1" , "repo2" },
6565 },
6666 {
67- name : "URL with token in it is redacted" ,
68- err : errors .New ("failed to push to https://ghp_token123@github.com/user/repo.git" ),
69- token : "ghp_token123" ,
70- owner : "user" ,
71- expectedParts : []string {"[***]" },
67+ name : "URL with token in it is redacted" ,
68+ err : errors .New ("failed to push to https://ghp_token123@github.com/user/repo.git" ),
69+ token : "ghp_token123" ,
70+ owner : "user" ,
71+ expectedParts : []string {"[***]" },
7272 forbiddenParts : []string {"ghp_token123" , "github.com" , "user" , "repo.git" },
7373 },
7474 {
75- name : "complex error with token, owner, and URL" ,
76- err : errors .New ("git remote set-url failed for testuser: https://ghp_secret@github.com/testuser/myrepo.git" ),
77- token : "ghp_secret" ,
78- owner : "testuser" ,
79- expectedParts : []string {"[***]" },
75+ name : "complex error with token, owner, and URL" ,
76+ err : errors .New ("git remote set-url failed for testuser: https://ghp_secret@github.com/testuser/myrepo.git" ),
77+ token : "ghp_secret" ,
78+ owner : "testuser" ,
79+ expectedParts : []string {"[***]" },
8080 forbiddenParts : []string {"ghp_secret" , "testuser" , "github.com" , "myrepo" },
8181 },
8282 {
83- name : "error without sensitive data remains unchanged" ,
84- err : errors .New ("connection timeout" ),
85- token : "ghp_1234" ,
86- owner : "user" ,
87- expectedParts : []string {"connection timeout" },
83+ name : "error without sensitive data remains unchanged" ,
84+ err : errors .New ("connection timeout" ),
85+ token : "ghp_1234" ,
86+ owner : "user" ,
87+ expectedParts : []string {"connection timeout" },
8888 forbiddenParts : nil ,
8989 },
9090 {
91- name : "URL with query parameters is fully redacted" ,
92- err : errors .New ("failed: https://api.github.com/repos/user/repo?token=abc123" ),
93- token : "" ,
94- owner : "" ,
95- expectedParts : []string {"[***]" },
91+ name : "URL with query parameters is fully redacted" ,
92+ err : errors .New ("failed: https://api.github.com/repos/user/repo?token=abc123" ),
93+ token : "" ,
94+ owner : "" ,
95+ expectedParts : []string {"[***]" },
9696 forbiddenParts : []string {"api.github.com" , "token=abc123" , "user" , "repo" },
9797 },
9898 {
99- name : "empty token and owner still redacts URLs" ,
100- err : errors .New ("error with https://github.com/path" ),
101- token : "" ,
102- owner : "" ,
103- expectedParts : []string {"[***]" },
99+ name : "empty token and owner still redacts URLs" ,
100+ err : errors .New ("error with https://github.com/path" ),
101+ token : "" ,
102+ owner : "" ,
103+ expectedParts : []string {"[***]" },
104104 forbiddenParts : []string {"github.com" },
105105 },
106106 }
@@ -141,9 +141,6 @@ func TestSanitizeError(t *testing.T) {
141141 }
142142}
143143
144-
145-
146-
147144func TestSanitizeError_EdgeCases (t * testing.T ) {
148145 tests := []struct {
149146 name string
@@ -282,7 +279,7 @@ func TestSanitizeError_PreservesErrorStructure(t *testing.T) {
282279 }
283280
284281 // Should still be an error type
285- var err error = sanitized
282+ var err = sanitized
286283 if err == nil {
287284 t .Error ("sanitized error should still implement error interface" )
288285 }
@@ -298,7 +295,6 @@ func TestSanitizeError_PreservesErrorStructure(t *testing.T) {
298295 }
299296}
300297
301-
302298// TestSanitizeError_OrderOfOperations tests that sanitization happens in the correct order
303299func TestSanitizeError_OrderOfOperations (t * testing.T ) {
304300 // Test that token is replaced before URL regex runs
@@ -410,4 +406,3 @@ func TestSanitizeError_CaseSensitivity(t *testing.T) {
410406 t .Errorf ("expected at least one redaction, got: %s" , resultMsg )
411407 }
412408}
413-
0 commit comments