From e6033a40f5e1a85cf50eeeb7776d57e2ca425fb4 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Tue, 15 Nov 2011 21:40:48 -0700
Subject: [PATCH] incremental porting of loadgen tool to new APIs - issue #504

---
 lib/load_gen/signup.js    | 16 +++++++++-------
 lib/load_gen/test_keys.js |  7 ++++---
 lib/load_gen/user_db.js   | 10 +++++-----
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/lib/load_gen/signup.js b/lib/load_gen/signup.js
index 1589f3ec9..6dd123e40 100644
--- a/lib/load_gen/signup.js
+++ b/lib/load_gen/signup.js
@@ -88,14 +88,11 @@ exports.startFunc = function(cfg, cb) {
   // only one at this point
   var email = userdb.any(user.emails);
 
-  // add a key for the specified email to their device context 
   var keypair = userdb.addKeyToUserCtx(context, email);
 
   // stage them
   wcli.post(cfg, '/wsapi/stage_user', context, {
     email: email,
-    pass: user.password,
-    pubkey: keypair.pub,
     site: userdb.any(user.sites)
   }, function (r) {
     if (r.code !== 200) return cb(false);
@@ -105,13 +102,18 @@ exports.startFunc = function(cfg, cb) {
     }, function (r) {
       if (r.code !== 200) return cb(false);
       // and simulate clickthrough
-      wcli.get(cfg, '/wsapi/prove_email_ownership', context, {
-        token: r.body
+      wcli.post(cfg, '/wsapi/complete_user_creation', context, {
+        token: r.body,
+        pass: user.password
       }, function (r) {
-        if (r.code !== 200 || r.body !== 'true') return cb(false);
+        r.body = JSON.parse(r.body);
+        if (r.code !== 200 || r.body.success !== true) return cb(false);
+
         // and now we should call registration status to complete the
         // process
-        wcli.get(cfg, '/wsapi/registration_status', context, {
+        wcli.post(cfg, '/wsapi/cert_key', context, {
+          email: email,
+          pubkey: keypair.publicKey.toSimpleObject()
         }, function(r) {
           var rv = (r.code === 200 && r.body === '"complete"');
           if (!rv) winston.error("registration_status failed during signup: " + JSON.stringify(r));
diff --git a/lib/load_gen/test_keys.js b/lib/load_gen/test_keys.js
index 3ea881855..7fac6dbab 100644
--- a/lib/load_gen/test_keys.js
+++ b/lib/load_gen/test_keys.js
@@ -5,11 +5,12 @@ const NUM_KEYPAIRS = 10;
 process.stdout.write("generating " + NUM_KEYPAIRS +
                      " keypairs to be (re)used in load generation: ");
 
-var keyPairs = [];
+exports.keyPairs = [];
 
-while (keyPairs.length < NUM_KEYPAIRS)
+while (exports.keyPairs.length < NUM_KEYPAIRS)
 {
-  keyPairs.push(jwk.KeyPair.generate("DS", 256));
+  exports.keyPairs.push(jwk.KeyPair.generate("DS", 256));
   process.stdout.write(".");
 }
+
 process.stdout.write("\n");
diff --git a/lib/load_gen/user_db.js b/lib/load_gen/user_db.js
index 166498355..6b97f3902 100644
--- a/lib/load_gen/user_db.js
+++ b/lib/load_gen/user_db.js
@@ -38,7 +38,9 @@
  * purposes of performance testing. 
  */
 
-var secrets = require('../secrets.js');
+const
+secrets = require('../secrets.js'),
+keys = require("./test_keys.js");
 
 // the grandiose database
 var users = [ ];
@@ -126,9 +128,7 @@ exports.addKeyToUserCtx = function(ctx, email) {
   // this is simulated.  it will need to be real to apply load to
   // the verifier, but that in turn will drastically increase the
   // cost of the application of load.  ho hum.
-  var pub = secrets.generate(128);
-  var priv = secrets.generate(128);
-  var k = {pub: pub, priv: priv}
+  var k = exports.any(keys.keyPairs);
   ctx.keys[email] = k;
   return k;
-}
\ No newline at end of file
+}
-- 
GitLab