Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Aug 22, 2022
2 parents 0be5d02 + 3f75f7b commit 5246510
Show file tree
Hide file tree
Showing 20 changed files with 946 additions and 703 deletions.
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
## [8.9.0-beta.3](https://github.com/nodkz/mongodb-memory-server/compare/v8.9.0-beta.2...v8.9.0-beta.3) (2022-08-21)


### Dependencies

* **mongodb:** upgrade to version 4.9.0 ([a0b5599](https://github.com/nodkz/mongodb-memory-server/commit/a0b5599bad49f0b1f1d554c22f2d46b4c29b1712)), closes [#676](https://github.com/nodkz/mongodb-memory-server/issues/676)

## [8.9.0-beta.2](https://github.com/nodkz/mongodb-memory-server/compare/v8.9.0-beta.1...v8.9.0-beta.2) (2022-08-17)


### Refactor

* **MongoBinaryDownloadUrl::translateArch:** combine case "arm64" & "aarch64" ([4eb48da](https://github.com/nodkz/mongodb-memory-server/commit/4eb48dae1fd94934d1c891eecdae745b0d7dd28f))

## [8.9.0-beta.1](https://github.com/nodkz/mongodb-memory-server/compare/v8.8.0...v8.9.0-beta.1) (2022-08-17)


### Features

* **errors:** add generic MMS Error ([7fc4acc](https://github.com/nodkz/mongodb-memory-server/commit/7fc4accd8bdd18f82d67a2cb321259a1bc5793c7))
* **MongoBinaryDownload::extract:** dont include ".dll" files in the filter anymore ([a7c685b](https://github.com/nodkz/mongodb-memory-server/commit/a7c685b8a91e898917386f38217f07c346b132ea))


### Style

* **MongoBinaryDownload::extractTarGz:** rename some variables to current convention ([bcb4dab](https://github.com/nodkz/mongodb-memory-server/commit/bcb4dab07b49505c63ec23c3d1f2a65ef2384ece))


### Fixes

* **MongoBinaryDownload::extractTarGz:** wrap error messages in "GenericMMSError" ([a8733dc](https://github.com/nodkz/mongodb-memory-server/commit/a8733dc4d5f14b5f71e086b2c93bf1423e548be2))
* **MongoMemoryReplSet::_initReplSet:** use "extraConnectionOptions" when "_ranCreateAuth" is "true" ([e116128](https://github.com/nodkz/mongodb-memory-server/commit/e1161284addab03b41b51be8c2dfb7617b5bae19))
* **MongoMemoryReplSet::cleanup:** reset "_ranCreateAuth" on cleanup ([2fc87e7](https://github.com/nodkz/mongodb-memory-server/commit/2fc87e77183418b6ed21902afdb35d5b806a9215))


### Dependencies

* **@types/jest:** upgrade to version 28.1.7 ([db3e729](https://github.com/nodkz/mongodb-memory-server/commit/db3e72936e5696570a12dc706cebaa5bf307e3ac))
* **@types/semver:** upgrade to version 7.3.12 ([8c61c71](https://github.com/nodkz/mongodb-memory-server/commit/8c61c714806cceeefe22fe51b834705eb2e69cba))
* **@typescript-eslint/*:** upgrade to version 5.33.1 ([cb0e223](https://github.com/nodkz/mongodb-memory-server/commit/cb0e223073b41cdb9c0dd6578c14b953cb643cbf))
* **eslint:** upgrade to version 8.22.0 ([01591eb](https://github.com/nodkz/mongodb-memory-server/commit/01591eb3adb7eb75dcb1f5cdf85905857725dab4))
* **ts-jest:** upgrade to version 28.0.8 ([10bb530](https://github.com/nodkz/mongodb-memory-server/commit/10bb53001ad4957f885cd7d525aa5660683c2a25))

## [8.8.0](https://github.com/nodkz/mongodb-memory-server/compare/v8.7.2...v8.8.0) (2022-07-24)


Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
"@semantic-release/github": "7.2.3",
"@semantic-release/npm": "7.1.3",
"@semantic-release/release-notes-generator": "9.0.3",
"@types/jest": "^28.1.6",
"@types/jest": "^28.1.7",
"@types/node": "~14.14.45",
"@typescript-eslint/eslint-plugin": "5.30.7",
"@typescript-eslint/parser": "5.30.7",
"@typescript-eslint/eslint-plugin": "5.33.1",
"@typescript-eslint/parser": "5.33.1",
"commitlint": "16.2.4",
"conventional-changelog-conventionalcommits": "5.0.0",
"cross-env": "7.0.3",
"doctoc": "2.2.0",
"eslint": "8.20.0",
"eslint": "8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "4.2.1",
"husky": "7.0.4",
"jest": "28.1.3",
"lint-staged": "11.2.6",
"prettier": "2.7.1",
"semantic-release": "17.4.7",
"ts-jest": "28.0.7",
"ts-jest": "28.0.8",
"typescript": "4.4.4"
},
"workspaces": {
Expand Down
10 changes: 6 additions & 4 deletions packages/mongodb-memory-server-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-core",
"version": "8.8.0",
"version": "8.9.0-beta.3",
"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.",
"main": "lib/index",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -33,11 +33,13 @@
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/find-cache-dir": "^3.2.1",
"@types/semver": "^7.3.10",
"@types/semver": "^7.3.12",
"@types/tar-stream": "^2.2.2",
"@types/uuid": "^8.3.4",
"@types/yauzl": "^2.10.0",
"rimraf": "^3.0.2"
"@types/yazl": "^2.4.2",
"rimraf": "^3.0.2",
"yazl": "^2.5.1"
},
"dependencies": {
"@types/tmp": "^0.2.3",
Expand All @@ -48,7 +50,7 @@
"get-port": "^5.1.1",
"https-proxy-agent": "^5.0.1",
"md5-file": "^5.0.0",
"mongodb": "~4.7.0",
"mongodb": "~4.9.0",
"new-find-package-json": "^2.0.0",
"semver": "^7.3.7",
"tar-stream": "^2.1.4",
Expand Down
6 changes: 6 additions & 0 deletions packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
}

this.servers = [];
this._ranCreateAuth = false;

return;
}
Expand Down Expand Up @@ -673,9 +674,14 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
const uris = this.servers.map((server) => server.getUri());
const isInMemory = this.servers[0].instanceInfo?.storageEngine === 'ephemeralForTest';

const extraOptions = this._ranCreateAuth
? this.servers[0].instanceInfo?.instance.extraConnectionOptions ?? {}
: {};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,56 +312,60 @@ describe('single server replset', () => {
replSet: { auth: {}, count: 3, storageEngine: 'wiredTiger' },
});

utils.assertion(!utils.isNullOrUndefined(replSet.replSetOpts.auth));
utils.assertion(typeof replSet.replSetOpts.auth === 'object');
async function testConnections() {
utils.assertion(!utils.isNullOrUndefined(replSet.replSetOpts.auth));
utils.assertion(typeof replSet.replSetOpts.auth === 'object');

utils.assertion(!utils.isNullOrUndefined(replSet.replSetOpts.auth.customRootName));
utils.assertion(!utils.isNullOrUndefined(replSet.replSetOpts.auth.customRootPwd));
utils.assertion(!utils.isNullOrUndefined(replSet.replSetOpts.auth.customRootName));
utils.assertion(!utils.isNullOrUndefined(replSet.replSetOpts.auth.customRootPwd));

// test unpriviliged connection
{
const con = await MongoClient.connect(replSet.getUri());
// test unpriviliged connection
{
const con = await MongoClient.connect(replSet.getUri());

const db = con.db('somedb');
const col = db.collection('somecol');
const db = con.db('somedb');
const col = db.collection('somecol');

try {
await col.insertOne({ test: 1 });
fail('Expected insertion to fail');
} catch (err) {
expect(err).toBeInstanceOf(MongoServerError);
expect((err as MongoServerError).codeName).toEqual('Unauthorized');
} finally {
await con.close();
try {
await col.insertOne({ test: 1 });
fail('Expected insertion to fail');
} catch (err) {
expect(err).toBeInstanceOf(MongoServerError);
expect((err as MongoServerError).codeName).toEqual('Unauthorized');
} finally {
await con.close();
}
}
}

// test priviliged connection
{
const con: MongoClient = await MongoClient.connect(replSet.getUri(), {
authSource: 'admin',
authMechanism: 'SCRAM-SHA-256',
auth: {
username: replSet.replSetOpts.auth.customRootName,
password: replSet.replSetOpts.auth.customRootPwd,
},
});
// test priviliged connection
{
const con: MongoClient = await MongoClient.connect(replSet.getUri(), {
authSource: 'admin',
authMechanism: 'SCRAM-SHA-256',
auth: {
username: replSet.replSetOpts.auth.customRootName,
password: replSet.replSetOpts.auth.customRootPwd,
},
});

const admindb = con.db('admin');
const users: { users?: { user: string }[] } = await admindb.command({
usersInfo: replSet.replSetOpts.auth.customRootName,
});
expect(users.users).toHaveLength(1);
expect(users.users?.[0].user).toEqual(replSet.replSetOpts.auth.customRootName);
const admindb = con.db('admin');
const users: { users?: { user: string }[] } = await admindb.command({
usersInfo: replSet.replSetOpts.auth.customRootName,
});
expect(users.users).toHaveLength(1);
expect(users.users?.[0].user).toEqual(replSet.replSetOpts.auth.customRootName);

const db = con.db('somedb');
const col = db.collection('somecol');
const db = con.db('somedb');
const col = db.collection('somecol');

expect(await col.insertOne({ test: 1 })).toHaveProperty('acknowledged', true);
expect(await col.insertOne({ test: 1 })).toHaveProperty('acknowledged', true);

await con.close();
await con.close();
}
}

await testConnections();

// @ts-expect-error because "initAllServers" is protected
expect(MongoMemoryReplSet.prototype.initAllServers).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledTimes(0);
Expand All @@ -372,6 +376,13 @@ describe('single server replset', () => {
expect(replSet.servers[2].instanceInfo?.instance.instanceOpts.auth).toStrictEqual(true);
}

await replSet.stop({ doCleanup: false });

// test restart for "_ranCreateAuth" restart testing
await replSet.start();

await testConnections();

await replSet.stop();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { assertion, mkdir, pathExists } from './utils';
import { DryMongoBinary } from './DryMongoBinary';
import { MongoBinaryOpts } from './MongoBinary';
import { clearLine } from 'readline';
import { Md5CheckFailedError } from './errors';
import { GenericMMSError, Md5CheckFailedError } from './errors';

const log = debug('MongoMS:MongoBinaryDownload');

Expand Down Expand Up @@ -281,7 +281,7 @@ export class MongoBinaryDownload {

await mkdir(path.dirname(mongodbFullPath));

const filter = (file: string) => /(?:bin\/(?:mongod(?:\.exe)?)|(?:.*\.dll))$/i.test(file);
const filter = (file: string) => /(?:bin\/(?:mongod(?:\.exe)?))$/i.test(file);

if (/(.tar.gz|.tgz)$/.test(mongoDBArchive)) {
await this.extractTarGz(mongoDBArchive, mongodbFullPath, filter);
Expand Down Expand Up @@ -332,22 +332,20 @@ export class MongoBinaryDownload {
stream.resume();
});

return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
createReadStream(mongoDBArchive)
.on('error', (err) => {
reject('Unable to open tarball ' + mongoDBArchive + ': ' + err);
rej(new GenericMMSError('Unable to open tarball ' + mongoDBArchive + ': ' + err));
})
.pipe(createUnzip())
.on('error', (err) => {
reject('Error during unzip for ' + mongoDBArchive + ': ' + err);
rej(new GenericMMSError('Error during unzip for ' + mongoDBArchive + ': ' + err));
})
.pipe(extract)
.on('error', (err) => {
reject('Error during untar for ' + mongoDBArchive + ': ' + err);
rej(new GenericMMSError('Error during untar for ' + mongoDBArchive + ': ' + err));
})
.on('finish', (result) => {
resolve(result);
});
.on('finish', res);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
case 'x64':
return 'x86_64';
case 'arm64':
return 'aarch64';
case 'aarch64':
return 'aarch64';
default:
Expand Down

0 comments on commit 5246510

Please sign in to comment.