-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from xBlaz3kx/fix/redact-password
Fix: Redact password from URL
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package connectionmanager | ||
|
||
import "testing" | ||
|
||
func Test_maskUrl(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
url string | ||
expected string | ||
}{ | ||
{ | ||
name: "No username or password", | ||
url: "amqp://localhost", | ||
expected: "amqp://localhost", | ||
}, | ||
{ | ||
name: "With username and password", | ||
url: "amqp://user:password@localhost", | ||
expected: "amqp://user:xxxxx@localhost", | ||
}, | ||
{ | ||
name: "With username and password and query params", | ||
url: "amqp://user:password@localhost?heartbeat=60", | ||
expected: "amqp://user:xxxxx@localhost?heartbeat=60", | ||
}, | ||
{ | ||
name: "Invalid URL", | ||
url: "invalidUrl", | ||
expected: "invalidUrl", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if maskPassword(tt.url) != tt.expected { | ||
t.Errorf("masked password = %v, but wanted %v", maskPassword(tt.url), tt.expected) | ||
} | ||
}) | ||
} | ||
} |