summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_include_other_subdomains_in_lookup.html
blob: 4c569463c501fa0bbb70ead52e4aa1621b0329fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test includeOtherSubdomainsInLookup</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content"></div>
<pre id="test">
  Test that logins with non-exact match origin appear in autocomplete dropdown.

  The includeOtherSubdomainsInLookup feature offers autocomplete results for
  subdomain related logins.

  For this testcase, there exists two logins for this origin on different
  subdomains (old.example.com and new.example.com) but with different
  passwords, beneath one login for the parent domain (example.com). Both
  logins should appear in the autocomplete popup.

<template id="form1-template">
  <form id="form1" action="https://otherexample.com/formtest.js">
    <input type="text" name="uname">
    <input type="password" name="pword">
  </form>
</template>

<script class="testbody" type="text/javascript">
  const formTemplate = document.getElementById("form1-template");

  const domainname = location.hostname;
  const loginInfos = [
    [`https://${domainname}/`, `https://${domainname}/`, null, "example-user", "example-password", "uname", "pword"],
    [`https://old.${domainname}/`, `https://old.${domainname}/`, null, "example-user", "example-password", "uname", "pword"],
    [`https://new.${domainname}/`, `https://new.${domainname}/`, null, "example-user", "new-example-password", "uname", "pword"],
  ];

  // calculates a date representation as used in the autocomplete menu to
  // distinguish duplicate logins
  function getDateString() {
    const dateAndTimeFormatter = new Services.intl.DateTimeFormat(undefined, { dateStyle: "medium" });
    return dateAndTimeFormatter.format(new Date());
  }

  add_setup(async () => {
    listenForUnexpectedPopupShown();
  });

  add_named_task("not including https login when includeOtherSubdomainsInLookup is false", async () => {
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", false]);
    await setStoredLoginsDuringTask(
      [`https://${domainname}/`, `https://${domainname}/`, null, "example-user-https", "example-password", "uname", "pword"],
    );
    const form = setContentForTask(formTemplate);
    form.uname.focus();

    await noPopupByArrowDown();
    ok(true, "no popup has been opened")
  });

  add_named_task("including https login when includeOtherSubdomainsInLookup is true", async () => {
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
    await setStoredLoginsDuringTask(
      [`https://${domainname}/`, `https://${domainname}/`, null, "example-user-https", "example-password", "uname", "pword"],
    );
    const form = setContentForTask(formTemplate);
    form.uname.focus();

    const autocompleteItems = await popupByArrowDown();
    checkAutoCompleteResults(autocompleteItems, ["example-user-https"], window.location.host, "https login showed");
  });

  add_named_task("including http login when includeOtherSubdomainsInLookup is false", async () => {
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", false]);
    await setStoredLoginsDuringTask(
      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      [`http://${domainname}/`, `https://${domainname}/`, null, "example-user-http", "example-password", "uname", "pword"],
    );
    const form = setContentForTask(formTemplate);
    form.uname.focus();

    const autocompleteItems = await popupByArrowDown();
    checkAutoCompleteResults(autocompleteItems, ["example-user-http"], window.location.host, "http login showed");
  });

  add_named_task("including http login when includeOtherSubdomainsInLookup is true", async () => {
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
    await setStoredLoginsDuringTask(
      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      [`http://${domainname}/`, `https://${domainname}/`, null, "example-user-http", "example-password", "uname", "pword"],
    );
    const form = setContentForTask(formTemplate);
    form.uname.focus();

    const autocompleteItems = await popupByArrowDown();
    checkAutoCompleteResults(autocompleteItems, ["example-user-http"], window.location.host, "http login showed");
  });

  add_named_task("including https and http login when includeOtherSubdomainsInLookup is false", async () => {
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", false]);
    await setStoredLoginsDuringTask(
      [`https://${domainname}/`, `https://${domainname}/`, null, "example-user-https", "example-password", "uname", "pword"],
      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      [`http://${domainname}/`, `https://${domainname}/`, null, "example-user-http", "example-password", "uname", "pword"],
    );
    const form = setContentForTask(formTemplate);
    form.uname.focus();

    const autocompleteItems = await popupByArrowDown();
    // checkAutoCompleteResults(autocompleteItems, ["example-user-https"], window.location.host, "https login showed");
    checkAutoCompleteResults(autocompleteItems, ["example-user-http"], window.location.host, "https login showed");
  });

  add_named_task("including https and http login when includeOtherSubdomainsInLookup is true", async () => {
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
    await setStoredLoginsDuringTask(
      [`https://${domainname}/`, `https://${domainname}/`, null, "example-user-https", "example-password", "uname", "pword"],
      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      [`http://${domainname}/`, `https://${domainname}/`, null, "example-user-http", "example-password", "uname", "pword"],
    );
    const form = setContentForTask(formTemplate);
    form.uname.focus();

    const autocompleteItems = await popupByArrowDown();
    // checkAutoCompleteResults(autocompleteItems, ["example-user-https"], window.location.host, "https login showed");
    checkAutoCompleteResults(autocompleteItems, ["example-user-http", "example-user-https"], window.location.host, "http and https logins showed");
  });

  add_named_task("menu does not show login for different subdomain when includeOtherSubdomainsInLookup is false", async () => {
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", false]);
    await setStoredLoginsDuringTask(
      ...[
        // These two logins should never be visible on https: versions of
        // *.example.com since the login is for http: and an https: login exists
        // for this username.
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        [`http://${domainname}/`, `https://${domainname}/`, null, "example-user", "example-password", "uname", "pword"],
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        [`http://old.${domainname}/`, `https://old.${domainname}/`, null, "example-user", "old-example-password", "uname", "pword"],
        ...loginInfos,
      ]
    );
    const form = setContentForTask(formTemplate);

    form.uname.focus();
    const autocompleteItems = await popupByArrowDown();
    checkAutoCompleteResults(autocompleteItems, ["example-user"], window.location.host, "Only exact subdomain showed");
  });

  add_named_task("menu shows two logins with the same username for different subdomain", async () => {
    await setStoredLoginsDuringTask(...loginInfos);
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
    const form = setContentForTask(formTemplate);

    // The logins are added "today" and since they are duplicates, the date that they were last
    // changed will be appended.
    const dateString = getDateString();
    const username = `example-user (${dateString})`;

    form.uname.focus();
    const autocompleteItems = await popupByArrowDown();
    checkAutoCompleteResults(autocompleteItems, [username, username], window.location.host, "Check all menuitems are displayed correctly.");
  });

  add_named_task("login with different subdomain is selectable", async () => {
    await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
    await setStoredLoginsDuringTask(...loginInfos);
    const form = setContentForTask(formTemplate);

    // consume initial autofill event
    await formAutofillResult(form.id);

    form.uname.focus();

    // select first item
    await popupByArrowDown();
    synthesizeKey("KEY_ArrowDown");
    synthesizeKey("KEY_Enter");

    await formAutofillResult(form.id);
    is(form.uname.value, "example-user", "correct username is set");
    is(form.pword.value, "example-password", "password matches first login");

    // select second item
    await popupByArrowDown();
    synthesizeKey("KEY_ArrowDown");
    synthesizeKey("KEY_ArrowDown");
    synthesizeKey("KEY_Enter");

    await formAutofillResult(form.id);
    is(form.uname.value, "example-user", "correct username is set");
    is(form.pword.value, "new-example-password", "password matches second login");
  });
</script>
</pre>
</body>
</html>