@vscode/test-electron
Advanced tools
Comparing version 2.3.6 to 2.3.7
# Changelog | ||
### 2.3.7 | 2022-11-23 | ||
- Remove detection for unsupported win32 builds | ||
- Add length and hash validation for downloaded builds | ||
### 2.3.6 | 2022-10-24 | ||
@@ -4,0 +9,0 @@ |
@@ -19,3 +19,3 @@ import { ProgressReporter } from './progress'; | ||
export declare type DownloadVersion = StringLiteralUnion<'insiders' | 'stable'>; | ||
export declare type DownloadPlatform = StringLiteralUnion<'darwin' | 'darwin-arm64' | 'win32-archive' | 'win32-x64-archive' | 'linux-x64' | 'linux-arm64' | 'linux-armhf'>; | ||
export declare type DownloadPlatform = StringLiteralUnion<'darwin' | 'darwin-arm64' | 'win32-x64-archive' | 'win32-arm64-archive' | 'linux-x64' | 'linux-arm64' | 'linux-armhf'>; | ||
export interface DownloadOptions { | ||
@@ -22,0 +22,0 @@ readonly cachePath: string; |
@@ -12,2 +12,3 @@ "use strict"; | ||
const path = require("path"); | ||
const semver = require("semver"); | ||
const stream_1 = require("stream"); | ||
@@ -17,3 +18,2 @@ const util_1 = require("util"); | ||
const request = require("./request"); | ||
const semver = require("semver"); | ||
const util_2 = require("./util"); | ||
@@ -145,2 +145,3 @@ const extensionRoot = process.cwd(); | ||
} | ||
const contentSHA256 = res.headers['x-sha256']; | ||
res.destroy(); | ||
@@ -184,3 +185,8 @@ const download = await request.getStream(url, timeout); | ||
}); | ||
return { stream: download, format: isZip ? 'zip' : 'tgz' }; | ||
return { | ||
stream: download, | ||
format: isZip ? 'zip' : 'tgz', | ||
sha256: contentSHA256, | ||
length: totalBytes, | ||
}; | ||
} | ||
@@ -190,4 +196,5 @@ /** | ||
*/ | ||
async function unzipVSCode(reporter, extractDir, stream, platform, format) { | ||
async function unzipVSCode(reporter, extractDir, platform, { format, stream, length, sha256 }) { | ||
const stagingFile = path.join(os_1.tmpdir(), `vscode-test-${Date.now()}.zip`); | ||
const checksum = util_2.validateStream(stream, length, sha256); | ||
if (format === 'zip') { | ||
@@ -203,2 +210,3 @@ try { | ||
const [buffer, JSZip] = await Promise.all([util_2.streamToBuffer(stream), Promise.resolve().then(() => require('jszip'))]); | ||
await checksum; | ||
const content = await JSZip.loadAsync(buffer); | ||
@@ -223,2 +231,3 @@ // extract file with jszip | ||
await pipelineAsync(stream, fs.createWriteStream(stagingFile)); | ||
await checksum; | ||
await spawnDecompressorChild('unzip', ['-q', stagingFile, '-d', extractDir]); | ||
@@ -239,2 +248,3 @@ } | ||
await spawnDecompressorChild('tar', ['-xzf', '-', `--strip-components=${s}`, '-C', extractDir], stream); | ||
await checksum; | ||
} | ||
@@ -285,2 +295,5 @@ } | ||
} | ||
if (platform === 'win32-archive' && semver.satisfies(version, '>= 1.85.0', { includePrerelease: true })) { | ||
throw new Error('Windows 32-bit is no longer supported from v1.85 onwards'); | ||
} | ||
reporter.report({ stage: progress_1.ProgressReportStage.ResolvedVersion, version }); | ||
@@ -329,3 +342,3 @@ const downloadedPath = path.resolve(cachePath, makeDownloadDirName(platform, version)); | ||
await fs.promises.rm(downloadedPath, { recursive: true, force: true }); | ||
const { stream, format } = await downloadVSCodeArchive({ | ||
const download = await downloadVSCodeArchive({ | ||
version, | ||
@@ -339,3 +352,3 @@ platform, | ||
// to start consuming the stream immediately. | ||
await unzipVSCode(reporter, downloadedPath, stream, platform, format); | ||
await unzipVSCode(reporter, downloadedPath, platform, download); | ||
await fs.promises.writeFile(path.join(downloadedPath, COMPLETE_FILE_NAME), ''); | ||
@@ -342,0 +355,0 @@ reporter.report({ stage: progress_1.ProgressReportStage.NewInstallComplete, downloadedPath }); |
@@ -14,4 +14,4 @@ "use strict"; | ||
'darwin-arm64', | ||
'win32-archive', | ||
'win32-x64-archive', | ||
'win32-arm64-archive', | ||
'linux-x64', | ||
@@ -74,3 +74,3 @@ 'linux-arm64', | ||
cachePath: path_1.join(extensionsDevelopmentPath, '.cache'), | ||
platform: 'win32-archive', | ||
platform: 'win32-x64-archive', | ||
timeout: 5000, | ||
@@ -77,0 +77,0 @@ extensionsDevelopmentPath: paths.map((p) => path_1.join(extensionsDevelopmentPath, p)), |
@@ -27,3 +27,2 @@ import { DownloadVersion, DownloadPlatform } from './download'; | ||
* Possible values are: | ||
* - `win32-archive` | ||
* - `win32-x64-archive` | ||
@@ -30,0 +29,0 @@ * - `win32-arm64-archive ` |
@@ -54,2 +54,9 @@ /// <reference types="node" /> | ||
export declare function isDefined<T>(arg: T | undefined | null): arg is T; | ||
/** | ||
* Validates the stream data matches the given length and checksum, if any. | ||
* | ||
* Note: md5 is not ideal, but it's what we get from the CDN, and for the | ||
* purposes of self-reported content verification is sufficient. | ||
*/ | ||
export declare function validateStream(readable: NodeJS.ReadableStream, length: number, sha256?: string): Promise<void>; | ||
/** Gets a Buffer from a Node.js stream */ | ||
@@ -56,0 +63,0 @@ export declare function streamToBuffer(readable: NodeJS.ReadableStream): Promise<Buffer>; |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.killTree = exports.onceWithoutRejections = exports.isSubdirectory = exports.streamToBuffer = exports.isDefined = exports.resolveCliArgsFromVSCodeExecutablePath = exports.resolveCliPathFromVSCodeExecutablePath = exports.getLatestInsidersMetadata = exports.getInsidersVersionMetadata = exports.insidersDownloadDirMetadata = exports.insidersDownloadDirToExecutablePath = exports.downloadDirToExecutablePath = exports.urlToOptions = exports.getVSCodeDownloadUrl = exports.isStableVersionIdentifier = exports.isInsiderVersionIdentifier = exports.systemDefaultPlatform = void 0; | ||
exports.killTree = exports.onceWithoutRejections = exports.isSubdirectory = exports.streamToBuffer = exports.validateStream = exports.isDefined = exports.resolveCliArgsFromVSCodeExecutablePath = exports.resolveCliPathFromVSCodeExecutablePath = exports.getLatestInsidersMetadata = exports.getInsidersVersionMetadata = exports.insidersDownloadDirMetadata = exports.insidersDownloadDirToExecutablePath = exports.downloadDirToExecutablePath = exports.urlToOptions = exports.getVSCodeDownloadUrl = exports.isStableVersionIdentifier = exports.isInsiderVersionIdentifier = exports.systemDefaultPlatform = void 0; | ||
const child_process_1 = require("child_process"); | ||
@@ -17,3 +17,4 @@ const fs_1 = require("fs"); | ||
const runTest_1 = require("./runTest"); | ||
const windowsPlatforms = new Set(['win32-archive', 'win32-x64-archive', 'win32-arm64-archive']); | ||
const crypto_1 = require("crypto"); | ||
const windowsPlatforms = new Set(['win32-x64-archive', 'win32-arm64-archive']); | ||
const darwinPlatforms = new Set(['darwin-arm64', 'darwin']); | ||
@@ -25,8 +26,3 @@ switch (process.platform) { | ||
case 'win32': | ||
exports.systemDefaultPlatform = | ||
process.arch === 'arm64' | ||
? 'win32-arm64-archive' | ||
: process.arch === 'ia32' | ||
? 'win32-archive' | ||
: 'win32-x64-archive'; | ||
exports.systemDefaultPlatform = process.arch === 'arm64' ? 'win32-arm64-archive' : 'win32-x64-archive'; | ||
break; | ||
@@ -139,2 +135,5 @@ default: | ||
function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath, platform = exports.systemDefaultPlatform) { | ||
if (platform === 'win32-archive') { | ||
throw new Error('Windows 32-bit is no longer supported'); | ||
} | ||
if (windowsPlatforms.has(platform)) { | ||
@@ -195,2 +194,30 @@ if (vscodeExecutablePath.endsWith('Code - Insiders.exe')) { | ||
exports.isDefined = isDefined; | ||
/** | ||
* Validates the stream data matches the given length and checksum, if any. | ||
* | ||
* Note: md5 is not ideal, but it's what we get from the CDN, and for the | ||
* purposes of self-reported content verification is sufficient. | ||
*/ | ||
function validateStream(readable, length, sha256) { | ||
let actualLen = 0; | ||
const checksum = sha256 ? crypto_1.createHash('sha256') : undefined; | ||
return new Promise((resolve, reject) => { | ||
readable.on('data', (chunk) => { | ||
checksum === null || checksum === void 0 ? void 0 : checksum.update(chunk); | ||
actualLen += chunk.length; | ||
}); | ||
readable.on('error', reject); | ||
readable.on('end', () => { | ||
if (actualLen !== length) { | ||
return reject(new Error(`Downloaded stream length ${actualLen} does not match expected length ${length}`)); | ||
} | ||
const digest = checksum === null || checksum === void 0 ? void 0 : checksum.digest('hex'); | ||
if (digest && digest !== sha256) { | ||
return reject(new Error(`Downloaded file checksum ${digest} does not match expected checksum ${sha256}`)); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
exports.validateStream = validateStream; | ||
/** Gets a Buffer from a Node.js stream */ | ||
@@ -197,0 +224,0 @@ function streamToBuffer(readable) { |
{ | ||
"name": "@vscode/test-electron", | ||
"version": "2.3.6", | ||
"version": "2.3.7", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "compile": "tsc -p ./", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84070
1471