From 705e2734003becf039a24a9d4c995e27603dadc5 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Sat, 20 May 2017 14:47:50 -0400 Subject: [PATCH] fix(GUI): catch EACCES when querying S3 packages (#1463) When the user is behind a firewall, then the HTTP request to query the latest available version from S3 may throw an EACCES error, eventually causing a confusin "You don't have access to this resource" error window. Change-Type: patch Changelog-Entry: Fix "You don't have access to this resource" error at startup when behind a firewall. Fixes: https://github.com/resin-io/etcher/issues/1458 Signed-off-by: Juan Cruz Viotti --- lib/shared/s3-packages.js | 2 ++ tests/shared/s3-packages.spec.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/shared/s3-packages.js b/lib/shared/s3-packages.js index 7fe8f24e..6d770e13 100644 --- a/lib/shared/s3-packages.js +++ b/lib/shared/s3-packages.js @@ -152,6 +152,8 @@ exports.getRemoteVersions = _.memoize((bucketUrl) => { code: 'ECONNRESET' }, { code: 'ECONNREFUSED' + }, { + code: 'EACCES' }, { code: 'ETIMEDOUT' }, () => { diff --git a/tests/shared/s3-packages.spec.js b/tests/shared/s3-packages.spec.js index 3aeedd55..0bbe6f6a 100644 --- a/tests/shared/s3-packages.spec.js +++ b/tests/shared/s3-packages.spec.js @@ -689,6 +689,29 @@ describe('Shared: s3Packages', function() { }); + describe('given EACCES', function() { + + beforeEach(function() { + const error = new Error('EACCES'); + error.code = 'EACCES'; + + this.requestGetAsyncStub = m.sinon.stub(request, 'getAsync'); + this.requestGetAsyncStub.returns(Bluebird.reject(error)); + }); + + afterEach(function() { + this.requestGetAsyncStub.restore(); + }); + + it('should resolve an empty array', function(done) { + s3Packages.getRemoteVersions(s3Packages.BUCKET_URL.PRODUCTION).then((versions) => { + m.chai.expect(versions).to.deep.equal([]); + done(); + }).catch(done); + }); + + }); + }); describe('.getLatestVersion()', function() {