Skip to content

Commit f047c9c

Browse files
committed
Merge branch 'beta' into master
2 parents 71b0c7d + 01d8b18 commit f047c9c

File tree

21 files changed

+2527
-2003
lines changed

21 files changed

+2527
-2003
lines changed

CHANGELOG.md

+52
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1+
## [8.8.0-beta.3](https://github.com/nodkz/mongodb-memory-server/compare/v8.8.0-beta.2...v8.8.0-beta.3) (2022-07-24)
2+
3+
4+
### Features
5+
6+
* **MongoBinaryDownloadUrl:** change to use "aarch64" by default and map to "arm64" where needed ([ddf1991](https://github.com/nodkz/mongodb-memory-server/commit/ddf19917aa07b1872db4e34fd1165d17f472905c)), closes [#678](https://github.com/nodkz/mongodb-memory-server/issues/678)
7+
* **MongoBinaryDownloadUrl::getRhelVersionString:** add support for aarch64 ([62d96e6](https://github.com/nodkz/mongodb-memory-server/commit/62d96e635bec8ced1dedde3bd65d4926c07f9a1f))
8+
9+
10+
### Dependencies
11+
12+
* **@types/jest:** upgrade to version 28.1.6 ([dff909f](https://github.com/nodkz/mongodb-memory-server/commit/dff909facf013e069861c35a105b0666c39832ac))
13+
* **@typescript-eslint/*:** upgrade to version 5.30.7 ([f73a26e](https://github.com/nodkz/mongodb-memory-server/commit/f73a26ec7adb75168a2fcf18479a97720e9eab03))
14+
* **eslint:** upgrade to version 8.20.0 ([76a4a48](https://github.com/nodkz/mongodb-memory-server/commit/76a4a48ba36c3f54302438f8043fd45a4c32919d))
15+
* **jest:** upgrade to version 28.1.3 ([2ade5c3](https://github.com/nodkz/mongodb-memory-server/commit/2ade5c31a6e323aa438b0596a7481d12f4a95d36))
16+
* **mongodb:** set version to be "~" ([8a5552a](https://github.com/nodkz/mongodb-memory-server/commit/8a5552a8db0ac33524f573176240a4b53412546e))
17+
* **ts-jest:** upgrade to version 28.0.7 ([fa9975d](https://github.com/nodkz/mongodb-memory-server/commit/fa9975d20566a704cdebc634d222de61bc475ec4))
18+
19+
## [8.8.0-beta.2](https://github.com/nodkz/mongodb-memory-server/compare/v8.8.0-beta.1...v8.8.0-beta.2) (2022-07-13)
20+
21+
22+
### Style
23+
24+
* **MongoBinaryDownloadUrl::getFedoraVersionString:** add comment about 36 ([c168c62](https://github.com/nodkz/mongodb-memory-server/commit/c168c62b0457eee48ce671a1e823dc48572e8b1c)), closes [#673](https://github.com/nodkz/mongodb-memory-server/issues/673)
25+
* **MongoBinaryDownloadUrl::getLegacyVersionString:** remove nonexistent parameter from tsdoc ([417d946](https://github.com/nodkz/mongodb-memory-server/commit/417d946bb79a9b7ecd0980e88253534b225a65db))
26+
27+
28+
### Fixes
29+
30+
* **MongoMemoryServer:** add some extra context to -86 error on macos-arm ([1f0f045](https://github.com/nodkz/mongodb-memory-server/commit/1f0f045ef89b2a94687fe10e4e7ca500f4df7426)), closes [#674](https://github.com/nodkz/mongodb-memory-server/issues/674)
31+
32+
## [8.8.0-beta.1](https://github.com/nodkz/mongodb-memory-server/compare/v8.7.2...v8.8.0-beta.1) (2022-07-05)
33+
34+
35+
### Features
36+
37+
* make use of the "localhost exception" for creating users ([b1f4dc0](https://github.com/nodkz/mongodb-memory-server/commit/b1f4dc01e007454aea5fe3c83df1f71fbaed892d)), closes [#670](https://github.com/nodkz/mongodb-memory-server/issues/670) [#671](https://github.com/nodkz/mongodb-memory-server/issues/671)
38+
39+
40+
### Style
41+
42+
* **MongoMemoryServer::AutomaticAuth:** fix typo in tsdoc ([770791b](https://github.com/nodkz/mongodb-memory-server/commit/770791b0e98b25573e0a626b1ebdab279b887d81))
43+
44+
45+
### Dependencies
46+
47+
* **@types/jest:** upgrade to version 28.1.4 ([627a3b5](https://github.com/nodkz/mongodb-memory-server/commit/627a3b5ba90cf87b5249f40e9627f2b08a637f72))
48+
* **@typescript-eslint/*:** upgrade to version 5.30.5 ([58cfeaf](https://github.com/nodkz/mongodb-memory-server/commit/58cfeafcc36e1c853e0a5dc2b87c124a56d25e27))
49+
* **eslint:** upgrade to version 8.19.0 ([574c252](https://github.com/nodkz/mongodb-memory-server/commit/574c252f804b20776337260fa5bc770c61722c7f))
50+
* **eslint-plugin-prettier:** upgrade to version 4.2.1 ([97145a8](https://github.com/nodkz/mongodb-memory-server/commit/97145a8a71c134ded6677cea5061abc534c61ae1))
51+
* **jest:** upgrade to version 28.1.2 ([c7c7303](https://github.com/nodkz/mongodb-memory-server/commit/c7c73037ddaaf619a8395de6764d2e92c73b9b02))
52+
153
## [8.7.2](https://github.com/nodkz/mongodb-memory-server/compare/v8.7.1...v8.7.2) (2022-06-29)
254

355

docs/guides/supported-systems.md

+16-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Currently Supported platforms:
1212
Officially Supported Architectures:
1313
<!--Platfrom taken from "MongoBinaryDownloadUrl.translateArch"-->
1414
- `x64` / `x86_64`
15+
- `arm64` / `aarch64` (only some linux distros have binaries)
1516
- ~~`ia32` / `i686` / `i386`~~ (There are only binaries up to ~3.2 and [will be removed with the next MMS version](https://github.com/nodkz/mongodb-memory-server/issues/638))
1617

1718
:::note
@@ -52,14 +53,13 @@ Depends on the distribution, many common ones should just work right out of the
5253
(uses mongodb's `ubuntu` release)<br/>
5354
Lowest supported Distribution version is `1404`<br/>
5455
Highest version is `2204`<br/>
55-
Default version is `1404`
56+
Default version is `1404`<br/>
57+
Architectures Supported: `x86_64`, `arm64`(`aarch64`)
58+
5659
:::note
5760
Lower Versions than `2004` may be used if mongodb dosnt provide binaries for an lower version of mongodb for an higher version of ubuntu
5861
:::
5962
:::note
60-
For Arm64 MongoDB only provides binaries for `ubuntu1604`
61-
:::
62-
:::note
6363
There are currently no native binaries for `2204`, so it is mapped to `2004` and will require `libssl1.1` to be installed.
6464
See [this mongodb issue](https://jira.mongodb.org/browse/SERVER-62300).
6565
:::
@@ -79,17 +79,27 @@ Default version is `10` (when in `unstable` or `testing`, otherwise none)
7979

8080
(uses mongodb's `rhel` release)<br/>
8181
Lowest supported Distribution version is `6`<br/>
82-
Highest version is `18`<br/>
82+
Highest version is `36` (see note)<br/>
8383
Default version is `34` (when above or equal to `34`, otherwise none)
8484

85+
:::note
86+
Fedora 36 and onwards dont ship openssl1.1 anymore by default and currently needs to be manually installed.
87+
There are currently no newer mongodb builds that support the newer provided openssl.
88+
:::
89+
8590
### Rhel
8691

8792
<span class="badge badge--warning">Untested</span> <span class="badge badge--warning">Outdated</span>
8893

8994
(uses mongodb's `rhel` release)<br/>
9095
Lowest supported Distribution version is `5`<br/>
9196
Highest version is `8`<br/>
92-
Default version is `70`
97+
Default version is `70`<br/>
98+
Architectures Supported: `x86_64`, `arm64`(`aarch64`)
99+
100+
:::note
101+
`arm64`/`aarch64` support is only for Rhel 8(.2)
102+
:::
93103

94104
### Amazon
95105

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414
"@semantic-release/github": "7.2.3",
1515
"@semantic-release/npm": "7.1.3",
1616
"@semantic-release/release-notes-generator": "9.0.3",
17-
"@types/jest": "^28.1.2",
17+
"@types/jest": "^28.1.6",
1818
"@types/node": "~14.14.45",
19-
"@typescript-eslint/eslint-plugin": "5.28.0",
20-
"@typescript-eslint/parser": "5.28.0",
19+
"@typescript-eslint/eslint-plugin": "5.30.7",
20+
"@typescript-eslint/parser": "5.30.7",
2121
"commitlint": "16.2.4",
2222
"conventional-changelog-conventionalcommits": "5.0.0",
2323
"cross-env": "7.0.3",
2424
"doctoc": "2.2.0",
25-
"eslint": "8.18.0",
25+
"eslint": "8.20.0",
2626
"eslint-config-prettier": "^8.5.0",
27-
"eslint-plugin-prettier": "4.0.0",
27+
"eslint-plugin-prettier": "4.2.1",
2828
"husky": "7.0.4",
29-
"jest": "28.1.1",
29+
"jest": "28.1.3",
3030
"lint-staged": "11.2.6",
3131
"prettier": "2.7.1",
3232
"semantic-release": "17.4.7",
33-
"ts-jest": "28.0.5",
33+
"ts-jest": "28.0.7",
3434
"typescript": "4.4.4"
3535
},
3636
"workspaces": {

packages/mongodb-memory-server-core/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb-memory-server-core",
3-
"version": "8.7.2",
3+
"version": "8.8.0-beta.3",
44
"description": "MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.",
55
"main": "lib/index",
66
"types": "lib/index.d.ts",
@@ -48,7 +48,7 @@
4848
"get-port": "^5.1.1",
4949
"https-proxy-agent": "^5.0.1",
5050
"md5-file": "^5.0.0",
51-
"mongodb": "^4.7.0",
51+
"mongodb": "~4.7.0",
5252
"new-find-package-json": "^2.0.0",
5353
"semver": "^7.3.7",
5454
"tar-stream": "^2.1.4",

packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts

+48-38
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface ReplSetOpts {
4848
* enable auth ("--auth" / "--noauth")
4949
* @default false
5050
*/
51-
auth?: boolean | AutomaticAuth;
51+
auth?: boolean | AutomaticAuth; // TODO: remove "boolean" option next major version
5252
/**
5353
* additional command line arguments passed to `mongod`
5454
* @default []
@@ -255,29 +255,58 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
255255

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

258-
if (typeof this._replSetOpts.auth === 'object') {
258+
// setting this for sanity
259+
if (typeof this._replSetOpts.auth === 'boolean') {
260+
this._replSetOpts.auth = { disable: !this._replSetOpts.auth };
261+
}
262+
263+
// do not set default when "disable" is "true" to save execution and memory
264+
if (!this._replSetOpts.auth.disable) {
259265
this._replSetOpts.auth = authDefault(this._replSetOpts.auth);
260266
}
261267
}
262268

269+
/**
270+
* Helper function to determine if "auth" should be enabled
271+
* This function expectes to be run after the auth object has been transformed to a object
272+
* @returns "true" when "auth" should be enabled
273+
*/
274+
protected enableAuth(): boolean {
275+
if (isNullOrUndefined(this._replSetOpts.auth)) {
276+
return false;
277+
}
278+
279+
assertion(typeof this._replSetOpts.auth === 'object', new AuthNotObjectError());
280+
281+
return typeof this._replSetOpts.auth.disable === 'boolean' // if "this._replSetOpts.auth.disable" is defined, use that
282+
? !this._replSetOpts.auth.disable // invert the disable boolean, because "auth" should only be disabled if "disabled = true"
283+
: true; // if "this._replSetOpts.auth.disable" is not defined, default to true because "this._replSetOpts.auth" is defined
284+
}
285+
263286
/**
264287
* Returns instance options suitable for a MongoMemoryServer.
265288
* @param baseOpts Options to merge with
289+
* @param keyfileLocation The Keyfile location if "auth" is used
266290
*/
267-
protected getInstanceOpts(baseOpts: MongoMemoryInstanceOptsBase = {}): MongoMemoryInstanceOpts {
291+
protected getInstanceOpts(
292+
baseOpts: MongoMemoryInstanceOptsBase = {},
293+
keyfileLocation?: string
294+
): MongoMemoryInstanceOpts {
295+
const enableAuth: boolean = this.enableAuth();
296+
268297
const opts: MongoMemoryInstanceOpts = {
269-
// disable "auth" if replsetopts has an object-auth
270-
auth:
271-
typeof this._replSetOpts.auth === 'object' && !this._ranCreateAuth
272-
? false
273-
: !!this._replSetOpts.auth,
298+
auth: enableAuth,
274299
args: this._replSetOpts.args,
275300
dbName: this._replSetOpts.dbName,
276301
ip: this._replSetOpts.ip,
277302
replSet: this._replSetOpts.name,
278303
storageEngine: this._replSetOpts.storageEngine,
279304
};
280305

306+
if (!isNullOrUndefined(keyfileLocation)) {
307+
opts.keyfileLocation = keyfileLocation;
308+
}
309+
281310
if (baseOpts.args) {
282311
opts.args = this._replSetOpts.args.concat(baseOpts.args);
283312
}
@@ -410,6 +439,12 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
410439
return;
411440
}
412441

442+
let keyfilePath: string | undefined = undefined;
443+
444+
if (this.enableAuth()) {
445+
keyfilePath = resolve((await this.ensureKeyFile()).name, 'keyfile');
446+
}
447+
413448
// Any servers defined within `_instanceOpts` should be started first as
414449
// the user could have specified a `dbPath` in which case we would want to perform
415450
// the `replSetInitiate` command against that server.
@@ -420,15 +455,15 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
420455
}" from instanceOpts (count: ${this.servers.length + 1}):`,
421456
opts
422457
);
423-
this.servers.push(this._initServer(this.getInstanceOpts(opts)));
458+
this.servers.push(this._initServer(this.getInstanceOpts(opts, keyfilePath)));
424459
});
425460
while (this.servers.length < this._replSetOpts.count) {
426461
log(
427462
`initAllServers: starting extra server "${this.servers.length + 1}" of "${
428463
this._replSetOpts.count
429464
}" (count: ${this.servers.length + 1})`
430465
);
431-
this.servers.push(this._initServer(this.getInstanceOpts()));
466+
this.servers.push(this._initServer(this.getInstanceOpts(undefined, keyfilePath)));
432467
}
433468

434469
log('initAllServers: waiting for all servers to finish starting');
@@ -638,15 +673,15 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
638673
const uris = this.servers.map((server) => server.getUri());
639674
const isInMemory = this.servers[0].instanceInfo?.storageEngine === 'ephemeralForTest';
640675

641-
let con: MongoClient = await MongoClient.connect(uris[0], {
676+
const con: MongoClient = await MongoClient.connect(uris[0], {
642677
// somehow since mongodb-nodejs 4.0, this option is needed when the server is set to be in a replset
643678
directConnection: true,
644679
});
645680
log('_initReplSet: connected');
646681

647682
// try-finally to close connection in any case
648683
try {
649-
let adminDb = con.db('admin');
684+
const adminDb = con.db('admin');
650685

651686
const members = uris.map((uri, index) => ({
652687
_id: index,
@@ -682,34 +717,9 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
682717
new InstanceInfoError('_initReplSet authIsObject primary')
683718
);
684719

720+
await con.close(); // just ensuring that no timeouts happen or conflicts happen
685721
await primary.createAuth(primary.instanceInfo);
686722
this._ranCreateAuth = true;
687-
688-
// TODO: maybe change the static "isInMemory" to be for each server individually, based on "storageEngine", not just the first one
689-
if (!isInMemory) {
690-
log('_initReplSet: closing connection for restart');
691-
await con.close(); // close connection in preparation for "stop"
692-
await this.stop({ doCleanup: false, force: false }); // stop all servers for enabling auth
693-
log('_initReplSet: starting all server again with auth');
694-
await this.initAllServers(); // start all servers again with "auth" enabled
695-
await this._waitForPrimary(); // wait for a primary to come around, because otherwise server selection may time out, this may take more than 30s
696-
697-
con = await MongoClient.connect(this.getUri(), {
698-
authSource: 'admin',
699-
authMechanism: 'SCRAM-SHA-256',
700-
auth: {
701-
username: this._replSetOpts.auth.customRootName as string, // cast because these are existing
702-
password: this._replSetOpts.auth.customRootPwd as string,
703-
},
704-
});
705-
adminDb = con.db('admin');
706-
log('_initReplSet: auth restart finished');
707-
} else {
708-
console.warn(
709-
'Not Restarting ReplSet for Auth\n' +
710-
'Storage engine of current PRIMARY is ephemeralForTest, which does not write data on shutdown, and mongodb does not allow changing "auth" runtime'
711-
);
712-
}
713723
}
714724
} catch (e) {
715725
if (e instanceof MongoError && e.errmsg == 'already initialized') {

0 commit comments

Comments
 (0)