Skip to content
Browse files

[api] lower-case all usernames

  • Loading branch information...
1 parent 2e50cf6 commit c2d9437a86fe32d935542f2006fbb32e6e5e6377 @jfhbrook jfhbrook committed Mar 19, 2012
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);
});
}

3 comments on commit c2d9437

@Marak
Marak commented on c2d9437 Mar 19, 2012

Why would you fix this in the client and not the server? This looks wrong. I don't see how this should be the responsibility of the API client.

@jfhbrook

I agree that it's the ultimate responsibility of the server, but this is something we can push out today without having to deploy new servers.

I'll be digging into the server-side code soon, to see what I can find.

@Marak
Marak commented on c2d9437 Mar 19, 2012

I disagree.

Don't bloat client code unless it's 100% needed. Now we have logic for handling upper-lower in the wrong place.

Take the time to fix it right, don't compound the problem.

Please sign in to comment.
Something went wrong with that request. Please try again.