Skip to content

Commit

Permalink
allow for asynchronous retrieval of credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Jan 12, 2015
1 parent 99fac26 commit 02065f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
11 changes: 8 additions & 3 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ var server = new Hapi.Server({connections: { routes: { security: true } } });
server.connection({ routes: { cors: true } }).route(routes);

var fuzzerOptions = {
credentials: {
username: 'default',
password: 'letmein'
credentials: function (callback) {
setTimeout(function () {
callback(null, { username: 'default', password: 'letmein' });
}, 1000);
},
// credentials: {
// username: 'default',
// password: 'letmein'
// },
maxIterations: 100
};

Expand Down
26 changes: 24 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@ var internals = {};
internals.factory = function (server, options) {

this.server = server;
this.credentials = options.credentials;
this.table = routeParser.getConnectionsData(server)[0].table;
this.log = server.log.bind(server);
this.iterations = options.iterations || 100;

if (typeof options.credentials === 'function') {
this.waiting = true;
options.credentials(function (err, credentials) {

if (err) {
throw err;
}

this.credentials = credentials;
this.waiting = false;
}.bind(this));
}
else {
this.credentials = options.credentials;
}
};

internals.factory.prototype.seed = function (param) {
Expand All @@ -27,7 +42,14 @@ internals.factory.prototype.fuzzParam = function (param) {
internals.factory.prototype.fuzz = function (callback) {

var self = this;
var table = this.table.filter(function (route) {
if (self.waiting) {
return setTimeout(function () {

self.fuzz(callback);
}, 100);
}

var table = self.table.filter(function (route) {
return Hoek.reach(route, 'queryParams.children') ||
Hoek.reach(route, 'payloadParams.children') ||
Hoek.reach(route, 'pathParams.children');
Expand Down

0 comments on commit 02065f2

Please sign in to comment.