[MM-18625] Make config.DatabaseStore.String() more robust (#12309)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b8f0546c19
Коммит
9a363f559e
@@ -142,6 +142,61 @@ func TestFixInvalidLocales(t *testing.T) {
|
||||
assert.Contains(t, *cfg.LocalizationSettings.AvailableLocales, *cfg.LocalizationSettings.DefaultClientLocale, "DefaultClientLocale should have been added to AvailableLocales")
|
||||
}
|
||||
|
||||
func TestStripPassword(t *testing.T) {
|
||||
for name, test := range map[string]struct {
|
||||
DSN string
|
||||
Schema string
|
||||
ExpectedOut string
|
||||
}{
|
||||
"mysql": {
|
||||
DSN: "mysql://mmuser:password@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s",
|
||||
Schema: "mysql",
|
||||
ExpectedOut: "mysql://mmuser:@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s",
|
||||
},
|
||||
"mysql idempotent": {
|
||||
DSN: "mysql://mmuser:@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s",
|
||||
Schema: "mysql",
|
||||
ExpectedOut: "mysql://mmuser:@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s",
|
||||
},
|
||||
"mysql: password with : and @": {
|
||||
DSN: "mysql://mmuser:p:assw@ord@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s",
|
||||
Schema: "mysql",
|
||||
ExpectedOut: "mysql://mmuser:@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s",
|
||||
},
|
||||
"mysql: password with @ and :": {
|
||||
DSN: "mysql://mmuser:pa@sswo:rd@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s",
|
||||
Schema: "mysql",
|
||||
ExpectedOut: "mysql://mmuser:@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s",
|
||||
},
|
||||
"postgres": {
|
||||
DSN: "postgres://mmuser:password@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",
|
||||
Schema: "postgres",
|
||||
ExpectedOut: "postgres://mmuser:@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",
|
||||
},
|
||||
"pipe": {
|
||||
DSN: "mysql://user@unix(/path/to/socket)/dbname",
|
||||
Schema: "mysql",
|
||||
ExpectedOut: "mysql://user@unix(/path/to/socket)/dbname",
|
||||
},
|
||||
"malformed without :": {
|
||||
DSN: "postgres://mmuserpassword@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",
|
||||
Schema: "postgres",
|
||||
ExpectedOut: "postgres://mmuserpassword@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",
|
||||
},
|
||||
"malformed without @": {
|
||||
DSN: "postgres://mmuser:passwordlocalhost:5432/mattermost?sslmode=disable&connect_timeout=10",
|
||||
Schema: "postgres",
|
||||
ExpectedOut: "(omitted due to error parsing the DSN)",
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
out := stripPassword(test.DSN, test.Schema)
|
||||
|
||||
assert.Equal(t, test.ExpectedOut, out)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func sToP(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user