diff options
author | Sophia Tan <sophia_tll@hotmail.com> | 2022-12-08 19:13:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-08 21:05:23 +0000 |
commit | b0e4fcd60fe4bb089d2142f4b767d4b4ae8c0ed0 (patch) | |
tree | 1f70c7176fcbdfc4567cb15021f1fd1bf20a5fd3 /jstests/libs | |
parent | a5e5da7276551d5424f06e39be607a20301456cb (diff) | |
download | mongo-b0e4fcd60fe4bb089d2142f4b767d4b4ae8c0ed0.tar.gz |
SERVER-70543 Create override that injects the tenantId using $tenant
Diffstat (limited to 'jstests/libs')
-rw-r--r-- | jstests/libs/override_methods/inject_dollar_tenant.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/jstests/libs/override_methods/inject_dollar_tenant.js b/jstests/libs/override_methods/inject_dollar_tenant.js new file mode 100644 index 00000000000..5e253cbd4bb --- /dev/null +++ b/jstests/libs/override_methods/inject_dollar_tenant.js @@ -0,0 +1,25 @@ +/** + * Overrides the runCommand method to append $tenant on command body, so that the requests send by + * client will pass the tenant information to server. + */ +(function() { +'use strict'; + +load("jstests/libs/override_methods/override_helpers.js"); // For 'OverrideHelpers'. + +const kTenantId = ObjectId(TestData.tenant); + +// Override the runCommand to inject $tenant. +function runCommandWithDollarTenant( + conn, dbName, cmdName, cmdObj, originalRunCommand, makeRunCommandArgs) { + // inject $tenant to cmdObj. + const cmdToRun = Object.assign({}, cmdObj, {"$tenant": kTenantId}); + // Actually run the provided command. + let res = originalRunCommand.apply(conn, makeRunCommandArgs(cmdToRun)); + return res; +} + +OverrideHelpers.prependOverrideInParallelShell( + "jstests/libs/override_methods/inject_dollar_tenant.js"); +OverrideHelpers.overrideRunCommand(runCommandWithDollarTenant); +})(); |