Add check for url with broken password
replace broken password in parseConfigError message
This commit is contained in:
@@ -178,6 +178,8 @@ func redactPW(connString string) string {
|
|||||||
connString = quotedDSN.ReplaceAllLiteralString(connString, "password=xxxxx")
|
connString = quotedDSN.ReplaceAllLiteralString(connString, "password=xxxxx")
|
||||||
plainDSN := regexp.MustCompile(`password=[^ ]*`)
|
plainDSN := regexp.MustCompile(`password=[^ ]*`)
|
||||||
connString = plainDSN.ReplaceAllLiteralString(connString, "password=xxxxx")
|
connString = plainDSN.ReplaceAllLiteralString(connString, "password=xxxxx")
|
||||||
|
brokenURL := regexp.MustCompile(`:\w.*@`)
|
||||||
|
connString = brokenURL.ReplaceAllLiteralString(connString, ":xxxxxx@")
|
||||||
return connString
|
return connString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,16 @@ func TestConfigError(t *testing.T) {
|
|||||||
err: pgconn.NewParseConfigError("postgresql://foo::pasword@host:1:", "msg", nil),
|
err: pgconn.NewParseConfigError("postgresql://foo::pasword@host:1:", "msg", nil),
|
||||||
expectedMsg: "cannot parse `postgresql://foo:xxxxx@host:1:`: msg",
|
expectedMsg: "cannot parse `postgresql://foo:xxxxx@host:1:`: msg",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "weird url with slash in password",
|
||||||
|
err: pgconn.NewParseConfigError("postgres://user:pass/word@host:5432/db_name", "msg", nil),
|
||||||
|
expectedMsg: "cannot parse `postgres://user:xxxxxx@host:5432/db_name`: msg",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "url without password",
|
||||||
|
err: pgconn.NewParseConfigError("postgresql://other@host/db", "msg", nil),
|
||||||
|
expectedMsg: "cannot parse `postgresql://other@host/db`: msg",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
|
|||||||
Reference in New Issue
Block a user