Skip to content

Commit

Permalink
ocd
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Mar 15, 2012
1 parent 3cf05ce commit 8db84c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
13 changes: 7 additions & 6 deletions lib/connection.js
Expand Up @@ -150,19 +150,20 @@ Connection.prototype.open = function (host, database, port, options, callback) {
var auth = uri.auth.split(':');
this.user = auth[0];
this.pass = auth[1];

// Check hostname for user/pass
} else if (host.match(/@/) && host.split('@').shift().match(/:/)) {
var auth = host.split('@').shift().split(':');
host = host.split('@').pop();
} else if (/@/.test(host) && /:/.test(host.split('@')[0])) {
host = host.split('@');
var auth = host.shift().split(':');
host = host.pop();
this.user = auth[0];
this.pass = auth[1];

// user/pass options
} else if (options && options.user && options.pass) {
this.user = options.user;
this.pass = options.pass;

} else {
this.user = this.pass = undefined;
}
Expand Down
14 changes: 6 additions & 8 deletions test/connection.test.js
Expand Up @@ -237,8 +237,8 @@ module.exports = {
db.host.should.equal('127.0.0.1');
db.port.should.equal(27017);
db.close();
// Test connecting using user/pass in hostname

// Test connecting using user/pass in hostname
db = mongoose.createConnection('aaron:psw@localhost', 'fake', 27000);
db.options.should.be.a('object');
db.options.server.should.be.a('object');
Expand All @@ -251,8 +251,8 @@ module.exports = {
db.host.should.equal('localhost');
db.port.should.equal(27000);
db.close();
// Test connecting using user/pass options

// Test connecting using user/pass options
db = mongoose.createConnection('localhost', 'fake', 27000, {user: 'aaron', pass: 'psw'});
db.options.should.be.a('object');
db.options.server.should.be.a('object');
Expand All @@ -265,8 +265,8 @@ module.exports = {
db.host.should.equal('localhost');
db.port.should.equal(27000);
db.close();
// Test connecting using only user option - which shouldn't work

// Test connecting using only user option - which shouldn't work
db = mongoose.createConnection('localhost', 'fake', 27000, {user: 'no_pass'});
db.options.should.be.a('object');
db.options.server.should.be.a('object');
Expand All @@ -279,8 +279,6 @@ module.exports = {
db.host.should.equal('localhost');
db.port.should.equal(27000);
db.close();


},

'connection.model allows passing a schema': function () {
Expand Down

0 comments on commit 8db84c4

Please sign in to comment.