Webmaker-auth has been updated to make testing things that need a login much, much easier

Michiel Kamermans michiel at mozillafoundation.org
Wed Mar 11 21:10:20 UTC 2015


Hello all,

earlier today we landed a patch in webmaker-auth and released version
1.0.3, which adds a new "testMode" option to the login experience. With
this option set to "true", trying to sign in will let you fill in a random
username and random password, and without ever hitting the login server be
accepted and logged in as user "testuser". Note that this doesn't magically
log you in when you click "sign in" on the client-facing pages, since that
would require a lot more work in each app to bypass the modal windows etc.
and make things really messy, but it does make it possible to automate the
login in process for client testing with things like phantom and slimer
without running additional webmaker components.

[How to use this in the project you're working on if not updated already]

you will typically have an app.js or server.js with code very similar to
the following code:

...
var WebmakerAuth = require("webmaker-auth");
...
  var webmakerAuth = new WebmakerAuth({
    loginURL: env.get("APP_HOSTNAME"),
    authLoginURL: env.get("LOGINAPI"),
    loginHost: env.get("APP_HOSTNAME"),
    secretKey: env.get("SESSION_SECRET"),
    forceSSL: env.get("FORCE_SSL"),
    domain: env.get("COOKIE_DOMAIN"),
    allowCors: env.get("ALLOWED_CORS_DOMAINS") &&
env.get("ALLOWED_CORS_DOMAINS").split(" ")
  });
...

all you'll need to do to make use of the new code is to:

a) update webmaker-auth to at least v1.0.3 (we'll be pushing 1.0.3 it up to
npm in a bit, hopefully by the time you read this mail that has been done),
b) as optional step, add an env var to your environment file that you're
going to use to toggle test mode on or off, and then,
c) extend the WebmakerAuth contstructor in app.js/server.js with whether or
not to run in test mode (if you don't, it'll do exactly the same as it was
already doing):

  var webmakerAuth = new WebmakerAuth({
    ...
    testMode: env.get("USE_FAKE_LOGIN_FOR_THE_WIN")
  });

For dedicated test runner files, this isn't even necessary, since test
runners tend to just want to run without needing external services, so in
those you'd either hardcode the value to "true", or you just fix the
process.env value by using something like the following code before
requiring in the code that sets up the webmaker auth object:

process.env.USE_FAKE_LOGIN_FOR_THE_WIN = true;


That's it. Any questions, you know where the IRC channel is - happy testing!

- Pomax
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/webmaker-dev/attachments/20150311/57f757db/attachment.html>


More information about the Webmaker-dev mailing list