From d9f7c814dde54e1c32fda9154b699937d22e9085 Mon Sep 17 00:00:00 2001 From: Christian Holbrook Date: Wed, 13 Dec 2023 08:09:10 -0700 Subject: [PATCH 1/3] Update wrong host password error message --- src/RokuDeploy.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/RokuDeploy.ts b/src/RokuDeploy.ts index 9d6e93a..51e7535 100644 --- a/src/RokuDeploy.ts +++ b/src/RokuDeploy.ts @@ -657,7 +657,8 @@ export class RokuDeploy { } if (results.response.statusCode === 401) { - throw new errors.UnauthorizedDeviceResponseError('Unauthorized. Please verify username and password for target Roku.', results); + const host = results?.response?.request?.host?.toString?.(); + throw new errors.UnauthorizedDeviceResponseError(`Unauthorized. Please verify credentials for host '${host}'`, results); } let rokuMessages = this.getRokuMessagesFromResponseBody(results.body); From 5a877a715d2e8fb4a7fc7af843785a85d1289965 Mon Sep 17 00:00:00 2001 From: Christian Holbrook Date: Wed, 13 Dec 2023 10:20:44 -0700 Subject: [PATCH 2/3] Fix unit test to look for the updated message --- src/RokuDeploy.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RokuDeploy.spec.ts b/src/RokuDeploy.spec.ts index 8a591ee..a8027d1 100644 --- a/src/RokuDeploy.spec.ts +++ b/src/RokuDeploy.spec.ts @@ -1055,7 +1055,7 @@ describe('index', () => { return rokuDeploy.publish(options).then(() => { assert.fail('Should not have succeeded due to roku server compilation failure'); }, (err) => { - expect(err.message).to.equal('Unauthorized. Please verify username and password for target Roku.'); + expect(err.message).to.be.a('string').and.satisfy(msg => msg.startsWith('Unauthorized. Please verify credentials for host')); expect(true).to.be.true; }); }); From 1130e5767be6425f977f9eb3b8ada67c62389318 Mon Sep 17 00:00:00 2001 From: Christian Holbrook Date: Wed, 13 Dec 2023 14:08:39 -0700 Subject: [PATCH 3/3] Get 100% code coverage --- src/RokuDeploy.spec.ts | 15 +++++++++++++++ src/RokuDeploy.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/RokuDeploy.spec.ts b/src/RokuDeploy.spec.ts index a8027d1..d93702f 100644 --- a/src/RokuDeploy.spec.ts +++ b/src/RokuDeploy.spec.ts @@ -1048,6 +1048,21 @@ describe('index', () => { }); }); + it('checkRequest handles edge case', () => { + function doTest(results, hostValue = undefined) { + let error: Error; + try { + rokuDeploy['checkRequest'](results); + } catch (e) { + error = e as any; + } + expect(error.message).to.eql(`Unauthorized. Please verify credentials for host '${hostValue}'`); + } + doTest({ body: 'something', response: { statusCode: 401, request: { host: '1.1.1.1' } } }, '1.1.1.1'); + doTest({ body: 'something', response: { statusCode: 401, request: { host: undefined } } }); + doTest({ body: 'something', response: { statusCode: 401, request: undefined } }); + }); + it('rejects when response contains invalid password status code', () => { options.failOnCompileError = true; mockDoPostRequest('', 401); diff --git a/src/RokuDeploy.ts b/src/RokuDeploy.ts index 51e7535..3a04b2e 100644 --- a/src/RokuDeploy.ts +++ b/src/RokuDeploy.ts @@ -657,7 +657,7 @@ export class RokuDeploy { } if (results.response.statusCode === 401) { - const host = results?.response?.request?.host?.toString?.(); + const host = results.response.request?.host?.toString?.(); throw new errors.UnauthorizedDeviceResponseError(`Unauthorized. Please verify credentials for host '${host}'`, results); }