Skip to content

Commit 802f5ec

Browse files
committed
OCPBUGS-57334: Redact bearertoken in TestContext
1 parent 6d8c2d0 commit 802f5ec

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pkg/cmd/openshift-tests/run-upgrade/options.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ func (o *RunUpgradeSuiteOptions) UpgradeTestPreSuite() error {
7272
if err := clusterdiscovery.InitializeTestFramework(exutil.TestContext, config, o.GinkgoRunSuiteOptions.DryRun); err != nil {
7373
return err
7474
}
75-
klog.V(4).Infof("Loaded test configuration: %#v", exutil.TestContext)
75+
// Redact the bearer token exposure
76+
testContextString := fmt.Sprintf("%#v", exutil.TestContext)
77+
redactedTestContext := exutil.RedactBearerToken(testContextString)
78+
klog.V(4).Infof("Loaded test configuration: %s", redactedTestContext)
7679

7780
return nil
7881
}

test/extended/util/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,9 +1042,11 @@ func (c *CLI) start(stdOutBuff, stdErrBuff *bytes.Buffer) (*exec.Cmd, error) {
10421042

10431043
func RedactBearerToken(args string) string {
10441044
if strings.Contains(args, "Authorization: Bearer") {
1045-
// redact bearer token
10461045
re := regexp.MustCompile(`Authorization:\s+Bearer.*\s+`)
10471046
args = re.ReplaceAllString(args, "Authorization: Bearer <redacted> ")
1047+
} else if strings.Contains(args, "BearerToken") {
1048+
re := regexp.MustCompile(`BearerToken:\s*\"[^\"]+\"`)
1049+
args = re.ReplaceAllString(args, "BearerToken: <redacted> ")
10481050
}
10491051
return args
10501052
}

0 commit comments

Comments
 (0)