Skip to content

Commit

Permalink
Fix reporting error for incomplete credentials
Browse files Browse the repository at this point in the history
- Add test for completely missing credentials
- Add test for partially missing credentials (eg. user is defined, but
  password is missing)
- Fix reporting "Missing credentials" error for only partially defined
  credentials
  • Loading branch information
iiska committed Nov 13, 2017
1 parent 9e0e926 commit e217417
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/smtp-connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class SMTPConnection extends EventEmitter {
this._authMethod = (this._supportedAuth[0] || 'PLAIN').toUpperCase().trim();
}

if (this._authMethod !== 'XOAUTH2' && !this._auth.credentials) {
if (this._authMethod !== 'XOAUTH2' && (!this._auth.credentials || !this._auth.credentials.user || !this._auth.credentials.pass)) {
if (this._auth.user && this._auth.pass) {
this._auth.credentials = {
user: this._auth.user,
Expand Down
38 changes: 38 additions & 0 deletions test/smtp-connection/smtp-connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,44 @@ describe('SMTP-Connection Tests', function() {
);
});

it('should return error for missing credentials', function(done) {
expect(client.authenticated).to.be.false;
client.login(
{
user: 'testuser'
},
function(err) {
expect(err).to.exist;
expect(client.authenticated).to.be.false;
expect(err.message).to.match(/^Missing credentials/);
expect(err.code).to.equal('EAUTH');
expect(err.response).to.be.undefined;
done();
}
);
});

it('should return error for incomplete credentials', function(done) {
expect(client.authenticated).to.be.false;
client.login(
{
user: 'testuser',
credentials: {
user: 'testuser'
}
},
function(err) {
expect(err).to.exist;
expect(client.authenticated).to.be.false;
expect(err.message).to.match(/^Missing credentials/);
expect(err.code).to.equal('EAUTH');
expect(err.response).to.be.undefined;
done();
}
);
});


describe('xoauth2 login', function() {
this.timeout(10 * 1000);
let x2server;
Expand Down

0 comments on commit e217417

Please sign in to comment.