Skip to content

Commit

Permalink
fix(cli-repl): use JS Proxy for forwarding lazy-loaded webpack functi…
Browse files Browse the repository at this point in the history
…on 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).
  • Loading branch information
addaleax authored Mar 25, 2024
1 parent 2a9140c commit c4db376
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 13 additions & 5 deletions packages/cli-repl/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,22 @@ function makeLazyForwardModule(pkg) {
} else {
source += `module.exports = {};\n`;
}
const proxyProps = Object.getOwnPropertyNames(Reflect);
source += `const { ${proxyProps
.map((prop) => `${prop}: R_${prop}`)
.join(', ')} } = Reflect;\n`;
let i = 0;
for (const key of Object.keys(moduleContents)) {
if (typeof moduleContents[key] === 'function') {
source += `module.exports[${S(
key
)}] = function(...args) { return orig()[${S(
key
)}].apply(this, args); };\n`;
source += `module.exports[${S(key)}] = new Proxy(function() {}, {
${proxyProps
.map(
(prop) => `${prop}(_target, ...args) {
return R_${prop}(orig()[${S(key)}], ...args);
}`
)
.join(',\n')}
});\n`;
} else {
source += `let value_${i}, value_${i}_set = false;\n`;
source += `Object.defineProperty(module.exports, ${S(key)}, {
Expand Down
4 changes: 0 additions & 4 deletions packages/e2e-tests/test/e2e-oidc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ describe('OIDC auth e2e', function () {
process.platform !== 'linux' ||
!process.env.MONGOSH_SERVER_TEST_VERSION ||
!process.env.MONGOSH_SERVER_TEST_VERSION.includes('-enterprise') ||
!(
process.env.MONGOSH_SERVER_TEST_VERSION.includes('latest-alpha') ||
+process.env.MONGOSH_SERVER_TEST_VERSION.split('.')[0] >= 7
) ||
+process.version.slice(1).split('.')[0] < 16
) {
// OIDC is only supported on Linux in the 7.0+ enterprise server,
Expand Down

0 comments on commit c4db376

Please sign in to comment.