Skip to content

Commit 9507eec

Browse files
committed
improve regex to redact password, including unit tests
1 parent 7413943 commit 9507eec

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

mgradm/shared/utils/cmd_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func AddPgsqlFlags(cmd *cobra.Command) {
281281
AddContainerImageFlags(cmd, "pgsql", L("PostgreSQL Database"), "pgsql-container", "server-postgresql")
282282
}
283283

284-
// AddServerFlags add flags common to install, upgrade and migrate.
284+
// AddServerFlags add flags common to install.
285285
func AddServerFlags(cmd *cobra.Command) {
286286
AddImageFlag(cmd)
287287
AddSCCFlag(cmd)

shared/utils/logUtils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"gopkg.in/natefinch/lumberjack.v2"
2020
)
2121

22-
var redactRegex = regexp.MustCompile(`([pP]assword[\t :"\\]+)[^\t "\\]+`)
22+
var redactRegex = regexp.MustCompile(`([pP]assword[\t :"\\]+)[^\\][^\t "\\]+`)
2323

2424
// The default directory where log files are written.
2525
const logDir = "/var/log/"

shared/utils/logUtils_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 SUSE LLC
1+
// SPDX-FileCopyrightText: 2025 SUSE LLC
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

@@ -28,6 +28,14 @@ func TestRedact(t *testing.T) {
2828
`{"adminLogin":"admin","adminPassword":"secret","email":"[email protected]"}`,
2929
`{"adminLogin":"admin","adminPassword":"<REDACTED>","email":"[email protected]"}`,
3030
},
31+
{
32+
`password\n`,
33+
`password\n`,
34+
},
35+
{
36+
`\"password\": \"foo\"`,
37+
`\"password\": \"<REDACTED>\"`,
38+
},
3139
}
3240

3341
for i, testCase := range data {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- During migration, improve info about usage on ssl-password and logs(bsc#1243009)

0 commit comments

Comments
 (0)