diff --git a/packages/download-url/src/bin.ts b/packages/download-url/src/bin.ts index c5a2aad..3be4342 100644 --- a/packages/download-url/src/bin.ts +++ b/packages/download-url/src/bin.ts @@ -1,12 +1,13 @@ import path from 'path'; import fs from 'fs'; import minimist from 'minimist'; +import type { Options } from './index'; import getURL from './index'; /* eslint no-sync:0 no-console:0 */ const usage = fs.readFileSync(path.resolve(__dirname, '../usage.txt'), 'utf8'); const args = minimist(process.argv.slice(2), { - boolean: ['debug'] + boolean: ['debug'], }); args.version = args._[0] || args.version || 'stable'; @@ -15,7 +16,11 @@ if (args.help || args.h) { console.error(usage); process.exitCode = 1; } else { - getURL(args as any) - .then(pkg => console.log(pkg.url)) - .catch(err => { process.nextTick(() => { throw err; }); }); + getURL(args as Options) + .then((pkg) => console.log(pkg.url)) + .catch((err) => { + process.nextTick(() => { + throw err; + }); + }); } diff --git a/packages/download-url/src/index.ts b/packages/download-url/src/index.ts index 70af8f1..67531f2 100644 --- a/packages/download-url/src/index.ts +++ b/packages/download-url/src/index.ts @@ -1,13 +1,14 @@ import os from 'os'; import path from 'path'; import semver from 'semver'; -import { getVersion, DownloadInfo, VersionListOpts, clearCache } from './version-list'; +import type { DownloadInfo, VersionListOpts } from './version-list'; +import { getVersion, clearCache } from './version-list'; import { getCurrentLinuxDistro } from './linux-distro'; import { inspect } from 'util'; import _debug from 'debug'; const debug = _debug('mongodb-download-url'); -type PriorityValue = { value: T; priority: number; } +type PriorityValue = { value: T; priority: number }; type ArtifactOptions = { /** @@ -51,7 +52,7 @@ type ArtifactOptions = { /** * @deprecated Use arch instead. */ - bits?: '32' | '64' | 32 | 64 + bits?: '32' | '64' | 32 | 64; }; export type Options = ArtifactOptions & VersionListOpts; @@ -121,7 +122,12 @@ function parseArch(arch: string): string[] { return [arch]; } -async function parseTarget(distro: string | undefined, platform: string, archs: string[], version: string): Promise[]> { +async function parseTarget( + distro: string | undefined, + platform: string, + archs: string[], + version: string +): Promise[]> { if (platform === 'linux') { const results: PriorityValue[] = []; if (distro) { @@ -145,15 +151,17 @@ async function parseTarget(distro: string | undefined, platform: string, archs: let distroResultsErr; try { - results.push(...await getCurrentLinuxDistro()); + results.push(...(await getCurrentLinuxDistro())); } catch (err) { distroResultsErr = err; } - if (distro === undefined && - distroResultsErr && - (version === '*' || - version === 'latest-alpha' || - semver.gte(version, '4.0.0'))) { + if ( + distro === undefined && + distroResultsErr && + (version === '*' || + version === 'latest-alpha' || + semver.gte(version, '4.0.0')) + ) { throw distroResultsErr; } return results; @@ -163,7 +171,7 @@ async function parseTarget(distro: string | undefined, platform: string, archs: if (archs.includes('i686')) { return [ { value: 'windows', priority: 1 }, - { value: 'windows_i686', priority: 10 } + { value: 'windows_i686', priority: 10 }, ]; } else { return [ @@ -171,7 +179,7 @@ async function parseTarget(distro: string | undefined, platform: string, archs: { value: 'windows_x86_64', priority: 10 }, { value: 'windows_x86_64-2008plus', priority: 10 }, { value: 'windows_x86_64-2008plus-ssl', priority: 100 }, - { value: 'windows_x86_64-2012plus', priority: 100 } + { value: 'windows_x86_64-2012plus', priority: 100 }, ]; } } else if (['darwin', 'osx', 'macos'].includes(platform)) { @@ -179,23 +187,23 @@ async function parseTarget(distro: string | undefined, platform: string, archs: { value: 'osx', priority: 1 }, { value: 'osx-ssl', priority: 10 }, { value: 'darwin', priority: 1 }, - { value: 'macos', priority: 1 } + { value: 'macos', priority: 1 }, ]; } return [{ value: platform, priority: 1 }]; } async function resolve(opts: ProcessedOptions): Promise { - let download: DownloadInfo; + let download: DownloadInfo | undefined; if (opts.version === 'latest-alpha' && opts.enterprise) { const targets = opts.target.map(({ value }) => value); const arch = opts.arch.includes('arm64') ? 'arm64' : 'x86_64'; - let url, target; + let url, target: string | undefined; if (targets.includes('macos')) { url = `https://downloads.mongodb.com/osx/mongodb-macos-${arch}-enterprise-latest.tgz`; target = 'macos'; } else if (targets.includes('linux_x86_64')) { - target = maximizer(opts.target, candidate => candidate.priority).value; + target = maximizer(opts.target, (candidate) => candidate.priority)!.value; url = `https://downloads.mongodb.com/linux/mongodb-linux-${arch}-enterprise-${target}-latest.tgz`; } else if (targets.includes('windows_x86_64')) { target = 'windows'; @@ -210,8 +218,8 @@ async function resolve(opts: ProcessedOptions): Promise { url, sha1: '', sha256: '', - debug_symbols: '' - } + debug_symbols: '', + }, }; } } @@ -222,44 +230,59 @@ async function resolve(opts: ProcessedOptions): Promise { if (!version) { throw new Error(`Could not find version matching ${inspect(opts)}`); } - const bestDownload = maximizer(version.downloads.map((candidate: DownloadInfo) => { - if (opts.enterprise) { - if (candidate.edition !== 'enterprise') { - return { value: candidate, priority: 0 }; + const bestDownload = maximizer( + version.downloads.map((candidate: DownloadInfo) => { + if (opts.enterprise) { + if (candidate.edition !== 'enterprise') { + return { value: candidate, priority: 0 }; + } + } else { + if ( + candidate.edition !== 'targeted' && + candidate.edition !== 'base' + ) { + return { value: candidate, priority: 0 }; + } } - } else { - if (candidate.edition !== 'targeted' && candidate.edition !== 'base') { + + if (!candidate.arch || !opts.arch.includes(candidate.arch)) { return { value: candidate, priority: 0 }; } - } - if (!opts.arch.includes(candidate.arch)) { - return { value: candidate, priority: 0 }; - } + const targetPriority = getPriority(opts.target, candidate.target); + return { value: candidate, priority: targetPriority }; + }), + (candidate: PriorityValue) => candidate.priority + ); - const targetPriority = getPriority(opts.target, candidate.target); - return { value: candidate, priority: targetPriority }; - }), (candidate: PriorityValue) => candidate.priority); - if (bestDownload.priority > 0) { + if (bestDownload && bestDownload.priority > 0) { download = bestDownload.value; } } if (!download) { - throw new Error(`Could not find download URL for version ${version?.version} ${inspect(opts)}`); + throw new Error( + `Could not find download URL for version ${version?.version} ${inspect( + opts + )}` + ); } const wantsCryptd = opts.cryptd && download.target; const wantsCryptShared = opts.crypt_shared && download.target; if (wantsCryptShared && !download.crypt_shared && !download.csfle) { - throw new Error(`No crypt_shared library download for version ${version?.version} available ${inspect(opts)}`); + throw new Error( + `No crypt_shared library download for version ${ + version?.version + } available ${inspect(opts)}` + ); } debug('fully resolved', JSON.stringify(opts, null, 2), download); // mongocryptd is contained in the regular enterprise archive, the csfle lib is not let { url } = wantsCryptShared - ? (download.crypt_shared ?? download.csfle) - : ((wantsCryptd ? download.cryptd : null) ?? download.archive); + ? (download.crypt_shared ?? download.csfle)! + : (wantsCryptd ? download.cryptd : null) ?? download.archive; if (wantsCryptd) { // cryptd package on Windows was buggy: https://jira.mongodb.org/browse/BUILD-13653 url = url.replace('mongodb-shell-windows', 'mongodb-cryptd-windows'); @@ -269,24 +292,26 @@ async function resolve(opts: ProcessedOptions): Promise { ...opts, name: 'mongodb', url: url, - arch: download.arch, - distro: download.target, - platform: download.target, - filenamePlatform: download.target, + arch: download.arch!, + distro: download.target!, + platform: download.target!, + filenamePlatform: download.target!, version: version?.version ?? '*', artifact: path.basename(url), debug: false, enterprise: download.edition === 'enterprise', branch: 'master', - bits: ['i386', 'i686'].includes(download.arch) ? '32' : '64', - ext: url.match(/\.([^.]+)$/)?.[1] ?? 'tgz' + bits: ['i386', 'i686'].includes(download.arch!) ? '32' : '64', + ext: url.match(/\.([^.]+)$/)?.[1] ?? 'tgz', }; } -async function options(opts: Options | string = {}): Promise { +async function options( + opts: Options | string = {} +): Promise { if (typeof opts === 'string') { opts = { - version: opts + version: opts, }; } else { opts = { ...opts }; @@ -314,10 +339,15 @@ async function options(opts: Options | string = {}): Promise { +export async function getDownloadURL( + opts?: Options | string +): Promise { const parsedOptions = await options(opts); debug('Building URL for options `%j`', parsedOptions); diff --git a/packages/download-url/src/linux-distro.ts b/packages/download-url/src/linux-distro.ts index 4907a51..8123780 100644 --- a/packages/download-url/src/linux-distro.ts +++ b/packages/download-url/src/linux-distro.ts @@ -5,48 +5,50 @@ import _debug from 'debug'; const debug = _debug('mongodb-download-url:linux-distro'); const execFile = promisify(childProcess.execFile); -type PriorityValue = { value: T; priority: number; } +type PriorityValue = { value: T; priority: number }; let osRelease: string; -export async function getCurrentLinuxDistro(): Promise[]> { +export async function getCurrentLinuxDistro(): Promise< + PriorityValue[] +> { if (process.env.DISTRO_ID) { const distroId = process.env.DISTRO_ID.split('-')[0].split('_')[0]; debug('Using environment-provided linux distro ID', distroId); let match; - if (match = distroId.match(/^ubuntu(\d\d)(\d\d)$/)) { + if ((match = distroId.match(/^ubuntu(\d\d)(\d\d)$/))) { return listDistroIds({ id: 'ubuntu', version: match[1] }); - } else if (match = distroId.match(/^debian([8-9])\d$/)) { + } else if ((match = distroId.match(/^debian([8-9])\d$/))) { return listDistroIds({ id: 'debian', version: match[1] }); - } else if (match = distroId.match(/^debian([1-7]\d)$/)) { + } else if ((match = distroId.match(/^debian([1-7]\d)$/))) { return listDistroIds({ id: 'debian', version: match[1] }); - } else if (match = distroId.match(/^suse(\d+)-?(sp\d+)?$/)) { + } else if ((match = distroId.match(/^suse(\d+)-?(sp\d+)?$/))) { return listDistroIds({ id: 'suse', version: match[1] }); - } else if (match = distroId.match(/^rhel(\d+)$/)) { + } else if ((match = distroId.match(/^rhel(\d+)$/))) { return listDistroIds({ id: 'redhatenterprise', version: match[1] }); } else if (['amazon', 'amzn64', 'amazon1'].includes(distroId)) { return listDistroIds({ id: 'amazon', version: '2018.03' }); - } else if (match = distroId.match(/^amazon([0-9.]+)$/)) { + } else if ((match = distroId.match(/^amazon([0-9.]+)$/))) { return listDistroIds({ id: 'amazon', version: match[1] }); } return [{ value: distroId, priority: 100 }]; } - let osReleaseId: string; + let osReleaseId: string | undefined; try { osRelease ??= await fs.readFile('/etc/os-release', 'utf8'); debug('loaded /etc/os-release'); - } catch (err) { + } catch (err: any) { if (err.code === 'ENOENT') { osRelease = ''; } } if (osRelease) { - const id = osReleaseId = osRelease.match(/^ID="?(.+?)"?$/m)?.[1]; + const id = (osReleaseId = osRelease.match(/^ID="?(.+?)"?$/m)?.[1]); const version = osRelease.match(/^VERSION_ID="?(.+?)"?$/m)?.[1]; const codename = osRelease.match(/^VERSION_CODENAME="?(.+?)"?$/m)?.[1]; if (id && (version || codename)) { debug('got os-release info', { id, version, codename }); - const results = listDistroIds({ id, version, codename }); + const results = listDistroIds({ id, version: version || '', codename }); if (results.length > 0) { return results; } @@ -57,10 +59,20 @@ export async function getCurrentLinuxDistro(): Promise[]> if (results.length > 0) { return results; } - throw new Error(`Could not figure out current Linux distro (${id}, ${osReleaseId})`); + throw new Error( + `Could not figure out current Linux distro (${id}, ${osReleaseId})` + ); } -function listDistroIds({ id, version, codename }: { id: string, version: string, codename?: string }): PriorityValue[] { +function listDistroIds({ + id, + version, + codename, +}: { + id: string; + version: string; + codename?: string; +}): PriorityValue[] { const results: PriorityValue[] = []; switch (id.toLowerCase()) { case 'ubuntu': { @@ -72,20 +84,30 @@ function listDistroIds({ id, version, codename }: { id: string, version: string, if (major >= 20) results.push({ value: 'ubuntu2004', priority: 500 }); if (major >= 22) results.push({ value: 'ubuntu2204', priority: 600 }); if (major >= 24) results.push({ value: 'ubuntu2404', priority: 700 }); - if (major > 24) results.push({ value: 'ubuntu' + version.replace('.', '') + '04', priority: 700 }); + if (major > 24) + results.push({ + value: 'ubuntu' + version.replace('.', '') + '04', + priority: 700, + }); return results; } case 'debian': { if (+version >= 8) results.push({ value: 'debian81', priority: 100 }); if (+version >= 9) results.push({ value: 'debian92', priority: 200 }); if (+version >= 10) results.push({ value: 'debian10', priority: 300 }); - if (+version > 10) results.push({ value: 'debian' + version, priority: 400 }); + if (+version > 10) + results.push({ value: 'debian' + version, priority: 400 }); if (!version) { - if (codename === 'buster') results.push({ value: 'debian10', priority: 100 }); - if (codename === 'bullseye') results.push({ value: 'debian11', priority: 200 }); - if (codename === 'bookworm') results.push({ value: 'debian12', priority: 300 }); - if (codename === 'trixie') results.push({ value: 'debian13', priority: 400 }); - if (codename === 'forky') results.push({ value: 'debian14', priority: 500 }); + if (codename === 'buster') + results.push({ value: 'debian10', priority: 100 }); + if (codename === 'bullseye') + results.push({ value: 'debian11', priority: 200 }); + if (codename === 'bookworm') + results.push({ value: 'debian12', priority: 300 }); + if (codename === 'trixie') + results.push({ value: 'debian13', priority: 400 }); + if (codename === 'forky') + results.push({ value: 'debian14', priority: 500 }); } return results; } @@ -96,9 +118,14 @@ function listDistroIds({ id, version, codename }: { id: string, version: string, case 'amzn64': case 'amazon': if (version.match(/^201[0-9]\./)) { - return [{ value: 'amazon', priority: 100 }, { value: 'amzn64', priority: 100 }]; + return [ + { value: 'amazon', priority: 100 }, + { value: 'amzn64', priority: 100 }, + ]; } else if (version.match(/^\d\d\d\d\./)) { - return [{ value: 'amazon' + version.replace(/\..+$/, ''), priority: 100 }]; + return [ + { value: 'amazon' + version.replace(/\..+$/, ''), priority: 100 }, + ]; } else { return [{ value: 'amazon' + version.replace('.', ''), priority: 100 }]; } @@ -117,29 +144,40 @@ function listDistroIds({ id, version, codename }: { id: string, version: string, want = want * 10 + 9; } const known = [55, 57, 62, 67, 70, 71, 72, 80, 81, 82, 83, 8, 90, 93, 9]; - const allowedVersions = known.filter(v => v > 50 ? v <= want : v * 10 <= want); + const allowedVersions = known.filter((v) => + v > 50 ? v <= want : v * 10 <= want + ); - return allowedVersions.map((v, i) => ({ value: 'rhel' + v, priority: (i + 1) * 100 })); + return allowedVersions.map((v, i) => ({ + value: `rhel${v}`, + priority: (i + 1) * 100, + })); } } return []; } -async function lsbReleaseInfo(): Promise<{ id: string, version: string, codename: string }> { - const [ - id, - version, - codename - ] = await Promise.all([ - (async() => { - return (await execFile('lsb_release', ['-si'], { encoding: 'utf8' })).stdout.trim(); +async function lsbReleaseInfo(): Promise<{ + id: string; + version: string; + codename: string; +}> { + const [id, version, codename] = await Promise.all([ + (async () => { + return ( + await execFile('lsb_release', ['-si'], { encoding: 'utf8' }) + ).stdout.trim(); })(), - (async() => { - return (await execFile('lsb_release', ['-sr'], { encoding: 'utf8' })).stdout.trim(); + (async () => { + return ( + await execFile('lsb_release', ['-sr'], { encoding: 'utf8' }) + ).stdout.trim(); + })(), + (async () => { + return ( + await execFile('lsb_release', ['-sc'], { encoding: 'utf8' }) + ).stdout.trim(); })(), - (async() => { - return (await execFile('lsb_release', ['-sc'], { encoding: 'utf8' })).stdout.trim(); - })() ]); debug('got lsb info', { id, version, codename }); return { id, version, codename }; diff --git a/packages/download-url/src/version-list.ts b/packages/download-url/src/version-list.ts index cf90545..0e6da94 100644 --- a/packages/download-url/src/version-list.ts +++ b/packages/download-url/src/version-list.ts @@ -77,11 +77,13 @@ function defaultCachePath(): string { let fullJSON: FullJSON | undefined; let fullJSONFetchTime = 0; async function getFullJSON(opts: VersionListOpts): Promise { - const versionListUrl = opts.versionListUrl ?? 'https://downloads.mongodb.org/full.json'; + const versionListUrl = + opts.versionListUrl ?? 'https://downloads.mongodb.org/full.json'; const cachePath = opts.cachePath ?? defaultCachePath(); const cacheTimeMs = opts.cacheTimeMs ?? 24 * 3600 * 1000; let tryWriteCache = cacheTimeMs > 0; - const inMemoryCopyUpToDate = () => fullJSONFetchTime >= new Date().getTime() - cacheTimeMs; + const inMemoryCopyUpToDate = () => + fullJSONFetchTime >= new Date().getTime() - cacheTimeMs; try { if ((!fullJSON || !inMemoryCopyUpToDate()) && cacheTimeMs > 0) { @@ -89,9 +91,14 @@ async function getFullJSON(opts: VersionListOpts): Promise { const fh = await fs.open(cachePath, 'r'); try { const stat = await fh.stat(); - if (process.getuid && (stat.uid !== process.getuid() || (stat.mode & 0o022) !== 0)) { + if ( + process.getuid && + (stat.uid !== process.getuid() || (stat.mode & 0o022) !== 0) + ) { tryWriteCache = false; - debug('cannot use cache because it is not a file or we do not own it'); + debug( + 'cannot use cache because it is not a file or we do not own it' + ); throw new Error(); } if (stat.mtime.getTime() < new Date().getTime() - cacheTimeMs) { @@ -106,12 +113,17 @@ async function getFullJSON(opts: VersionListOpts): Promise { await fh.close(); } } - } catch {} + } catch { + // Ignore errors + } + if (!fullJSON || !inMemoryCopyUpToDate()) { debug('trying to load versions from source', versionListUrl); const response = await fetch(versionListUrl); if (!response.ok) { - throw new Error(`Could not get mongodb versions from ${versionListUrl}: ${response.statusText}`); + throw new Error( + `Could not get mongodb versions from ${versionListUrl}: ${response.statusText}` + ); } fullJSON = await response.json(); fullJSONFetchTime = new Date().getTime(); @@ -120,17 +132,22 @@ async function getFullJSON(opts: VersionListOpts): Promise { await fs.mkdir(path.dirname(cachePath), { recursive: true }); try { const compressed = await gzip(JSON.stringify(fullJSON), { level: 9 }); - await fs.writeFile(partialFilePath, compressed, { mode: 0o644, flag: 'wx' }); + await fs.writeFile(partialFilePath, compressed, { + mode: 0o644, + flag: 'wx', + }); await fs.rename(partialFilePath, cachePath); debug('wrote cache', cachePath); } catch { try { await fs.unlink(partialFilePath); - } catch {} + } catch { + // Ignore errors + } } } } - return fullJSON; + return fullJSON!; } export async function getVersion(opts: VersionListOpts): Promise { @@ -138,12 +155,18 @@ export async function getVersion(opts: VersionListOpts): Promise { let versions = fullJSON.versions; versions = versions.filter((info: VersionInfo) => info.downloads.length > 0); if (opts.allowedTags && !opts.allowedTags.includes('*')) { - versions = versions.filter((info: VersionInfo) => opts.allowedTags.some(tag => !!info[tag])); + versions = versions.filter((info: VersionInfo) => + opts.allowedTags!.some((tag) => !!info[tag as Exclude]) + ); } if (opts.version && opts.version !== '*') { - versions = versions.filter((info: VersionInfo) => semver.satisfies(info.version, opts.version)); + versions = versions.filter((info: VersionInfo) => + semver.satisfies(info.version, opts.version!) + ); } - versions = versions.sort((a: VersionInfo, b: VersionInfo) => semver.rcompare(a.version, b.version)); + versions = versions.sort((a: VersionInfo, b: VersionInfo) => + semver.rcompare(a.version, b.version) + ); return versions[0]; } @@ -154,7 +177,7 @@ export async function clearCache(cachePath?: string): Promise { if (cachePath !== '') { try { await fs.unlink(cachePath ?? defaultCachePath()); - } catch (err) { + } catch (err: any) { if (err.code === 'ENOENT') return; throw err; } diff --git a/packages/download-url/test/index.test.ts b/packages/download-url/test/index.test.ts index cd69351..4baf2d3 100644 --- a/packages/download-url/test/index.test.ts +++ b/packages/download-url/test/index.test.ts @@ -1,15 +1,21 @@ import assert from 'assert'; import fetch from 'node-fetch'; +import type { PathLike } from 'fs'; import { promises as fs } from 'fs'; import path from 'path'; import zlib from 'zlib'; import http from 'http'; import { once } from 'events'; -import resolve, { Options, clearCache } from '../'; +import type { Options } from '../'; +import resolve, { clearCache } from '../'; +import type { AddressInfo } from 'net'; const kUnknownUrl = Symbol('kUnknownUrl'); -async function verify(query: Options | string | undefined, expectedURL: string | typeof kUnknownUrl): Promise { +async function verify( + query: Options | string | undefined, + expectedURL: string | typeof kUnknownUrl +): Promise { const res = await resolve(query); if (expectedURL !== kUnknownUrl) { assert.strictEqual(res.url, expectedURL); @@ -21,13 +27,17 @@ async function verify(query: Options | string | undefined, expectedURL: string | } } -function withFakeDistro(distro) { - let origDistroId; - before(function() { +function withFakeDistro(distro: string) { + let origDistroId: string | undefined; + + // eslint-disable-next-line mocha/no-top-level-hooks + before(function () { origDistroId = process.env.DISTRO_ID; process.env.DISTRO_ID = distro; }); - after(function() { + + // eslint-disable-next-line mocha/no-top-level-hooks + after(function () { if (origDistroId) { process.env.DISTRO_ID = origDistroId; } else { @@ -36,738 +46,921 @@ function withFakeDistro(distro) { }); } -describe('mongodb-download-url', function() { +describe('mongodb-download-url', function () { this.slow(10_000); this.timeout(20_000); - before(async function() { + before(async function () { await clearCache(); }); - describe('linux', function() { - it('should resolve 2.4.14', async function() { + describe('linux', function () { + it('should resolve 2.4.14', async function () { const query = { version: '2.4.14', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.14.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.14.tgz' + ); }); - it('should resolve 2.6.11', async function() { + it('should resolve 2.6.11', async function () { const query = { version: '2.6.11', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz' + ); }); - it('should resolve 3.1.9 enterprise', async function() { + it('should resolve 3.1.9 enterprise', async function () { const query = { version: '3.1.9', platform: 'linux', distro: 'ubuntu1404', enterprise: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1404-3.1.9.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1404-3.1.9.tgz' + ); }); - it('should resolve 5.0.2 enterprise cryptd-only on Linux', async function() { + it('should resolve 5.0.2 enterprise cryptd-only on Linux', async function () { const query = { version: '5.0.2', platform: 'linux', distro: 'ubuntu2004', enterprise: true, cryptd: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/linux/mongodb-cryptd-linux-x86_64-enterprise-ubuntu2004-5.0.2.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/linux/mongodb-cryptd-linux-x86_64-enterprise-ubuntu2004-5.0.2.tgz' + ); }); - it('should resolve 5.0.2 enterprise cryptd-only on Windows', async function() { + it('should resolve 5.0.2 enterprise cryptd-only on Windows', async function () { const query = { version: '5.0.2', platform: 'windows', distro: 'windows', enterprise: true, cryptd: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/windows/mongodb-cryptd-windows-x86_64-enterprise-5.0.2.zip'); + await verify( + query, + 'https://downloads.mongodb.com/windows/mongodb-cryptd-windows-x86_64-enterprise-5.0.2.zip' + ); }); - it('should resolve 6.0.1 enterprise csfle-only on Linux', async function() { + it('should resolve 6.0.1 enterprise csfle-only on Linux', async function () { const query = { version: '6.0.1', platform: 'linux', distro: 'ubuntu2004', enterprise: true, csfle: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/linux/mongo_crypt_shared_v1-linux-x86_64-enterprise-ubuntu2004-6.0.1.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/linux/mongo_crypt_shared_v1-linux-x86_64-enterprise-ubuntu2004-6.0.1.tgz' + ); }); - it('should resolve 6.0.1 enterprise csfle-only on Windows', async function() { + it('should resolve 6.0.1 enterprise csfle-only on Windows', async function () { const query = { version: '6.0.1', platform: 'windows', distro: 'windows', enterprise: true, csfle: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/windows/mongo_crypt_shared_v1-windows-x86_64-enterprise-6.0.1.zip'); + await verify( + query, + 'https://downloads.mongodb.com/windows/mongo_crypt_shared_v1-windows-x86_64-enterprise-6.0.1.zip' + ); }); - it('should resolve 3.0.7 (32-bit)', async function() { + it('should resolve 3.0.7 (32-bit)', async function () { const query = { version: '3.0.7', platform: 'linux', - bits: 32 + bits: 32, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-i686-3.0.7.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-i686-3.0.7.tgz' + ); }); - describe('ubuntu 18.04', function() { + describe('ubuntu 18.04', function () { withFakeDistro('ubuntu1804'); - it('should resolve 4.2.0-rc1 with ubuntu-specific url', async function() { + it('should resolve 4.2.0-rc1 with ubuntu-specific url', async function () { const query = { version: '4.2.0-rc1', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.0-rc1.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.0-rc1.tgz' + ); }); - it('should resolve 4.0.0 with ubuntu-specific url and fallback to an older version of ubuntu', async function() { + it('should resolve 4.0.0 with ubuntu-specific url and fallback to an older version of ubuntu', async function () { const query = { version: '4.0.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.0.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.0.0.tgz' + ); }); - it('should resolve 3.6.0 with ubuntu-specific url and fallback to an older version of ubuntu', async function() { + it('should resolve 3.6.0 with ubuntu-specific url and fallback to an older version of ubuntu', async function () { const query = { version: '3.6.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-3.6.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-3.6.0.tgz' + ); }); - it('should resolve 2.6.11 with generic linux url', async function() { + it('should resolve 2.6.11 with generic linux url', async function () { const query = { version: '2.6.11', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz' + ); }); }); - describe('ubuntu 20.04', function() { + describe('ubuntu 20.04', function () { withFakeDistro('ubuntu2004'); - it('should resolve * with ubuntu-specific url', async function() { + it('should resolve * with ubuntu-specific url', async function () { const query = { version: '*', - platform: 'linux' + platform: 'linux', }; await verify(query, kUnknownUrl); }); - it('should resolve 4.4.4 with ubuntu-specific url', async function() { + it('should resolve 4.4.4 with ubuntu-specific url', async function () { const query = { version: '4.4.4', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.4.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.4.tgz' + ); }); - it('should resolve 4.2.3 with ubuntu-specific url', async function() { + it('should resolve 4.2.3 with ubuntu-specific url', async function () { const query = { version: '4.2.3', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.3.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.3.tgz' + ); }); - it('should resolve 4.4.0 with ubuntu-specific url for arm', async function() { + it('should resolve 4.4.0 with ubuntu-specific url for arm', async function () { const query = { version: '4.4.0', platform: 'linux', - arch: 'arm64' + arch: 'arm64', }; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-ubuntu2004-4.4.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-ubuntu2004-4.4.0.tgz' + ); }); - it('should resolve 6.2.0 as a continuous release', async function() { + it('should resolve 6.2.0 as a continuous release', async function () { const query = { version: '>= 6.1 <= 6.2.0', platform: 'linux', arch: 'arm64', - allowedTags: ['production_release', 'continuous_release'] + allowedTags: ['production_release', 'continuous_release'], } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-ubuntu2004-6.2.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-ubuntu2004-6.2.0.tgz' + ); }); }); - describe('sunos', function() { - it('should resolve 3.5.8 with sunos-specific url', async function() { + describe('sunos', function () { + it('should resolve 3.5.8 with sunos-specific url', async function () { const query = { version: '3.5.8', platform: 'sunos', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/sunos5/mongodb-sunos5-x86_64-3.5.8.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/sunos5/mongodb-sunos5-x86_64-3.5.8.tgz' + ); }); }); - describe('suse 12', function() { + describe('suse 12', function () { withFakeDistro('suse12'); - it('should resolve 4.4.0 with suse-specific url', async function() { + it('should resolve 4.4.0 with suse-specific url', async function () { const query = { version: '4.4.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse12-4.4.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse12-4.4.0.tgz' + ); }); }); - describe('suse 15', function() { + describe('suse 15', function () { withFakeDistro('suse15'); - it('should resolve 4.4.0 with suse-specific url', async function() { + it('should resolve 4.4.0 with suse-specific url', async function () { const query = { version: '4.4.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.0.tgz' + ); }); }); - describe('suse 15', function() { + describe('suse 15sp4', function () { withFakeDistro('suse15sp4'); - it('should resolve 4.4.0 with suse-specific url', async function() { + it('should resolve 4.4.0 with suse-specific url', async function () { const query = { version: '4.4.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.0.tgz' + ); }); }); - describe('RHEL 7.7', function() { + describe('RHEL 7.7', function () { withFakeDistro('rhel77'); - it('should resolve 7.0.14 with RHEL-specific url', async function() { + it('should resolve 7.0.14 with RHEL-specific url', async function () { const query = { version: '7.0.14', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-7.0.14.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-7.0.14.tgz' + ); }); - it('should resolve 4.4.0 with RHEL-specific url', async function() { + it('should resolve 4.4.0 with RHEL-specific url', async function () { const query = { version: '4.4.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.0.tgz' + ); }); }); - describe('RHEL 8.3', function() { + describe('RHEL 8.3', function () { withFakeDistro('rhel83'); - it('should resolve 7.0.14 with new schema RHEL-specific url', async function() { + it('should resolve 7.0.14 with new schema RHEL-specific url', async function () { const query = { version: '7.0.14', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel8-7.0.14.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel8-7.0.14.tgz' + ); }); }); - describe('RHEL 8.0', function() { + describe('RHEL 8.0', function () { withFakeDistro('rhel80'); - it('should resolve 6.0.17 with new schema RHEL-specific url', async function() { + it('should resolve 6.0.17 with new schema RHEL-specific url', async function () { const query = { version: '6.0.17', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel8-6.0.17.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel8-6.0.17.tgz' + ); }); - it('should resolve 6.0.16 with old schema RHEL-specific url', async function() { + it('should resolve 6.0.16 with old schema RHEL-specific url', async function () { const query = { version: '6.0.16', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-6.0.16.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-6.0.16.tgz' + ); }); }); - describe('RHEL 5.5', function() { + describe('RHEL 5.5', function () { withFakeDistro('rhel55'); - it('should resolve 3.0.0 with RHEL-specific url', async function() { + it('should resolve 3.0.0 with RHEL-specific url', async function () { const query = { version: '3.0.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel55-3.0.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel55-3.0.0.tgz' + ); }); }); - describe('RHEL 7', function() { + describe('RHEL 7', function () { withFakeDistro('rhel7'); - it('should resolve 7.2 with RHEL-specific url', async function() { + it('should resolve 7.2 with RHEL-specific url', async function () { const query = { platform: 'linux', arch: 's390x', enterprise: true, - version: '6.0.19' + version: '6.0.19', } as const; - await verify(query, 'https://downloads.mongodb.com/linux/mongodb-linux-s390x-enterprise-rhel72-6.0.19.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/linux/mongodb-linux-s390x-enterprise-rhel72-6.0.19.tgz' + ); }); }); - describe('RHEL 8', function() { + describe('RHEL 8', function () { withFakeDistro('rhel8'); - it('should resolve zseries with RHEL8.3-specific url', async function() { + it('should resolve zseries with RHEL8.3-specific url', async function () { const query = { platform: 'linux', arch: 's390x', enterprise: true, - version: '6.0.19' + version: '6.0.19', } as const; // We don't have zseries release tagged as rhel8, so this should fallback to rhel83 as the latest one - await verify(query, 'https://downloads.mongodb.com/linux/mongodb-linux-s390x-enterprise-rhel83-6.0.19.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/linux/mongodb-linux-s390x-enterprise-rhel83-6.0.19.tgz' + ); }); - it('should resolve x64 with RHEL8-specific url', async function() { + it('should resolve x64 with RHEL8-specific url', async function () { const query = { platform: 'linux', enterprise: true, version: '6.0.19', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-rhel8-6.0.19.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-rhel8-6.0.19.tgz' + ); }); }); - describe('debian 9.2', function() { + describe('debian 9.2', function () { withFakeDistro('debian92'); - it('should resolve 4.4.4 with debian-specific url', async function() { + it('should resolve 4.4.4 with debian-specific url', async function () { const query = { version: '4.4.4', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.4.4.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.4.4.tgz' + ); }); - it('should resolve 4.0.0 with debian-specific url', async function() { + it('should resolve 4.0.0 with debian-specific url', async function () { const query = { version: '4.0.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.0.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.0.0.tgz' + ); }); - it('should resolve 3.6.0 with debian-specific url', async function() { + it('should resolve 3.6.0 with debian-specific url', async function () { const query = { version: '3.6.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian81-3.6.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian81-3.6.0.tgz' + ); }); - it('should resolve 2.6.11 with generic linux url', async function() { + it('should resolve 2.6.11 with generic linux url', async function () { const query = { version: '2.6.11', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz' + ); }); }); - describe('debian 10', function() { + describe('debian 10', function () { withFakeDistro('debian10'); - it('should resolve 4.4.4 with debian-specific url', async function() { + it('should resolve 4.4.4 with debian-specific url', async function () { const query = { version: '4.4.4', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-4.4.4.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-4.4.4.tgz' + ); }); - it('should resolve 4.2.1 with debian-specific url', async function() { + it('should resolve 4.2.1 with debian-specific url', async function () { const query = { version: '4.2.1', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-4.2.1.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-4.2.1.tgz' + ); }); - it('should resolve 4.1.1 with debian-specific url', async function() { + it('should resolve 4.1.1 with debian-specific url', async function () { const query = { version: '4.1.1', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.1.1.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.1.1.tgz' + ); }); - it('should resolve 3.6.0 with debian-specific url', async function() { + it('should resolve 3.6.0 with debian-specific url', async function () { const query = { version: '3.6.0', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian81-3.6.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian81-3.6.0.tgz' + ); }); - it('should resolve 2.6.11 with generic linux url', async function() { + it('should resolve 2.6.11 with generic linux url', async function () { const query = { version: '2.6.11', platform: 'linux', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz' + ); }); }); - describe('rhel 7.1 ppc', function() { + describe('rhel 7.1 ppc', function () { withFakeDistro('rhel71'); - it('should resolve 4.4.5 with rhel-specific url', async function() { + it('should resolve 4.4.5 with rhel-specific url', async function () { const query = { version: '4.4.5', platform: 'linux', arch: 'ppc64', - enterprise: true + enterprise: true, }; - await verify(query, 'https://downloads.mongodb.com/linux/mongodb-linux-ppc64le-enterprise-rhel71-4.4.5.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/linux/mongodb-linux-ppc64le-enterprise-rhel71-4.4.5.tgz' + ); }); }); }); - describe('windows', function() { - it('should resolve 3.1.9', async function() { + describe('windows', function () { + it('should resolve 3.1.9', async function () { const query = { version: '3.1.9', platform: 'win32', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.1.9.zip'); + await verify( + query, + 'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.1.9.zip' + ); }); - it('should resolve 3.1.19 enterprise', async function() { + it('should resolve 3.1.19 enterprise', async function () { const query = { version: '3.1.9', platform: 'win32', enterprise: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/win32/mongodb-win32-x86_64-enterprise-windows-64-3.1.9.zip'); + await verify( + query, + 'https://downloads.mongodb.com/win32/mongodb-win32-x86_64-enterprise-windows-64-3.1.9.zip' + ); }); - it('should resolve 2.6.11', async function() { + it('should resolve 2.6.11', async function () { const query = { version: '2.6.11', platform: 'win32', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.6.11.zip'); + await verify( + query, + 'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.6.11.zip' + ); }); - it('should resolve 3.0.7 (32-bit)', async function() { + it('should resolve 3.0.7 (32-bit)', async function () { const query = { version: '3.0.7', platform: 'win32', - bits: 32 + bits: 32, } as const; - await verify(query, 'https://fastdl.mongodb.org/win32/mongodb-win32-i386-3.0.7.zip'); + await verify( + query, + 'https://fastdl.mongodb.org/win32/mongodb-win32-i386-3.0.7.zip' + ); }); - it('should resolve 4.2.1 (64-bit)', async function() { + it('should resolve 4.2.1 (64-bit)', async function () { const query = { version: '4.2.1', platform: 'win32', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.1.zip'); + await verify( + query, + 'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.1.zip' + ); }); - it('should resolve stable (64-bit)', async function() { + it('should resolve stable (64-bit)', async function () { const query = { version: 'stable', platform: 'win32', - bits: 64 + bits: 64, } as const; await verify(query, kUnknownUrl); }); }); - describe('osx', function() { - it('should resolve 3.1.19 enterprise', async function() { + describe('osx', function () { + it('should resolve 3.1.19 enterprise', async function () { const query = { version: '3.1.9', platform: 'osx', enterprise: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/osx/mongodb-osx-x86_64-enterprise-3.1.9.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/osx/mongodb-osx-x86_64-enterprise-3.1.9.tgz' + ); }); - it('should resolve 3.6.8', async function() { + it('should resolve 3.6.8', async function () { const query = { version: '3.6.8', platform: 'osx', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.8.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.8.tgz' + ); }); - it('should resolve 4.0.3', async function() { + it('should resolve 4.0.3', async function () { const query = { version: '4.0.3', platform: 'osx', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.3.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.3.tgz' + ); }); - it('should resolve 4.1.3', async function() { + it('should resolve 4.1.3', async function () { const query = { version: '4.1.3', platform: 'osx', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.1.3.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.1.3.tgz' + ); }); - it('should resolve 3.5.13 community', async function() { + it('should resolve 3.5.13 community', async function () { const query = { version: '3.5.13', platform: 'osx', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.5.13.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.5.13.tgz' + ); }); - it('should resolve 3.0.0 without ssl', async function() { + it('should resolve 3.0.0 without ssl', async function () { const query = { version: '3.0.0', platform: 'osx', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.0.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.0.0.tgz' + ); }); - it('should resolve 2.6.0 without ssl', async function() { + it('should resolve 2.6.0 without ssl', async function () { const query = { version: '2.6.0', platform: 'osx', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz' + ); }); - it('should resolve 3.2.0 with ssl', async function() { + it('should resolve 3.2.0 with ssl', async function () { const query = { version: '3.2.0', platform: 'osx', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.2.0.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.2.0.tgz' + ); }); - it('should resolve 3.6.0-rc3 with ssl', async function() { + it('should resolve 3.6.0-rc3 with ssl', async function () { const query = { version: '3.6.0-rc3', platform: 'osx', - bits: 64 + bits: 64, } as const; - await verify(query, 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.0-rc3.tgz'); + await verify( + query, + 'https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.0-rc3.tgz' + ); }); }); - describe('version aliases', function() { - it('should resolve `stable`', async function() { + describe('version aliases', function () { + it('should resolve `stable`', async function () { const query = { - version: 'stable' + version: 'stable', }; await verify(query, kUnknownUrl); }); - it('should resolve `unstable`', async function() { + it('should resolve `unstable`', async function () { const query = { - version: 'unstable' + version: 'unstable', }; await verify(query, kUnknownUrl); }); - it('should resolve `latest`', async function() { + it('should resolve `latest`', async function () { const query = { - version: 'latest' + version: 'latest', }; await verify(query, kUnknownUrl); }); - it('should resolve `rapid`', async function() { + it('should resolve `rapid`', async function () { const query = { - version: 'rapid' + version: 'rapid', }; await verify(query, kUnknownUrl); }); - it('should resolve `latest-alpha` for macos arm64', async function() { + it('should resolve `latest-alpha` for macos arm64', async function () { const query = { version: 'latest-alpha', platform: 'macos', enterprise: true, - arch: 'aarch64' + arch: 'aarch64', }; - await verify(query, 'https://downloads.mongodb.com/osx/mongodb-macos-arm64-enterprise-latest.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/osx/mongodb-macos-arm64-enterprise-latest.tgz' + ); }); - it('should resolve `latest-alpha` for macos x64', async function() { + it('should resolve `latest-alpha` for macos x64', async function () { const query = { version: 'latest-alpha', platform: 'macos', enterprise: true, - arch: 'x64' + arch: 'x64', }; - await verify(query, 'https://downloads.mongodb.com/osx/mongodb-macos-x86_64-enterprise-latest.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/osx/mongodb-macos-x86_64-enterprise-latest.tgz' + ); }); - it('should resolve `latest-alpha` for windows', async function() { + it('should resolve `latest-alpha` for windows', async function () { const query = { version: 'latest-alpha', platform: 'windows', enterprise: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/windows/mongodb-windows-x86_64-enterprise-latest.zip'); + await verify( + query, + 'https://downloads.mongodb.com/windows/mongodb-windows-x86_64-enterprise-latest.zip' + ); }); - it('should resolve `latest-alpha` for linux', async function() { + it('should resolve `latest-alpha` for linux', async function () { const query = { version: 'latest-alpha', platform: 'linux', distro: 'ubuntu2004', enterprise: true, - bits: 64 + bits: 64, } as const; - await verify(query, 'https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-ubuntu2004-latest.tgz'); + await verify( + query, + 'https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-ubuntu2004-latest.tgz' + ); }); }); - describe('options', function() { - it('should handle empty options', async function() { + describe('options', function () { + it('should handle empty options', async function () { await verify({}, kUnknownUrl); }); - it('should handle no options at all', async function() { + it('should handle no options at all', async function () { await verify(undefined, kUnknownUrl); }); - it('should handle a version string input', async function() { + it('should handle a version string input', async function () { await verify('7.0.11', kUnknownUrl); }); - it('should use the MONGODB_VERSION environment variable for version', async function() { + it('should use the MONGODB_VERSION environment variable for version', async function () { process.env.MONGODB_VERSION = '3.0.7'; const query = { platform: 'win32', - bits: 32 + bits: 32, } as const; - await verify(query, 'https://fastdl.mongodb.org/win32/mongodb-win32-i386-3.0.7.zip'); + await verify( + query, + 'https://fastdl.mongodb.org/win32/mongodb-win32-i386-3.0.7.zip' + ); delete process.env.MONGODB_VERSION; }); }); - describe('errors', function() { - it('fails for bad versions', async function() { + describe('errors', function () { + it('fails for bad versions', async function () { const query = { - version: '123.456.789' + version: '123.456.789', }; - await assert.rejects(() => verify(query, kUnknownUrl), /Could not find version matching/); + await assert.rejects( + () => verify(query, kUnknownUrl), + /Could not find version matching/ + ); }); - it('fails for bad download specifiers', async function() { + it('fails for bad download specifiers', async function () { const query = { version: '1.0.0', - enterprise: true + enterprise: true, }; - await assert.rejects(() => verify(query, kUnknownUrl), /Could not find download URL for/); + await assert.rejects( + () => verify(query, kUnknownUrl), + /Could not find download URL for/ + ); }); }); - describe('full.json cache', function() { - let tmpdir, cachePath; - let server, versionListUrl, currentFakeVersion, baseOptions; + describe('full.json cache', function () { + let tmpdir: PathLike, cachePath: PathLike; + let server: http.Server, + versionListUrl: string, + currentFakeVersion: string, + baseOptions: Options; function fakeVersion(version: string) { return { @@ -781,38 +974,48 @@ describe('mongodb-download-url', function() { edition: 'targeted', arch: 'x64', archive: { - url: `${versionListUrl}${version}.tgz` - } - } - ] - } - ] + url: `${versionListUrl}${version}.tgz`, + }, + }, + ], + }, + ], }; } - beforeEach(async function() { + beforeEach(async function () { currentFakeVersion = '1.2.1'; - tmpdir = path.join(__dirname, '..', 'tmp-' + Date.now()); + tmpdir = path.join(__dirname, '..', `tmp-${Date.now()}`); cachePath = path.join(tmpdir, 'mongodb-full-json-cache.gz'); await fs.mkdir(tmpdir, { recursive: true }); await clearCache(''); // Clear in-memory cache. - server = http.createServer((req, res) => { - res.writeHead(200, { 'Content-Type': 'application/json' }); - res.end(JSON.stringify(fakeVersion(currentFakeVersion))); - }).listen(0); + server = http + .createServer((req, res) => { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify(fakeVersion(currentFakeVersion))); + }) + .listen(0); await once(server, 'listening'); - versionListUrl = `http://localhost:${server.address().port}/`; - baseOptions = { cachePath, versionListUrl, platform: 'linux', arch: 'x64', distro: 'ubuntu2004' }; + versionListUrl = `http://localhost:${ + (server.address() as AddressInfo).port + }/`; + baseOptions = { + cachePath, + versionListUrl, + platform: 'linux', + arch: 'x64', + distro: 'ubuntu2004', + }; process.umask(0o002); }); - afterEach(async function() { - await fs.rmdir(tmpdir, { recursive: true }); + afterEach(async function () { + await fs.rm(tmpdir, { recursive: true }); await clearCache(''); // Clear in-memory cache. server.close(); process.umask(0o022); }); - it('stores a cache file with mode 0o644', async function() { + it('stores a cache file with mode 0o644', async function () { if (process.platform === 'win32') { return this.skip(); } @@ -820,7 +1023,7 @@ describe('mongodb-download-url', function() { assert.strictEqual((await fs.stat(cachePath)).mode & 0o777, 0o644); }); - it('caches in memory if possible', async function() { + it('caches in memory if possible', async function () { await verify({ ...baseOptions }, `${versionListUrl}1.2.1.tgz`); await fs.stat(cachePath); await fs.unlink(cachePath); @@ -828,20 +1031,26 @@ describe('mongodb-download-url', function() { await assert.rejects(() => fs.stat(cachePath), /ENOENT/); }); - it('reads from disk if in-memory cache is cleared', async function() { + it('reads from disk if in-memory cache is cleared', async function () { await verify({ ...baseOptions }, `${versionListUrl}1.2.1.tgz`); await fs.stat(cachePath); await clearCache(''); - await fs.writeFile(cachePath, zlib.gzipSync(JSON.stringify(fakeVersion('1.2.3')))); + await fs.writeFile( + cachePath, + zlib.gzipSync(JSON.stringify(fakeVersion('1.2.3'))) + ); await verify({ ...baseOptions }, `${versionListUrl}1.2.3.tgz`); }); - it('does not write to disk if requested not to', async function() { - await verify({ ...baseOptions, cacheTimeMs: 0 }, `${versionListUrl}1.2.1.tgz`); + it('does not write to disk if requested not to', async function () { + await verify( + { ...baseOptions, cacheTimeMs: 0 }, + `${versionListUrl}1.2.1.tgz` + ); await assert.rejects(() => fs.stat(cachePath), /ENOENT/); }); - it('refuses to read the disk cache if permissions are insecure', async function() { + it('refuses to read the disk cache if permissions are insecure', async function () { if (process.platform === 'win32') { return this.skip(); } @@ -849,11 +1058,15 @@ describe('mongodb-download-url', function() { await fs.stat(cachePath); await clearCache(''); await fs.unlink(cachePath); - await fs.writeFile(cachePath, zlib.gzipSync(JSON.stringify(fakeVersion('1.2.3'))), { mode: 0o666 }); + await fs.writeFile( + cachePath, + zlib.gzipSync(JSON.stringify(fakeVersion('1.2.3'))), + { mode: 0o666 } + ); await verify({ ...baseOptions }, `${versionListUrl}1.2.1.tgz`); }); - it('refuses to read the disk cache if it is outdated', async function() { + it('refuses to read the disk cache if it is outdated', async function () { await verify({ ...baseOptions }, `${versionListUrl}1.2.1.tgz`); await fs.stat(cachePath); await clearCache('');