Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wrong host password error message #134

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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