From 25a0e1cbbc808754685cdb66fe60b646fa21c7b9 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 22 Feb 2021 15:07:44 -0500 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20use=20electron's?= =?UTF-8?q?=20net=20request=20instead=20of=20axios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/desktop/electron-app/src/origin.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ui/desktop/electron-app/src/origin.js b/ui/desktop/electron-app/src/origin.js index 7d85e4466..967b9aebc 100644 --- a/ui/desktop/electron-app/src/origin.js +++ b/ui/desktop/electron-app/src/origin.js @@ -1,4 +1,28 @@ const axios = require('axios'); +const { net } = require('electron') + +const requestTimeoutSeconds = 10; +// Simple promise wrapper around Electron's net.request feature. +// https://www.electronjs.org/docs/api/client-request +const netRequestPromise = url => new Promise((resolve, reject) => { + try { + const request = net.request(url); + // We don't worry about canceling the request timeout timer once a + // request ends because: request.abort() has no effect after a request + // ends and the promise will already have been completed, so a rejection + // has no effect either. + const requestTimeout = + setTimeout(() => { + request.abort(); + reject(new Error('Request timeout')); + }, requestTimeoutSeconds * 1000); + request.on('error', reject); + request.on('response', resolve); + request.end(); + } catch (e) { + reject(e); + } +}); // Provides a singleton class instance to enable a consistent view of // runtime settings across the application. @@ -34,7 +58,8 @@ class RuntimeSettings { // test to see if the origin is API-compatible with the desktop client. const scopesEndpoint = `${origin}/v1/scopes`; try { - await axios.get(scopesEndpoint) + await netRequestPromise(scopesEndpoint); + //await axios.get(scopesEndpoint); } catch (e) { throw new Error(`Origin ${origin} could not be validated.`); } From 6f9fa06d113e2c29224992433d18f4402a17b3cb Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 22 Feb 2021 15:18:01 -0500 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20axios=20de?= =?UTF-8?q?pendency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/desktop/electron-app/package.json | 1 - ui/desktop/electron-app/src/origin.js | 2 -- ui/desktop/electron-app/yarn.lock | 12 ------------ 3 files changed, 15 deletions(-) diff --git a/ui/desktop/electron-app/package.json b/ui/desktop/electron-app/package.json index 69caf84b0..931719eb8 100644 --- a/ui/desktop/electron-app/package.json +++ b/ui/desktop/electron-app/package.json @@ -21,7 +21,6 @@ "forge": "config/forge.config.js" }, "dependencies": { - "axios": "^0.21.1", "electron-devtools-installer": "^3.1.1", "electron-is-dev": "^1.2.0", "electron-squirrel-startup": "^1.0.0", diff --git a/ui/desktop/electron-app/src/origin.js b/ui/desktop/electron-app/src/origin.js index 967b9aebc..cdb640cd2 100644 --- a/ui/desktop/electron-app/src/origin.js +++ b/ui/desktop/electron-app/src/origin.js @@ -1,4 +1,3 @@ -const axios = require('axios'); const { net } = require('electron') const requestTimeoutSeconds = 10; @@ -59,7 +58,6 @@ class RuntimeSettings { const scopesEndpoint = `${origin}/v1/scopes`; try { await netRequestPromise(scopesEndpoint); - //await axios.get(scopesEndpoint); } catch (e) { throw new Error(`Origin ${origin} could not be validated.`); } diff --git a/ui/desktop/electron-app/yarn.lock b/ui/desktop/electron-app/yarn.lock index f885d02d3..b33789d73 100644 --- a/ui/desktop/electron-app/yarn.lock +++ b/ui/desktop/electron-app/yarn.lock @@ -494,13 +494,6 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA== -axios@^0.21.1: - version "0.21.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" - integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== - dependencies: - follow-redirects "^1.10.0" - balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -1335,11 +1328,6 @@ fmix@^0.1.0: dependencies: imul "^1.0.0" -follow-redirects@^1.10.0: - version "1.13.1" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.1.tgz#5f69b813376cee4fd0474a3aba835df04ab763b7" - integrity sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg== - forever-agent@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" From 388a146cda6d98a492a604f9498717d9f9a058d0 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 22 Feb 2021 15:24:16 -0500 Subject: [PATCH 3/3] chore: update changelog --- ui/desktop/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ui/desktop/CHANGELOG.md b/ui/desktop/CHANGELOG.md index 1627a2137..cee2b0afe 100644 --- a/ui/desktop/CHANGELOG.md +++ b/ui/desktop/CHANGELOG.md @@ -3,6 +3,12 @@ Canonical reference for changes, improvements, and bugfixes for Boundary Desktop. +## Next + +### Changes/Deprecations + +- Boundary origin validation now occurs via Electron's built-in net request module, ensuring the validation request is made via chromium's networking library rather than Node's. ([PR](https://github.com/hashicorp/boundary-ui/pull/480)) + ## v1.0.0-alpha (2021.02.16) v1.0.0-alpha is the first release of Boundary Desktop. As a result there are no changes, improvements, or bugfixes from past versions.