Skip to content

Commit ec31e07

Browse files
authored
CLOUDP-320359: redact snapshot data (#3909)
1 parent 35c23ab commit ec31e07

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

test/e2e/testdata/.snapshots/TestLinkToken/Create/POST__api_atlas_v2_orgs_a0123456789abcdef012345a_liveMigrations_linkTokens_1.snaphost

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
HTTP/2.0 201 Created
2-
Content-Length: 208
2+
Content-Length: 29
33
Content-Type: application/vnd.atlas.2023-01-01+json;charset=utf-8
44
Date: Mon, 12 May 2025 05:08:20 GMT
55
Referrer-Policy: strict-origin-when-cross-origin
@@ -13,4 +13,4 @@ X-Java-Version: 17.0.14+7
1313
X-Mongodb-Service-Version: gitHash=b4fa165bfbcb725abc0816ef770e5f595c0528ce; versionString=master
1414
X-Permitted-Cross-Domain-Policies: none
1515

16-
{"linkToken":"eyJvcmdJZCI6IjVlZmRhNjgyYTNmMmVkMmU3ZGQ2Y2RlNCIsIm9yZ05hbWUiOiJBdGxhcyBDTEkgRTJFIiwicHJpdmF0ZUFwaUtleSI6ImI4Y2QxMDUzLWUxZDYtNGRlZS04MTYxLWViODMwMDA2YTA4YiIsInB1YmxpY0FwaUtleSI6InhrdnNpZ3NuIn0="}
16+
{"linkToken":"redactedToken"}

test/internal/atlas_e2e_test_generator.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"os/exec"
3434
"path"
3535
"path/filepath"
36+
"regexp"
3637
"slices"
3738
"strconv"
3839
"strings"
@@ -43,6 +44,7 @@ import (
4344
)
4445

4546
const updateSnapshotsEnvVarKey = "UPDATE_SNAPSHOTS"
47+
const redactedToken = "redactedToken"
4648

4749
type snapshotMode int
4850

@@ -524,6 +526,8 @@ func (g *AtlasE2ETestGenerator) maskString(s string) string {
524526
o = strings.ReplaceAll(o, os.Getenv("E2E_FLEX_INSTANCE_NAME"), "test-flex")
525527
o = strings.ReplaceAll(o, os.Getenv("E2E_TEST_BUCKET"), "test-bucket")
526528
o = strings.ReplaceAll(o, g.snapshotTargetURI, "http://localhost:8080/")
529+
o = replaceLinkToken(o)
530+
527531
return o
528532
}
529533

@@ -661,6 +665,17 @@ func (g *AtlasE2ETestGenerator) prepareSnapshot(r *http.Response) *http.Response
661665
return resp
662666
}
663667

668+
func replaceLinkToken(out string) string {
669+
if !strings.Contains(out, `"linkToken"`) {
670+
return out
671+
}
672+
673+
redactedObject := []byte(`{"linkToken":"` + redactedToken + `"}`)
674+
675+
jsonObjectRe := regexp.MustCompile(`\{[^{]*"linkToken"\s*:\s*"[^"]*"[^}]*\}`)
676+
return string(jsonObjectRe.ReplaceAll([]byte(out), redactedObject))
677+
}
678+
664679
func (g *AtlasE2ETestGenerator) storeSnapshot(r *http.Response) {
665680
g.t.Helper()
666681

0 commit comments

Comments
 (0)