diff --git a/bin/load_gen b/bin/load_gen index 99f492bfb8c983ea84b5a367f521b8a3dac77df7..3250fa4b347dd5b03f0dd4e0495489b0109ca17c 100755 --- a/bin/load_gen +++ b/bin/load_gen @@ -112,13 +112,11 @@ var activity = { // users add a new email address once every 2 weeks probability: (1.0 / (40 * 14.0)) }, -/* "reauth": { // users must re-authenticate to browser id once a week // (once every two weeks per device) probability: (1.0 / (40 * 7.0)) }, -*/ "signin": { // users sign in using existing authentication material // 8 times a day (once every six hours per device) @@ -271,7 +269,7 @@ function poll() { // start the new activites until they're all started, or until we've // got twice as many outstanding as would be required by the target we - // want to hit (which means the server can't keep up). + // want to hit (which means the server can't keep up). while (newAct >= 1.0 && outstanding < (activitiesPerUserPerSecond * targetActive * 2)) { startNewActivity(); newAct--; diff --git a/lib/load_gen/activities/reauth.js b/lib/load_gen/activities/reauth.js index 6a5085cb9c1769d628376519ea36c4e8e0c4e4cb..59e4913cd2161239da753dba700c7ce35628a93f 100644 --- a/lib/load_gen/activities/reauth.js +++ b/lib/load_gen/activities/reauth.js @@ -39,54 +39,10 @@ * picking an identity */ const -wcli = require("../../libs/wsapi_client.js"), -userdb = require("./user_db.js"), -winston = require('winston'); - -function syncEmails(cfg, context, cb) { - - function keyRefresh(email, cb) { - var keypair = userdb.addKeyToUserCtx(context, email); - wcli.post(cfg, '/wsapi/set_key', context, { - email: email, - pubkey: keypair.pub - }, function (r) { - cb(r.code === 200 && r.body === 'true'); - }); - } - - var emails = {}; - Object.keys(context.keys).forEach(function(e) { emails[e] = context.keys[e].pub }); - wcli.post( - cfg, '/wsapi/sync_emails', context, - { emails: JSON.stringify(emails) }, - function(r) { - if (r.code != 200) { - winston.error('failed to sync emails'); - return cb(false); - } - // now let's sync these emails! - var sr = JSON.parse(r.body); - - // first delete emails we know about that the server doesn't - for (var i = 0; i < sr.unknown_emails; i++) { - delete context.keys[sr.unknown_emails[i]]; - } - - // now refresh the keys for each email mentioned - var complete = 0; - var success = true; - for (var i = 0; i < sr.key_refresh.length; i++) { - keyRefresh(sr.key_refresh[i], function(r) { - sucess = r && success; - if (++complete >= sr.key_refresh.length) { - cb(success); - } - }); - } - if (sr.key_refresh.length === 0) cb(true); - }); -} +common = require("../common.js"), +userdb = require("../user_db.js"), +winston = require('winston'), +wcli = require('../../wsapi_client.js'); exports.startFunc = function(cfg, cb) { // 1. RP includes include.js @@ -105,7 +61,7 @@ exports.startFunc = function(cfg, cb) { if (!user) { winston.warn("can't achieve desired concurrency! not enough users!"); - return cb(false); + return cb("concurrency error"); } // user will be "released" once we're done with her. @@ -126,14 +82,13 @@ exports.startFunc = function(cfg, cb) { // clear cookies from this context (we're going to log in again) wcli.clearCookies(context); - wcli.post( - cfg, '/wsapi/authenticate_user', context, - { email: email, pass: user.password }, - function(r) { - if (r.code != 200 || r.body !== "true") { - winston.error('authentication failure: ' + r.code + "/" + r.body); - return cb(false); - } - syncEmails(cfg, context, cb); + var origin = userdb.any(user.sites); + + // establish session context and authenticate if needed + common.authAndKey(cfg, user, context, email, function(err) { + if (err) return cb(err); + common.genAssertionAndVerify(cfg, user, context, email, origin, function(err) { + cb(err); }); + }); };