setAuth() should fail with error on non-204 response #25

Merged
merged 1 commit into from Dec 21, 2011

Conversation

Projects
None yet
2 participants

For some reason, when the request initiated by setAuth() returns a non-204 response (ie. 401 due to invalid api key, etc), no error is being returned and authorized is being set to true, even though all the config items (serverUrl, setStorageUrl, cdnUrl, etc) are undefined because of the unauthorized response. This leads to unexpected behavior since you're assuming you have authorization.

Relevant lines (lib/cloudfiles/core.js:62-75):

request(authOptions, function (err, res, body) {
  if (err) {
    return callback(err); 
  }

  self.authorized = true;
  self.config.serverUrl = res.headers['x-server-management-url'];
  self.config.setStorageUrl(res.headers['x-storage-url']);
  self.config.cdnUrl = res.headers['x-cdn-management-url'];
  self.config.authToken = res.headers['x-auth-token'];
  self.config.storageToken = res.headers['x-storage-token']

  callback(null, res, self.config);
});

We should probably also be checking that the res.statusCode is equal to 200, as per the documentation for request:

var request = require('request');
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print the google web page.
  }
})

@bmeck bmeck added a commit that referenced this pull request Dec 21, 2011

@bmeck bmeck Merge pull request #25 from kainosnoema/fix/setAuth-error
setAuth() should fail with error on non-204 response
f5654ea

@bmeck bmeck merged commit f5654ea into nodejitsu:master Dec 21, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment