-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable plugin if a key is not specified
- Loading branch information
Alexey Melnikov
committed
Jul 15, 2016
1 parent
28ddcb0
commit ab24bc1
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
var Hapi = require('hapi'); | ||
var async = require('async'); | ||
var chai = require('chai'); | ||
chai.should(); | ||
|
||
describe('HAPI with globally registered plugin', function () { | ||
var server; | ||
var max = 5; | ||
var duration = 10000; | ||
|
||
beforeEach(function() { | ||
server = new Hapi.Server(); | ||
server.connection({port: 8000}); | ||
|
||
var options = { | ||
redis: { | ||
host: process.env.REDIS_HOST, | ||
port: 6379 | ||
}, | ||
getKey: function (request, reply, done) { | ||
done(); | ||
}, | ||
getLimit: function (request, reply, done) { | ||
done(null, { | ||
max: max, | ||
duration: duration | ||
}); | ||
} | ||
}; | ||
|
||
server.register({ | ||
register: require('../'), | ||
options: options | ||
}, function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
}); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/', | ||
handler: function (request, reply) { | ||
reply('OK'); | ||
} | ||
}); | ||
}); | ||
|
||
it("should disable limits if the key is not determined", function (done) { | ||
var options = { | ||
method: "GET", | ||
url: "/" | ||
}; | ||
|
||
server.inject(options, function (response) { | ||
response.statusCode.should.equal(200); | ||
|
||
response.headers.should.not.have.property('x-ratelimit-limit'); | ||
response.headers.should.not.have.property('x-ratelimit-remaining'); | ||
response.headers.should.not.have.property('x-ratelimit-reset'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
}); |