tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_invalidEmailCase.html (3637B)


      1 <!--
      2     Any copyright is dedicated to the Public Domain.
      3     http://creativecommons.org/publicdomain/zero/1.0/
      4 -->
      5 <!DOCTYPE HTML>
      6 <html>
      7 <!--
      8 Tests for Firefox Accounts signin with invalid email case
      9 https://bugzilla.mozilla.org/show_bug.cgi?id=963835
     10 -->
     11 <head>
     12  <title>Test for Firefox Accounts (Bug 963835)</title>
     13  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     14  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
     15 </head>
     16 <body>
     17 
     18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=963835">Mozilla Bug 963835</a>
     19 <p id="display"></p>
     20 <div id="content" style="display: none">
     21  Test for correction of invalid email case in Fx Accounts signIn
     22 </div>
     23 <pre id="test">
     24 <script class="testbody" type="text/javascript">
     25 
     26 SimpleTest.waitForExplicitFinish();
     27 
     28 const {FxAccounts} = ChromeUtils.importESModule(
     29  "resource://gre/modules/FxAccounts.sys.mjs"
     30 );
     31 const {FxAccountsClient} = ChromeUtils.importESModule(
     32  "resource://gre/modules/FxAccountsClient.sys.mjs"
     33 );
     34 
     35 const TEST_SERVER =
     36  "http://mochi.test:8888/chrome/services/fxaccounts/tests/mochitest/file_invalidEmailCase.sjs?path=";
     37 
     38 let MockStorage = function() {
     39  this.data = null;
     40 };
     41 MockStorage.prototype = Object.freeze({
     42  set(contents) {
     43    this.data = contents;
     44    return Promise.resolve(null);
     45  },
     46  get() {
     47    return Promise.resolve(this.data);
     48  },
     49  getOAuthTokens() {
     50    return Promise.resolve(null);
     51  },
     52  setOAuthTokens() {
     53    return Promise.resolve();
     54  },
     55 });
     56 
     57 function MockFxAccounts() {
     58  return new FxAccounts({
     59    _now_is: new Date(),
     60 
     61    now() {
     62      return this._now_is;
     63    },
     64 
     65    signedInUserStorage: new MockStorage(),
     66 
     67    fxAccountsClient: new FxAccountsClient(TEST_SERVER),
     68  });
     69 }
     70 
     71 let wrongEmail = "greta.garbo@gmail.com";
     72 let rightEmail = "Greta.Garbo@gmail.COM";
     73 let password = "123456";
     74 
     75 function runTest() {
     76  is(Services.prefs.getStringPref("identity.fxaccounts.auth.uri"), TEST_SERVER,
     77     "Pref for auth.uri should be set to test server");
     78 
     79  let fxa = new MockFxAccounts();
     80  let client = fxa._internal.fxAccountsClient;
     81 
     82  is(true, !!fxa, "Couldn't mock fxa");
     83  is(true, !!client, "Couldn't mock fxa client");
     84  is(client.host, TEST_SERVER, "Should be using the test auth server uri");
     85 
     86  // First try to sign in using the email with the wrong capitalization.  The
     87  // FxAccountsClient will receive a 400 from the server with the corrected email.
     88  // It will automatically try to sign in again.  We expect this to succeed.
     89  client.signIn(wrongEmail, password).then(
     90    user => {
     91      // Now store the signed-in user state.  This will include the correct
     92      // email capitalization.
     93      fxa._internal.setSignedInUser(user).then(
     94        () => {
     95          // Confirm that the correct email got stored.
     96          fxa.getSignedInUser().then(
     97            data => {
     98              is(data.email, rightEmail);
     99              SimpleTest.finish();
    100            },
    101            getUserError => {
    102              ok(false, JSON.stringify(getUserError));
    103            }
    104          );
    105        },
    106        setSignedInUserError => {
    107          ok(false, JSON.stringify(setSignedInUserError));
    108        }
    109      );
    110    },
    111    signInError => {
    112      ok(false, JSON.stringify(signInError));
    113    }
    114  );
    115 }
    116 
    117 SpecialPowers.pushPrefEnv({"set": [
    118    ["identity.fxaccounts.enabled", true],         // fx accounts
    119    ["identity.fxaccounts.auth.uri", TEST_SERVER], // our sjs server
    120    ["browser.dom.window.dump.enabled", true],
    121    ["devtools.console.stdout.chrome", true],
    122  ]},
    123  function() { runTest(); }
    124 );
    125 
    126 </script>
    127 </pre>
    128 </body>
    129 </html>