Merge pull request +15437 from c9/docker-rate-limit-activate

Docker rate limit activate and create
pull/374/merge
Fabian Jakobs 2017-06-06 12:09:56 +02:00 zatwierdzone przez GitHub
commit bbc7c703fc
2 zmienionych plików z 15 dodań i 0 usunięć

3
node_modules/c9/ratelimit.js wygenerowano vendored
Wyświetl plik

@ -38,6 +38,9 @@ function ratelimit(key, duration, max) {
// Returns a deep value from an object. E.g. resolveValue({user: {id: 5}}, "user.id") === 5
function resolveValue(obj, path) {
if (path === "*")
return "*";
return path.split('.').reduce(function(prev, curr) {
return prev ? prev[curr] : undefined;
}, obj);

12
node_modules/c9/ratelimit_test.js wygenerowano vendored
Wyświetl plik

@ -47,6 +47,18 @@ describe("ratelimit", function() {
});
});
it("Should work with wildcard", function (done) {
var limiter = ratelimit("*", 100, 1);
limiter({params: {user: {id: "hey"}}}, null, function (err) {
assert(!err, err);
limiter({}, null, function (err) {
assert(err);
assert.equal(err.code, 429);
done();
});
});
});
it("Should work with parameters directly on req, if req is specified as the first part of the deep key", function (done) {
var limiter = ratelimit("req.user.id", 100, 1);
limiter({user: {id: "hey"}}, null, function (err) {