不要怂,就是干,撸起袖子干!

Commit 8aafd1b1 by Mick Hansen

Merge pull request #1351 from saschagehlich/bugfix/authenticate-error

Make sure that sequelize.authenticate() passes the real error instead of squashing it
2 parents 3780d3b7 25ce6567
Showing with 44 additions and 2 deletions
...@@ -405,7 +405,7 @@ module.exports = (function() { ...@@ -405,7 +405,7 @@ module.exports = (function() {
.query('SELECT 1+1 AS result', null, { raw: true, plain: true }) .query('SELECT 1+1 AS result', null, { raw: true, plain: true })
.complete(function(err, result) { .complete(function(err, result) {
if (!!err) { if (!!err) {
emitter.emit('error', new Error('Invalid credentials.')) emitter.emit('error', new Error(err))
} else { } else {
emitter.emit('success') emitter.emit('success')
} }
...@@ -413,6 +413,8 @@ module.exports = (function() { ...@@ -413,6 +413,8 @@ module.exports = (function() {
}).run() }).run()
} }
Sequelize.prototype.validate = Sequelize.prototype.authenticate;
Sequelize.fn = Sequelize.prototype.fn = function (fn) { Sequelize.fn = Sequelize.prototype.fn = function (fn) {
return new Utils.fn(fn, Array.prototype.slice.call(arguments, 1)) return new Utils.fn(fn, Array.prototype.slice.call(arguments, 1))
} }
......
...@@ -59,9 +59,43 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -59,9 +59,43 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
}) })
}) })
describe('with an invalid connection', function() {
beforeEach(function() {
var options = _.extend({}, this.sequelize.options, { port: "99999" })
this.sequelizeWithInvalidConnection = new Sequelize("wat", "trololo", "wow", options)
})
it('triggers the error event', function(done) {
this
.sequelizeWithInvalidConnection
.authenticate()
.complete(function(err, result) {
expect(err).to.not.be.null
done()
})
})
it('triggers the actual adapter error', function(done) {
this
.sequelizeWithInvalidConnection
.authenticate()
.complete(function(err, result) {
if (dialect === 'mariadb') {
expect(err.message).to.match(/Access denied for user/)
} else if (dialect === 'postgres') {
expect(err.message).to.match(/invalid port number/)
} else {
expect(err.message).to.match(/Failed to authenticate/)
}
done()
})
})
})
describe('with invalid credentials', function() { describe('with invalid credentials', function() {
beforeEach(function() { beforeEach(function() {
this.sequelizeWithInvalidCredentials = new Sequelize("omg", "wtf", "lol", this.sequelize.options) this.sequelizeWithInvalidCredentials = new Sequelize("localhost", "wtf", "lol", this.sequelize.options)
}) })
it('triggers the error event', function(done) { it('triggers the error event', function(done) {
...@@ -91,6 +125,12 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -91,6 +125,12 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
}) })
}) })
}) })
describe('validate', function() {
it('is an alias for .authenticate()', function() {
expect(this.sequelize.validate).to.equal(this.sequelize.authenticate)
})
})
} }
describe('getDialect', function() { describe('getDialect', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!