services/fxaccounts/tests/mochitest/file_invalidEmailCase.sjs

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * This server simulates the behavior of /account/login on the Firefox Accounts
     6  * auth server in the case where the user is trying to sign in with an email
     7  * with the wrong capitalization.
     8  *
     9  * https://github.com/mozilla/fxa-auth-server/blob/master/docs/api.md#post-v1accountlogin
    10  *
    11  * The expected behavior is that on the first attempt, with the wrong email,
    12  * the server will respond with a 400 and the canonical email capitalization
    13  * that the client should use.  The client then has one chance to sign in with
    14  * this different capitalization.
    15  *
    16  * In this test, the user with the account id "Greta.Garbo@gmail.COM" initially
    17  * tries to sign in as "greta.garbo@gmail.com".
    18  *
    19  * On success, the client is responsible for updating its sign-in user state
    20  * and recording the proper email capitalization.
    21  */
    23 const CC = Components.Constructor;
    24 const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
    25                              "nsIBinaryInputStream",
    26                              "setInputStream");
    28 const goodEmail = "Greta.Garbo@gmail.COM";
    29 const badEmail = "greta.garbo@gmail.com";
    31 function handleRequest(request, response) {
    32   let body = new BinaryInputStream(request.bodyInputStream);
    33   let bytes = [];
    34   let available;
    35   while ((available = body.available()) > 0) {
    36     Array.prototype.push.apply(bytes, body.readByteArray(available));
    37   }
    39   let data = JSON.parse(String.fromCharCode.apply(null, bytes));
    40   let message;
    42   switch (data.email) {
    43     case badEmail:
    44       // Almost - try again with fixed email case
    45       message = {
    46         code: 400,
    47         errno: 120,
    48         error: "Incorrect email case",
    49         email: goodEmail,
    50       };
    51       response.setStatusLine(request.httpVersion, 400, "Almost");
    52       break;
    54     case goodEmail:
    55       // Successful login.
    56       message = {
    57         uid: "your-uid",
    58         sessionToken: "your-sessionToken",
    59         keyFetchToken: "your-keyFetchToken",
    60         verified: true,
    61         authAt: 1392144866,
    62       };
    63       response.setStatusLine(request.httpVersion, 200, "Yay");
    64       break;
    66     default:
    67       // Anything else happening in this test is a failure.
    68       message = {
    69         code: 400,
    70         errno: 999,
    71         error: "What happened!?",
    72       };
    73       response.setStatusLine(request.httpVersion, 400, "Ouch");
    74       break;
    75   }
    77   messageStr = JSON.stringify(message);
    78   response.bodyOutputStream.write(messageStr, messageStr.length);
    79 }

mercurial