Skip to content

Commit

Permalink
feat(MongoMemoryReplSet): change "auth" to not be able to be a boolea…
Browse files Browse the repository at this point in the history
…n anymore

BREAKING CHANGE:
ReplSet option "auth" can now not be a boolean anymore, use as a object instead
  • Loading branch information
hasezoey committed Jun 9, 2023
1 parent 66a5ad3 commit 0c6b574
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
6 changes: 3 additions & 3 deletions docs/api/interfaces/replset-opts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ API Documentation of `ReplSetOpts`-Interface

### auth

Typings: `auth?: boolean | AutomaticAuth`
Default: `false`
Typings: `auth?: AutomaticAuth`
Default: `{ enable: false }`

Set wheter to enable Authentication, with configuration from [`AutomaticAuth`](./mongo-memory-server-automaticauth.md).
Set whether to enable Authentication, with configuration from [`AutomaticAuth`](./mongo-memory-server-automaticauth.md).

Also see [`MongoMemoryInstanceOpts.auth`](./mongo-memory-instance-opts.md#auth).

Expand Down
11 changes: 3 additions & 8 deletions packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ const log = debug('MongoMS:MongoMemoryReplSet');
*/
export interface ReplSetOpts {
/**
* enable auth ("--auth" / "--noauth")
* Enable Authentication
* @default false
*/
auth?: boolean | AutomaticAuth; // TODO: remove "boolean" option next major version
auth?: AutomaticAuth;
/**
* additional command line arguments passed to `mongod`
* @default []
Expand Down Expand Up @@ -240,7 +240,7 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
set replSetOpts(val: ReplSetOpts) {
assertionIsMMSRSState(MongoMemoryReplSetStates.stopped, this._state);
const defaults: Required<ReplSetOpts> = {
auth: false,
auth: { enable: false },
args: [],
name: 'testset',
count: 1,
Expand All @@ -254,11 +254,6 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced

assertion(this._replSetOpts.count > 0, new ReplsetCountLowError(this._replSetOpts.count));

// setting this for sanity
if (typeof this._replSetOpts.auth === 'boolean') {
this._replSetOpts.auth = { enable: this._replSetOpts.auth };
}

// only set default is enabled
if (this._replSetOpts.auth.enable) {
this._replSetOpts.auth = authDefault(this._replSetOpts.auth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ describe('MongoMemoryReplSet', () => {
storageEngine: 'ephemeralForTest',
configSettings: {},
});
replSet.replSetOpts = { auth: true };
replSet.replSetOpts = { auth: { enable: true } };
// @ts-expect-error because "_replSetOpts" is protected
expect(replSet.replSetOpts).toEqual(replSet._replSetOpts);
const authDefault = utils.authDefault(replSet.replSetOpts.auth as AutomaticAuth);
Expand Down

0 comments on commit 0c6b574

Please sign in to comment.