Skip to content

Commit c4db376

Browse files
authored
fix(cli-repl): use JS Proxy for forwarding lazy-loaded webpack function exports MONGOSH-1743 (#1896)
This fixes OIDC for compiled executables, because class exports like the `Issuer` class from `openid-client` or `IncomingMessage` from `http` did not fully have properties on the function and/or its prototype forwarded, effectively breaking the feature. This was not caught by our e2e tests because they were first written before the 7.x+ server was the default stable one, and therefore additional checks needed to be added to the test conditions for it. It is now safe to remove those checks, which will make the OIDC e2e tests run as part of our regular e2e test suite for compiled executables (on systems that support 7.x+ servers).
1 parent 2a9140c commit c4db376

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/cli-repl/webpack.config.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,22 @@ function makeLazyForwardModule(pkg) {
102102
} else {
103103
source += `module.exports = {};\n`;
104104
}
105+
const proxyProps = Object.getOwnPropertyNames(Reflect);
106+
source += `const { ${proxyProps
107+
.map((prop) => `${prop}: R_${prop}`)
108+
.join(', ')} } = Reflect;\n`;
105109
let i = 0;
106110
for (const key of Object.keys(moduleContents)) {
107111
if (typeof moduleContents[key] === 'function') {
108-
source += `module.exports[${S(
109-
key
110-
)}] = function(...args) { return orig()[${S(
111-
key
112-
)}].apply(this, args); };\n`;
112+
source += `module.exports[${S(key)}] = new Proxy(function() {}, {
113+
${proxyProps
114+
.map(
115+
(prop) => `${prop}(_target, ...args) {
116+
return R_${prop}(orig()[${S(key)}], ...args);
117+
}`
118+
)
119+
.join(',\n')}
120+
});\n`;
113121
} else {
114122
source += `let value_${i}, value_${i}_set = false;\n`;
115123
source += `Object.defineProperty(module.exports, ${S(key)}, {

packages/e2e-tests/test/e2e-oidc.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ describe('OIDC auth e2e', function () {
3838
process.platform !== 'linux' ||
3939
!process.env.MONGOSH_SERVER_TEST_VERSION ||
4040
!process.env.MONGOSH_SERVER_TEST_VERSION.includes('-enterprise') ||
41-
!(
42-
process.env.MONGOSH_SERVER_TEST_VERSION.includes('latest-alpha') ||
43-
+process.env.MONGOSH_SERVER_TEST_VERSION.split('.')[0] >= 7
44-
) ||
4541
+process.version.slice(1).split('.')[0] < 16
4642
) {
4743
// OIDC is only supported on Linux in the 7.0+ enterprise server,

0 commit comments

Comments
 (0)