From f54aeaf928a92b8180c5343370f3541f206c632f Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Tue, 22 Nov 2011 17:55:32 -0700 Subject: [PATCH] (loadgen) when generating assertions, calculate current server time in the same manner that the webclient does - namely add a delta from session creation time to now to server time - issue #504 --- lib/load_gen/common.js | 8 ++++++-- lib/wsapi_client.js | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/load_gen/common.js b/lib/load_gen/common.js index cfb891898..f26a4dfbc 100644 --- a/lib/load_gen/common.js +++ b/lib/load_gen/common.js @@ -46,7 +46,11 @@ exports.authAndKey = function(cfg, user, ctx, email, cb) { }; exports.genAssertionAndVerify = function(cfg, user, ctx, email, audience, cb) { - var serverTime = new Date(ctx.session.server_time); + // assume server time is different from local time, and simulate what + // the web client does (calculates local delta from session creation time, and + // adds that to server time) + var t = new Date(((new Date()).getTime() - ctx.sessionStartedAt) + ctx.session.server_time); + wcli.get(cfg, '/wsapi/list_emails', ctx, undefined, function (r) { // just verify that we got a JSON object, we don't care about // the contents so much @@ -57,7 +61,7 @@ exports.genAssertionAndVerify = function(cfg, user, ctx, email, audience, cb) { } var assertion = crypto.getAssertion({ - now: serverTime, + now: t, secretKey: ctx.keys[email].keyPair.secretKey, cert: ctx.keys[email].cert, audience: audience, diff --git a/lib/wsapi_client.js b/lib/wsapi_client.js index 7fd111317..ba560f001 100644 --- a/lib/wsapi_client.js +++ b/lib/wsapi_client.js @@ -118,6 +118,7 @@ function withCSRF(cfg, context, cb) { try { if (r.code !== 200) throw 'http error'; context.session = JSON.parse(r.body); + context.sessionStartedAt = new Date().getTime(); cb(context.session.csrf_token); } catch(e) { console.log('error getting csrf token: ', e); -- GitLab