diff --git a/README.md b/README.md index f5d843f37..b60709831 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ const mongod = new MongodbMemoryServer({ downloadDir?: string, // by default %HOME/.mongodb-binaries platform?: string, // by default os.platform() arch?: string, // by default os.arch() - http?: any, // see mongodb-download package + ssl?: boolean, // by default false debug?: boolean, // by default false }, debug?: boolean, // by default false diff --git a/src/MongoMemoryServer.js b/src/MongoMemoryServer.js index 89b0aa1a5..a4e2617e8 100644 --- a/src/MongoMemoryServer.js +++ b/src/MongoMemoryServer.js @@ -22,7 +22,7 @@ export type MongoMemoryServerOptsT = { downloadDir?: string, platform?: string, arch?: string, - http?: any, + ssl?: boolean, debug?: boolean | Function, }, debug?: boolean, diff --git a/src/util/MongoBinary.js b/src/util/MongoBinary.js index 33b7d2822..8e1717546 100644 --- a/src/util/MongoBinary.js +++ b/src/util/MongoBinary.js @@ -15,7 +15,7 @@ export type MongoBinaryOpts = { downloadDir?: string, platform?: string, arch?: string, - http?: any, + ssl?: boolean, debug?: boolean | Function, }; @@ -27,8 +27,8 @@ export default class MongoBinary { downloadDir = path.resolve(os.homedir(), '.mongodb-binaries'), platform = os.platform(), arch = os.arch(), + ssl = false, version = '3.4.4', - http = {}, } = opts; let debug; @@ -79,8 +79,8 @@ export default class MongoBinary { downloadDir, platform, arch, + ssl, version, - http, }); downloader.debug = debug; diff --git a/src/util/MongoBinaryDownload.js b/src/util/MongoBinaryDownload.js index 45df0f6c2..eae8dd042 100644 --- a/src/util/MongoBinaryDownload.js +++ b/src/util/MongoBinaryDownload.js @@ -15,7 +15,7 @@ export type MongoBinaryDownloadOpts = { downloadDir: string, platform: string, arch: string, - http: any, + ssl: boolean, debug?: boolean | Function, }; @@ -32,22 +32,22 @@ export default class MongoBinaryDownload { downloadDir: string; arch: string; + ssl: boolean; version: string; platform: string; - http: any; constructor({ platform, arch, + ssl, downloadDir, version, - http, debug, }: $Shape) { this.platform = platform || os.platform(); this.arch = arch || os.arch(); + this.ssl = ssl || false; this.version = version || 'latest'; - this.http = http || {}; this.downloadDir = path.resolve(downloadDir || 'mongodb-download'); this.dlProgress = { current: 0, @@ -89,6 +89,7 @@ export default class MongoBinaryDownload { const mbdUrl = new MongoBinaryDownloadUrl({ platform: this.platform, arch: this.arch, + ssl: this.ssl, version: this.version, }); diff --git a/src/util/MongoBinaryDownloadUrl.js b/src/util/MongoBinaryDownloadUrl.js index 3ff6303e3..fc10c3750 100644 --- a/src/util/MongoBinaryDownloadUrl.js +++ b/src/util/MongoBinaryDownloadUrl.js @@ -14,18 +14,21 @@ export type MongoBinaryDownloadUrlOpts = { version: string, platform: string, arch: string, + ssl?: boolean, os?: ?OS, // getos() result }; export default class MongoBinaryDownloadUrl { platform: string; arch: string; + ssl: ?boolean; version: string; os: ?OS; - constructor({ platform, arch, version, os }: MongoBinaryDownloadUrlOpts) { + constructor({ platform, arch, ssl, version, os }: MongoBinaryDownloadUrlOpts) { this.platform = this.translatePlatform(platform); this.arch = this.translateArch(arch, this.platform); + this.ssl = ssl; this.version = version; this.os = os; } @@ -36,7 +39,13 @@ export default class MongoBinaryDownloadUrl { } async getArchiveName(): Promise { - let name = `mongodb-${this.platform}-${this.arch}`; + let name = `mongodb-${this.platform}`; + + if (this.ssl) { + name += '-ssl'; + } + + name += `-${this.arch}`; let osString; if (this.platform === 'linux' && this.arch !== 'i686') { diff --git a/src/util/__tests__/MongoBinaryDownloadUrl-test.js b/src/util/__tests__/MongoBinaryDownloadUrl-test.js index bad8838b0..fdf67d1df 100644 --- a/src/util/__tests__/MongoBinaryDownloadUrl-test.js +++ b/src/util/__tests__/MongoBinaryDownloadUrl-test.js @@ -4,6 +4,43 @@ import MongoBinaryDownloadUrl from '../MongoBinaryDownloadUrl'; describe('MongoBinaryDownloadUrl', () => { describe('getDownloadUrl()', () => { + describe('for mac', () => { + it('3.4.4 without ssl', async () => { + const du = new MongoBinaryDownloadUrl({ + platform: 'darwin', + arch: 'x64', + version: '3.4.4', + }); + expect(await du.getDownloadUrl()).toBe( + 'https://downloads.mongodb.org/osx/mongodb-osx-x86_64-3.4.4.tgz' + ); + }); + + it('3.4.4 with ssl', async () => { + const du = new MongoBinaryDownloadUrl({ + platform: 'darwin', + arch: 'x64', + version: '3.4.4', + ssl: true, + }); + expect(await du.getDownloadUrl()).toBe( + 'https://downloads.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.4.4.tgz' + ); + }); + + it('3.6.2 with ssl', async () => { + const du = new MongoBinaryDownloadUrl({ + platform: 'darwin', + arch: 'x64', + version: '3.6.2', + ssl: true, + }); + expect(await du.getDownloadUrl()).toBe( + 'https://downloads.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.2.tgz' + ); + }); + }); + it('for ubuntu', async () => { const du = new MongoBinaryDownloadUrl({ platform: 'linux',