Skip to content

Commit

Permalink
Update wrong host password error message (#134)
Browse files Browse the repository at this point in the history
* Update wrong host password error message

* Fix unit test to look for the updated message

* Get 100% code coverage
  • Loading branch information
Christian-Holbrook authored Dec 14, 2023
1 parent 06cd6e7 commit 1ca7f51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,14 +1048,29 @@ 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);

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;
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1ca7f51

Please sign in to comment.