kopia lustrzana https://github.com/c9/core
Merge pull request +15437 from c9/docker-rate-limit-activate
Docker rate limit activate and createpull/374/merge
commit
bbc7c703fc
|
@ -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
|
// Returns a deep value from an object. E.g. resolveValue({user: {id: 5}}, "user.id") === 5
|
||||||
function resolveValue(obj, path) {
|
function resolveValue(obj, path) {
|
||||||
|
if (path === "*")
|
||||||
|
return "*";
|
||||||
|
|
||||||
return path.split('.').reduce(function(prev, curr) {
|
return path.split('.').reduce(function(prev, curr) {
|
||||||
return prev ? prev[curr] : undefined;
|
return prev ? prev[curr] : undefined;
|
||||||
}, obj);
|
}, obj);
|
||||||
|
|
|
@ -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) {
|
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);
|
var limiter = ratelimit("req.user.id", 100, 1);
|
||||||
limiter({user: {id: "hey"}}, null, function (err) {
|
limiter({user: {id: "hey"}}, null, function (err) {
|
||||||
|
|
Ładowanie…
Reference in New Issue