From 16c833b2a8de81b0a19ec673ef34aeb9e4304681 Mon Sep 17 00:00:00 2001 From: Liam Bigelow <40188355+bglw@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:41:48 +1200 Subject: [PATCH] Delete old wrapper --- wwrappers/node/.npmrc | 1 - wwrappers/node/LICENSE/LICENSE | 16 - wwrappers/node/LICENSE/LICENSE-vscode-ripgrep | 13 - wwrappers/node/README.md | 3 - wwrappers/node/index.js | 1 - wwrappers/node/jsconfig.json | 8 - wwrappers/node/lib/download.js | 343 ------------------ wwrappers/node/lib/index.js | 31 -- wwrappers/node/lib/postinstall.js | 86 ----- wwrappers/node/package.json | 37 -- 10 files changed, 539 deletions(-) delete mode 100644 wwrappers/node/.npmrc delete mode 100644 wwrappers/node/LICENSE/LICENSE delete mode 100644 wwrappers/node/LICENSE/LICENSE-vscode-ripgrep delete mode 100644 wwrappers/node/README.md delete mode 100644 wwrappers/node/index.js delete mode 100644 wwrappers/node/jsconfig.json delete mode 100644 wwrappers/node/lib/download.js delete mode 100755 wwrappers/node/lib/index.js delete mode 100644 wwrappers/node/lib/postinstall.js delete mode 100644 wwrappers/node/package.json diff --git a/wwrappers/node/.npmrc b/wwrappers/node/.npmrc deleted file mode 100644 index bd3327a..0000000 --- a/wwrappers/node/.npmrc +++ /dev/null @@ -1 +0,0 @@ -//registry.npmjs.org/:_authToken=${NPM_TOKEN} \ No newline at end of file diff --git a/wwrappers/node/LICENSE/LICENSE b/wwrappers/node/LICENSE/LICENSE deleted file mode 100644 index 858918f..0000000 --- a/wwrappers/node/LICENSE/LICENSE +++ /dev/null @@ -1,16 +0,0 @@ -toolproof - -Copyright (c) CloudCannon - -All rights reserved. - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Includes other software related under the MIT license: -- vscode-ripgrep, Copyright Microsoft Corporation. For licensing see /LICENSE/LICENSE-vscode-ripgrep \ No newline at end of file diff --git a/wwrappers/node/LICENSE/LICENSE-vscode-ripgrep b/wwrappers/node/LICENSE/LICENSE-vscode-ripgrep deleted file mode 100644 index 4e2bb26..0000000 --- a/wwrappers/node/LICENSE/LICENSE-vscode-ripgrep +++ /dev/null @@ -1,13 +0,0 @@ -vscode-ripgrep - -Copyright (c) Microsoft Corporation - -All rights reserved. - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/wwrappers/node/README.md b/wwrappers/node/README.md deleted file mode 100644 index 77edde0..0000000 --- a/wwrappers/node/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Toolproof - -The CLI for Toolproof. diff --git a/wwrappers/node/index.js b/wwrappers/node/index.js deleted file mode 100644 index 75933be..0000000 --- a/wwrappers/node/index.js +++ /dev/null @@ -1 +0,0 @@ -console.log("—"); \ No newline at end of file diff --git a/wwrappers/node/jsconfig.json b/wwrappers/node/jsconfig.json deleted file mode 100644 index cca8d94..0000000 --- a/wwrappers/node/jsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "compilerOptions": { - "resolveJsonModule": true, - "lib": [ - "esnext" - ] - } -} \ No newline at end of file diff --git a/wwrappers/node/lib/download.js b/wwrappers/node/lib/download.js deleted file mode 100644 index 5f54183..0000000 --- a/wwrappers/node/lib/download.js +++ /dev/null @@ -1,343 +0,0 @@ -const path = require("path"); -const fs = require("fs"); -const os = require("os"); -const https = require("https"); -const util = require("util"); -const url = require("url"); -const URL = url.URL; -const child_process = require("child_process"); -const proxy_from_env = require("proxy-from-env"); -const { createHash } = require("crypto"); - -const packageVersion = require("../package.json").version; -const cacheDir = path.join(__dirname, `../cache`); -const tmpDir = path.join(cacheDir, packageVersion); - -const fsUnlink = util.promisify(fs.unlink); -const fsExists = util.promisify(fs.exists); -const fsMkdir = util.promisify(fs.mkdir); - -const isWindows = os.platform() === "win32"; - -const REPO = "CloudCannon/toolproof"; - -function downloadWin(url, dest, opts) { - return new Promise((resolve, reject) => { - let userAgent; - if (opts.headers["user-agent"]) { - userAgent = opts.headers["user-agent"]; - delete opts.headers["user-agent"]; - } - const headerValues = Object.keys(opts.headers) - .map((key) => `\\"${key}\\"=\\"${opts.headers[key]}\\"`) - .join("; "); - const headers = `@{${headerValues}}`; - console.log("Downloading with Invoke-WebRequest"); - dest = sanitizePathForPowershell(dest); - let iwrCmd = `[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -URI ${url} -UseBasicParsing -OutFile ${dest} -Headers ${headers}`; - if (userAgent) { - iwrCmd += " -UserAgent " + userAgent; - } - if (opts.proxy) { - iwrCmd += " -Proxy " + opts.proxy; - - try { - const { username, password } = new URL(opts.proxy); - if (username && password) { - const decodedPassword = decodeURIComponent(password); - iwrCmd += ` -ProxyCredential (New-Object PSCredential ('${username}', (ConvertTo-SecureString '${decodedPassword}' -AsPlainText -Force)))`; - } - } catch (err) { - reject(err); - } - } - - iwrCmd = `powershell "${iwrCmd}"`; - - child_process.exec(iwrCmd, (err) => { - if (err) { - reject(err); - return; - } - resolve(); - }); - }); -} - -function download(_url, dest, opts) { - const proxy = proxy_from_env.getProxyForUrl(url.parse(_url)); - if (proxy !== "") { - var HttpsProxyAgent = require("https-proxy-agent"); - opts = { - ...opts, - agent: new HttpsProxyAgent(proxy), - proxy, - }; - } - - if (isWindows) { - // This alternative strategy shouldn't be necessary but sometimes on Windows the file does not get closed, - // so unzipping it fails, and I don't know why. - return downloadWin(_url, dest, opts); - } - - return new Promise((resolve, reject) => { - console.log(`Download options: ${JSON.stringify(opts)}`); - const outFile = fs.createWriteStream(dest); - const mergedOpts = { - ...url.parse(_url), - ...opts, - }; - https - .get(mergedOpts, (response) => { - console.log("statusCode: " + response.statusCode); - if (response.statusCode === 302) { - console.log("Following redirect to: " + response.headers.location); - return download(response.headers.location, dest, opts).then( - resolve, - reject - ); - } else if (response.statusCode !== 200) { - reject(new Error("Download failed with " + response.statusCode)); - return; - } - - response.pipe(outFile); - outFile.on("finish", () => { - resolve(); - }); - }) - .on("error", async (err) => { - await fsUnlink(dest); - reject(err); - }); - }); -} - -function get(_url, opts) { - console.log(`GET ${_url}`); - - const proxy = proxy_from_env.getProxyForUrl(url.parse(_url)); - if (proxy !== "") { - var HttpsProxyAgent = require("https-proxy-agent"); - opts = { - ...opts, - agent: new HttpsProxyAgent(proxy), - }; - } - - return new Promise((resolve, reject) => { - let result = ""; - opts = { - ...url.parse(_url), - ...opts, - }; - https.get(opts, (response) => { - if (response.statusCode !== 200) { - reject(new Error("Request failed: " + response.statusCode)); - } - - response.on("data", (d) => { - result += d.toString(); - }); - - response.on("end", () => { - resolve(result); - }); - - response.on("error", (e) => { - reject(e); - }); - }); - }); -} - -function getApiUrl(repo, tag) { - console.log(`https://api.github.com/repos/${repo}/releases/tags/${tag}`); - return `https://api.github.com/repos/${repo}/releases/tags/${tag}`; -} - -/** - * @param {{ force: boolean; token: string; version: string; }} opts - * @param {string} assetName - * @param {string} downloadFolder - */ -async function getAssetFromGithubApi(opts, assetName, downloadFolder) { - const assetDownloadPath = path.join(downloadFolder, assetName); - - // We can just use the cached binary - if (await fsExists(assetDownloadPath)) { - console.log("Using cached download: " + assetDownloadPath); - return assetDownloadPath; - } - - const downloadOpts = { - headers: { - "user-agent": "toolproof", - }, - }; - - console.log(`Finding release for ${opts.version}`); - const release = await get(getApiUrl(REPO, opts.version), downloadOpts); - let jsonRelease; - try { - jsonRelease = JSON.parse(release); - } catch (e) { - throw new Error("Malformed API response: " + e.stack); - } - - if (!jsonRelease.assets) { - throw new Error("Bad API response: " + JSON.stringify(release)); - } - - const asset = jsonRelease.assets.find((a) => a.name === assetName); - if (!asset) { - throw new Error("Asset not found with name: " + assetName); - } - - console.log(`Downloading from ${asset.url}`); - console.log(`Downloading to ${assetDownloadPath}`); - - downloadOpts.headers.accept = "application/octet-stream"; - await download(asset.url, assetDownloadPath, downloadOpts); -} - -// Handle whitespace in filepath as powershell split's path with whitespaces -function sanitizePathForPowershell(path) { - path = path.replace(/ /g, "` "); // replace whitespace with "` " as solution provided here https://stackoverflow.com/a/18537344/7374562 - return path; -} - -function untar(zipPath, destinationDir) { - return new Promise((resolve, reject) => { - const unzipProc = child_process.spawn( - "tar", - ["xvf", zipPath, "-C", destinationDir], - { stdio: "inherit" } - ); - unzipProc.on("error", (err) => { - reject(err); - }); - unzipProc.on("close", (code) => { - console.log(`tar xvf exited with ${code}`); - if (code !== 0) { - reject(new Error(`tar xvf exited with ${code}`)); - return; - } - - resolve(); - }); - }); -} - -async function unzipBinary(zipPath, destinationDir) { - const expectedName = path.join(destinationDir, "toolproof"); - - if (await fsExists(expectedName)) { - await fsUnlink(expectedName); - } - - if (await fsExists(expectedName + ".exe")) { - await fsUnlink(expectedName + ".exe"); - } - - await untar(zipPath, destinationDir); - - if (await fsExists(expectedName)) { - return expectedName; - } - - if (await fsExists(expectedName + ".exe")) { - return expectedName + ".exe"; - } - - throw new Error( - `Expecting toolproof or toolproof.exe unzipped into ${destinationDir}, didn't find one.` - ); -} - -async function cleanCache() { - return Promise.all( - fs.readdirSync(cacheDir).map((dir) => { - if (dir != packageVersion) { - return fs.promises.rm(path.join(cacheDir, dir), { recursive: true }); - } - }) - ); -} - -function verifyChecksum(assetName, downloadFolder) { - const checksumPath = path.join( - __dirname, - "../checksums", - `${assetName}.sha256` - ); - const releaseSum = fs.readFileSync(checksumPath, "utf8").split(" ")[0]; - - const assetDownloadPath = path.join(downloadFolder, assetName); - const assetBuffer = fs.readFileSync(assetDownloadPath); - const hash = createHash("sha256"); - hash.update(assetBuffer); - const assetSum = hash.digest("hex"); - - if (assetSum !== releaseSum) { - throw new Error("Integrity check failed."); - } -} - -module.exports = async (opts) => { - if (!opts.version) { - return Promise.reject(new Error("Missing version")); - } - - if (!opts.target) { - return Promise.reject(new Error("Missing target")); - } - - const assetName = - ["toolproof", opts.version, opts.target].join("-") + ".tar.gz"; - - if (!(await fsExists(tmpDir))) { - await fsMkdir(tmpDir, { recursive: true }); - } - - const assetDownloadPath = path.join(tmpDir, assetName); - try { - await getAssetFromGithubApi(opts, assetName, tmpDir); - await verifyChecksum(assetName, tmpDir); - } catch (e) { - console.log("Deleting invalid download cache"); - try { - await fsUnlink(assetDownloadPath); - const expectedName = path.join(opts.destDir, "toolproof"); - - if (await fsExists(expectedName)) { - await fsUnlink(expectedName); - } - - if (await fsExists(expectedName + ".exe")) { - await fsUnlink(expectedName + ".exe"); - } - } catch (e) {} - - throw e; - } - - console.log(`Unzipping to ${opts.destDir}`); - try { - const destinationPath = await unzipBinary(assetDownloadPath, opts.destDir); - if (!isWindows) { - await util.promisify(fs.chmod)(destinationPath, "755"); - } - } catch (e) { - console.log("Deleting invalid download"); - - try { - await fsUnlink(assetDownloadPath); - } catch (e) {} - - throw e; - } - - await cleanCache(); -}; diff --git a/wwrappers/node/lib/index.js b/wwrappers/node/lib/index.js deleted file mode 100755 index a5c16cf..0000000 --- a/wwrappers/node/lib/index.js +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env node -const path = require("path"); -const fs = require("fs"); -const { execFileSync } = require("child_process"); - -const binaryPath = path.join( - __dirname, - `../bin/toolproof${process.platform === "win32" ? ".exe" : ""}` -); - -if (!fs.existsSync(binaryPath)) { - console.error( - `Binary failed to download — package expected to have downloaded the binary to ${binaryPath} during its postinstall` - ); - console.error(`Do you have install scripts disabled for npm?`); - console.error( - `Try running \`npm config set ignore-scripts false\` and re-installing.` - ); - console.error( - `Otherwise, your platform might not be supported. Open an issue on GitHub!` - ); - process.exit(1); -} - -try { - execFileSync(binaryPath, process.argv.slice(2), { - stdio: [process.stdin, process.stdout, process.stderr], - }); -} catch (err) { - process.exit(1); -} diff --git a/wwrappers/node/lib/postinstall.js b/wwrappers/node/lib/postinstall.js deleted file mode 100644 index 061189d..0000000 --- a/wwrappers/node/lib/postinstall.js +++ /dev/null @@ -1,86 +0,0 @@ -const os = require("os"); -const fs = require("fs"); -const path = require("path"); -const util = require("util"); -const child_process = require("child_process"); - -const download = require("./download"); - -const fsExists = util.promisify(fs.exists); -const mkdir = util.promisify(fs.mkdir); -const exec = util.promisify(child_process.exec); - -const VERSION = `v${require("../package.json").version}`; -const BIN_PATH = path.join(__dirname, "../bin"); - -process.on("unhandledRejection", (reason, promise) => { - console.log("Unhandled rejection: ", promise, "reason:", reason); -}); - -async function isMusl() { - let stderr; - try { - stderr = (await exec("ldd --version")).stderr; - } catch (err) { - stderr = err.stderr; - } - if (stderr.indexOf("musl") > -1) { - return true; - } - return false; -} - -async function getTarget() { - const arch = process.env.npm_config_arch || os.arch(); - - switch (os.platform()) { - case "darwin": - return arch === "arm64" ? "aarch64-apple-darwin" : "x86_64-apple-darwin"; - case "win32": - return arch === "x64" - ? "x86_64-pc-windows-msvc" - : arch === "arm" - ? "aarch64-pc-windows-msvc" - : "i686-pc-windows-msvc"; - case "linux": - return arch === "x64" - ? "x86_64-unknown-linux-musl" - : arch === "arm" - ? "arm-unknown-linux-gnueabihf" - : arch === "armv7l" - ? "arm-unknown-linux-gnueabihf" - : arch === "arm64" - ? (await isMusl()) - ? "aarch64-unknown-linux-musl" - : "aarch64-unknown-linux-gnu" - : arch === "ppc64" - ? "powerpc64le-unknown-linux-gnu" - : arch === "s390x" - ? "s390x-unknown-linux-gnu" - : "i686-unknown-linux-musl"; - default: - throw new Error("Unknown platform: " + os.platform()); - } -} - -async function main() { - const binExists = await fsExists(BIN_PATH); - - if (!binExists) { - await mkdir(BIN_PATH); - } - - const opts = { - version: VERSION, - target: await getTarget(), - destDir: BIN_PATH, - }; - try { - await download(opts); - } catch (err) { - console.error(`Downloading toolproof failed: ${err.stack}`); - process.exit(1); - } -} - -main(); diff --git a/wwrappers/node/package.json b/wwrappers/node/package.json deleted file mode 100644 index 0adc524..0000000 --- a/wwrappers/node/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "toolproof", - "version": "0.0.0", - "description": "A user-centric testing framework for tools and applications", - "bin": "lib/index.js", - "repository": { - "type": "git", - "url": "https://github.com/CloudCannon/toolproof" - }, - "scripts": { - "postinstall": "node ./lib/postinstall.js" - }, - "author": "@LiamBigelow", - "license": "MIT", - "dependencies": { - "https-proxy-agent": "^5.0.0", - "proxy-from-env": "^1.1.0" - }, - "overrides": { - "agent-base": "^6.0.2" - }, - "keywords": [ - "CloudCannon", - "Cloud", - "Cannon", - "toolproof", - "tool", - "proof", - "testing", - "bdd", - "test" - ], - "bugs": { - "url": "https://github.com/CloudCannon/toolproof/issues" - }, - "homepage": "https://github.com/CloudCannon/toolproof#readme" -} \ No newline at end of file