Skip to content
This repository has been archived by the owner on Jan 7, 2018. It is now read-only.

Commit

Permalink
Fix unlimited rate limit on APIs not working for users with settings.
Browse files Browse the repository at this point in the history
An API with an unlimited rate limit mode was not being applied when a
user had been edited in the admin and had a default rate limit selected.
In this case, the "null" value for the rate_limit_mode at the user-level
was overwriting the "unlimited" value that should have been taking
precedent at the API level.
  • Loading branch information
GUI committed Mar 19, 2015
1 parent 5e011ae commit 0b0ec82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/gatekeeper/middleware/api_key_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ _.extend(ApiKeyValidatorRequest.prototype, {
this.request.apiUmbrellaGatekeeper.user = user;

if(user.settings) {
// Delete a "null" value for a user-specific rate limit mode, since
// we don't want that to overwrite the API-specific settings during
// the settings merge.
if(user.settings.rate_limit_mode === null) {
delete user.settings.rate_limit_mode;
}

request.apiUmbrellaGatekeeper.originalUserSettings = cloneDeep(user.settings);
mergeOverwriteArrays(request.apiUmbrellaGatekeeper.settings, user.settings);
}
Expand Down
15 changes: 15 additions & 0 deletions test/server/rate_limiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,21 @@ describe('ApiUmbrellaGatekeper', function() {
});

itBehavesLikeUnlimitedRateLimits('/hello', 5);

describe('user with settings object present, but null rate_limit mode', function() {
beforeEach(function setupApiUser(done) {
Factory.create('api_user', {
settings: {
rate_limit_mode: null,
}
}, function(user) {
this.apiKey = user.api_key;
done();
}.bind(this));
});

itBehavesLikeUnlimitedRateLimits('/hello', 5);
});
});

describe('api specific limits', function() {
Expand Down

0 comments on commit 0b0ec82

Please sign in to comment.