Automatically lower-cased usernames #9

Closed
wants to merge 2 commits into from
View
2 node.js/lib/client/apps.js
@@ -34,6 +34,8 @@ Apps.prototype.list = function (username, callback) {
username = this.options.get('username');
}
+ username = username.toLowerCase();
+
this.request('GET', ['apps', username], callback, function (res, result) {
callback(null, result.apps || res.statusCode);
})
View
4 node.js/lib/client/client.js
@@ -43,7 +43,7 @@ Client.prototype.request = function (method, uri /* variable arguments */) {
success = args.pop(),
callback = args.pop(),
body = typeof args[args.length - 1] === 'object' && !Array.isArray(args[args.length - 1]) && args.pop(),
- encoded = new Buffer(this.options.get('username') + ':' + this.options.get('password')).toString('base64'),
+ encoded = new Buffer(this.options.get('username').toLowerCase() + ':' + this.options.get('password')).toString('base64'),
proxy = this.options.get('proxy');
options = {
@@ -118,7 +118,7 @@ Client.prototype.upload = function (uri, contentType, file, callback, success) {
encoded,
proxy = self.options.get('proxy');
- encoded = new Buffer(this.options.get('username') + ':' + this.options.get('password')).toString('base64');
+ encoded = new Buffer(this.options.get('username').toLowerCase() + ':' + this.options.get('password')).toString('base64');
fs.stat(file, function (err, stat) {
if (err) {
View
16 node.js/lib/client/databases.js
@@ -29,7 +29,9 @@ util.inherits(Databases, Client);
// Provisions a database for the user
//
Databases.prototype.create = function (databaseType, databaseName, callback) {
- this.request('POST', ['databases', this.options.get('username'), databaseName], {type:databaseType}, callback, function (res, result) {
+ var username = this.options.get('username').toLowerCase();
+
+ this.request('POST', ['databases', username, databaseName], {type:databaseType}, callback, function (res, result) {
callback(null, result, res);
});
};
@@ -41,7 +43,9 @@ Databases.prototype.create = function (databaseType, databaseName, callback) {
// Gets the metadata for the specified database
//
Databases.prototype.get = function (databaseName, callback) {
- this.request('GET', ['databases', this.options.get('username'), databaseName], callback, function (res, result) {
+ var username = this.options.get('username').toLowerCase();
+
+ this.request('GET', ['databases', username, databaseName], callback, function (res, result) {
callback(null, result);
});
};
@@ -52,7 +56,9 @@ Databases.prototype.get = function (databaseName, callback) {
// Gets the list of databases assigned to the user
//
Databases.prototype.list = function (callback) {
- this.request('GET', ['databases', this.options.get('username')], callback, function (res, result) {
+ var username = this.options.get('username').toLowerCase();
+
+ this.request('GET', ['databases', username], callback, function (res, result) {
callback(null, result);
});
};
@@ -64,7 +70,9 @@ Databases.prototype.list = function (callback) {
// Deprovisions specified database
//
Databases.prototype.destroy = function (databaseName, callback) {
- this.request('DELETE', ['databases', this.options.get('username'), databaseName], callback, function (res, result) {
+ var username = this.options.get('username').toLowerCase();
+
+ this.request('DELETE', ['databases', username, databaseName], callback, function (res, result) {
callback(null, result);
});
}
View
2 node.js/lib/client/helpers.js
@@ -7,7 +7,7 @@
//
exports.defaultUser = function (appName) {
if (appName.search('/') === -1) {
- appName = this.options.get('username') + '/' + appName;
+ appName = this.options.get('username').toLowerCase() + '/' + appName;
}
return appName;
View
2 node.js/lib/client/logs.js
@@ -65,6 +65,8 @@ Logs.prototype.byUser = function (username, amount, callback) {
username = this.options.get('username');
}
+ username = username.toLowerCase();
+
options = {
from: 'NOW-1DAY',
until: 'NOW',
View
12 node.js/lib/client/users.js
@@ -40,7 +40,7 @@ Users.prototype.auth = function (callback) {
// Creates a new user with the properties specified by `user`.
//
Users.prototype.create = function (user, callback) {
- this.request('POST', ['users', user.username], user, callback, function (res, result) {
+ this.request('POST', ['users', user.username.toLowerCase()], user, callback, function (res, result) {
callback();
});
};
@@ -52,7 +52,7 @@ Users.prototype.create = function (user, callback) {
// Checks the availability of the specified `username`.
//
Users.prototype.available = function (username, callback) {
- this.request('GET', ['users', username, 'available'], callback, function (res, result) {
+ this.request('GET', ['users', username.toLowerCase(), 'available'], callback, function (res, result) {
callback(null, result);
});
};
@@ -64,7 +64,7 @@ Users.prototype.available = function (username, callback) {
//
Users.prototype.view = function (username, callback) {
- this.request('GET', ['users', username], callback, function (res, result) {
+ this.request('GET', ['users', username.toLowerCase()], callback, function (res, result) {
callback(null, result);
});
};
@@ -76,7 +76,7 @@ Users.prototype.view = function (username, callback) {
// Confirms the specified `user` by sending the invite code in the `user` specified.
//
Users.prototype.confirm = function (user, callback) {
- this.request('POST', ['users', user.username, 'confirm'], user, callback, function (res, result) {
+ this.request('POST', ['users', user.username.toLowerCase(), 'confirm'], user, callback, function (res, result) {
callback(null, result);
});
};
@@ -94,7 +94,7 @@ Users.prototype.forgot = function (username, params, callback) {
params = {};
}
- this.request('POST', ['users', username, 'forgot'], params, callback, function (res, result) {
+ this.request('POST', ['users', username.toLowerCase(), 'forgot'], params, callback, function (res, result) {
return callback(null, result);
});
};
@@ -107,7 +107,7 @@ Users.prototype.forgot = function (username, params, callback) {
// Update user account information.
//
Users.prototype.update = function (username, object, callback) {
- this.request('PUT', ['users', username], object, callback, function (res, result) {
+ this.request('PUT', ['users', username.toLowerCase()], object, callback, function (res, result) {
callback(null, result);
});
}
View
2 node.js/test/commands/apps-test.js
@@ -16,7 +16,7 @@ vows.describe('apps').addBatch(makeApiCall(
'apps list myUser',
function setup () {
nock('http://api.mockjitsu.com')
- .get('/apps/myUser')
+ .get('/apps/myuser')
.reply(200, {
apps: []
}, { 'x-powered-by': 'Nodejitsu' })
View
2 node.js/test/commands/logs-test.js
@@ -18,7 +18,7 @@ vows.describe('logs').addBatch(makeApiCall(
'logs byUser myUser 50',
function setup () {
nock('http://api.mockjitsu.com')
- .post('/logs/myUser', {
+ .post('/logs/myuser', {
from: "NOW-1DAY",
until: "NOW",
rows: "50"
View
16 node.js/test/commands/users-test.js
@@ -5,43 +5,43 @@ var vows = require('vows'),
vows.describe('users').addBatch(makeApiCall(
'users create',
- { username: 'adam' },
+ { username: 'Adam' },
function setup () {
nock('http://api.mockjitsu.com')
- .post('/users/adam', { username: 'adam' })
+ .post('/users/adam', { username: 'Adam' })
.reply(200, {}, { 'x-powered-by': 'Nodejitsu' })
}
)).addBatch(makeApiCall(
- 'users available eve',
+ 'users available Eve',
function setup () {
nock('http://api.mockjitsu.com')
.get('/users/eve/available')
.reply(200, {}, { 'x-powered-by': 'Nodejitsu' })
}
)).addBatch(makeApiCall(
- 'users view abraham',
+ 'users view Abraham',
function setup () {
nock('http://api.mockjitsu.com')
.get('/users/abraham')
.reply(200, {}, { 'x-powered-by': 'Nodejitsu' })
}
)).addBatch(makeApiCall(
'users confirm',
- { username: 'noah' },
+ { username: 'Noah' },
function setup () {
nock('http://api.mockjitsu.com')
- .post('/users/noah/confirm', { username: 'noah' })
+ .post('/users/noah/confirm', { username: 'Noah' })
.reply(200, {}, { 'x-powered-by': 'Nodejitsu' })
}
)).addBatch(makeApiCall(
- 'users forgot job',
+ 'users forgot Job',
function setup () {
nock('http://api.mockjitsu.com')
.post('/users/job/forgot', {})
.reply(200, {}, { 'x-powered-by': 'Nodejitsu' })
}
)).addBatch(makeApiCall(
- 'users update moses',
+ 'users update Moses',
{ prophet: true },
function setup () {
nock('http://api.mockjitsu.com')