Skip to content

Commit

Permalink
test: fix issues with cherry-picking #13376 to 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
IslandRhythms authored and vkarpov15 committed Feb 25, 2024
1 parent 352137b commit 5dfb62f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/helpers/processConnectionOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ function processConnectionOptions(uri, options) {
? opts.readPreference
: getUriReadPreference(uri);

const clonedOpts = clone(opts);
const resolvedOpts = (readPreference && readPreference !== 'primary' && readPreference !== 'primaryPreferred')
? resolveOptsConflicts(readPreference, opts)
: opts;
? resolveOptsConflicts(readPreference, clonedOpts)
: clonedOpts;

return clone(resolvedOpts);
return resolvedOpts;
}

function resolveOptsConflicts(pref, opts) {
Expand Down
9 changes: 9 additions & 0 deletions test/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1537,4 +1537,13 @@ describe('connections:', function() {
});
assert.deepEqual(m.connections.length, 0);
});

describe('processConnectionOptions', function() {
it('should not throw an error when attempting to mutate unmutable options object gh-13335', async function() {
const m = new mongoose.Mongoose();
const opts = Object.preventExtensions({});
const conn = await m.connect('mongodb://localhost:27017/db?retryWrites=true&w=majority&readPreference=secondaryPreferred', opts);
assert.ok(conn);
});
});
});

0 comments on commit 5dfb62f

Please sign in to comment.