passbolt-styleguide 5.18.2 → 5.19.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RELEASE_NOTES.md +7 -2
- package/build/css/themes/default/api_authentication.min.css +4 -4
- package/build/css/themes/default/api_main.min.css +4 -4
- package/build/css/themes/default/ext_app.min.css +4 -4
- package/build/css/themes/default/ext_authentication.min.css +4 -4
- package/build/css/themes/default/ext_external.min.css +2 -2
- package/build/css/themes/default/ext_in_form_cta.min.css +4 -4
- package/build/css/themes/default/ext_in_form_menu.min.css +4 -4
- package/build/css/themes/default/ext_quickaccess.min.css +4 -4
- package/build/css/themes/layette/api_authentication.min.css +4 -4
- package/build/css/themes/layette/api_main.min.css +4 -4
- package/build/css/themes/layette/ext_app.min.css +4 -4
- package/build/css/themes/layette/ext_authentication.min.css +4 -4
- package/build/css/themes/layette/ext_in_form_cta.min.css +4 -4
- package/build/css/themes/layette/ext_in_form_menu.min.css +4 -4
- package/build/css/themes/layette/ext_quickaccess.min.css +4 -4
- package/build/css/themes/midgar/api_authentication.min.css +4 -4
- package/build/css/themes/midgar/api_main.min.css +4 -4
- package/build/css/themes/midgar/ext_app.min.css +4 -4
- package/build/css/themes/midgar/ext_authentication.min.css +4 -4
- package/build/css/themes/midgar/ext_in_form_cta.min.css +4 -4
- package/build/css/themes/midgar/ext_in_form_menu.min.css +4 -4
- package/build/css/themes/midgar/ext_quickaccess.min.css +4 -4
- package/build/css/themes/sakura/api_authentication.min.css +4 -4
- package/build/css/themes/sakura/api_main.min.css +4 -4
- package/build/css/themes/sakura/ext_app.min.css +4 -4
- package/build/css/themes/sakura/ext_authentication.min.css +4 -4
- package/build/css/themes/sakura/ext_in_form_cta.min.css +4 -4
- package/build/css/themes/sakura/ext_in_form_menu.min.css +4 -4
- package/build/css/themes/sakura/ext_quickaccess.min.css +4 -4
- package/build/css/themes/solarized_dark/api_authentication.min.css +4 -4
- package/build/css/themes/solarized_dark/api_main.min.css +4 -4
- package/build/css/themes/solarized_dark/ext_app.min.css +4 -4
- package/build/css/themes/solarized_dark/ext_authentication.min.css +4 -4
- package/build/css/themes/solarized_dark/ext_in_form_cta.min.css +4 -4
- package/build/css/themes/solarized_dark/ext_in_form_menu.min.css +4 -4
- package/build/css/themes/solarized_dark/ext_quickaccess.min.css +4 -4
- package/build/css/themes/solarized_light/api_authentication.min.css +4 -4
- package/build/css/themes/solarized_light/api_main.min.css +4 -4
- package/build/css/themes/solarized_light/ext_app.min.css +4 -4
- package/build/css/themes/solarized_light/ext_authentication.min.css +4 -4
- package/build/css/themes/solarized_light/ext_in_form_cta.min.css +4 -4
- package/build/css/themes/solarized_light/ext_in_form_menu.min.css +4 -4
- package/build/css/themes/solarized_light/ext_quickaccess.min.css +4 -4
- package/build/css/themes/themes.json +1 -0
- package/build/js/dist/api-account-recovery.js +1 -1
- package/build/js/dist/api-app.js +1 -1
- package/build/js/dist/api-feedback.js +1 -1
- package/build/js/dist/api-mfa-verify-delegated.js +1 -1
- package/build/js/dist/api-mfa-verify.js +1 -1
- package/build/js/dist/api-recover.js +1 -1
- package/build/js/dist/api-setup.js +1 -1
- package/build/js/dist/api-triage.js +1 -1
- package/build/locales/cs-CZ/common.json +167 -13
- package/build/locales/de-DE/common.json +165 -13
- package/build/locales/es-ES/common.json +165 -13
- package/build/locales/fr-FR/common.json +165 -13
- package/build/locales/it-IT/common.json +165 -13
- package/build/locales/ja-JP/common.json +164 -13
- package/build/locales/ko-KR/common.json +164 -13
- package/build/locales/lt-LT/common.json +167 -13
- package/build/locales/nl-NL/common.json +165 -13
- package/build/locales/pl-PL/common.json +167 -13
- package/build/locales/pt-BR/common.json +165 -13
- package/build/locales/ro-RO/common.json +166 -13
- package/build/locales/ru-RU/common.json +167 -13
- package/build/locales/sl-SI/common.json +167 -13
- package/build/locales/sv-SE/common.json +165 -13
- package/build/locales/uk-UA/common.json +167 -13
- package/package.json +2 -2
- package/src/img/svg/logo.svg +2 -2
- package/src/locales/cs-CZ/common.json +167 -13
- package/src/locales/de-DE/common.json +165 -13
- package/src/locales/es-ES/common.json +165 -13
- package/src/locales/fr-FR/common.json +165 -13
- package/src/locales/it-IT/common.json +165 -13
- package/src/locales/ja-JP/common.json +164 -13
- package/src/locales/ko-KR/common.json +164 -13
- package/src/locales/lt-LT/common.json +167 -13
- package/src/locales/nl-NL/common.json +165 -13
- package/src/locales/pl-PL/common.json +167 -13
- package/src/locales/pt-BR/common.json +165 -13
- package/src/locales/ro-RO/common.json +166 -13
- package/src/locales/ru-RU/common.json +167 -13
- package/src/locales/sl-SI/common.json +167 -13
- package/src/locales/sv-SE/common.json +165 -13
- package/src/locales/uk-UA/common.json +167 -13
- package/src/react-extension/ExtAuthenticationLogin.js +1 -0
- package/src/react-extension/components/Administration/DisplayHealthcheckAdministration/DisplayHealthcheckAdministration.js +14 -23
- package/src/react-extension/components/UserSetting/DisplayUserTheme/DisplayUserTheme.js +2 -1
- package/src/react-extension/components/UserSetting/DisplayUserTheme/DisplayUserTheme.test.data.js +5 -0
- package/src/react-extension/components/UserSetting/DisplayUserTheme/DisplayUserTheme.test.js +13 -1
- package/src/react-extension/contexts/ResourceWorkspaceContext.js +3 -1
- package/src/react-extension/contexts/ResourceWorkspaceContext.test.js +8 -0
- package/src/react-web-integration/lib/Dom/DomUtils.js +1 -1
- package/src/react-web-integration/lib/Dom/DomUtils.test.js +19 -0
- package/src/react-web-integration/lib/InForm/InFormCallToActionField.js +5 -1
- package/src/react-web-integration/lib/InForm/InFormCallToActionField.test.js +39 -0
- package/src/react-web-integration/lib/InForm/InFormManager.js +36 -13
- package/src/react-web-integration/lib/InForm/InformManager.test.js +255 -6
- package/src/react-web-integration/lib/InForm/InformManager.test.page.js +7 -7
- package/src/react-web-integration/lib/InForm/ScrapingDictionary.js +1 -1
- package/src/react-web-integration/services/Scraping/FieldScraperService.js +7 -4
- package/src/react-web-integration/services/Scraping/LabelIndex.js +86 -0
- package/src/react-web-integration/services/Scraping/LabelIndex.test.js +111 -0
- package/src/react-web-integration/services/Scraping/LabelScraperService.js +18 -14
- package/src/react-web-integration/services/Scraping/LabelScraperService.test.js +5 -5
- package/src/react-web-integration/services/Scraping/PageScraperHelpers.js +21 -5
- package/src/react-web-integration/services/Scraping/PageScraperHelpers.test.js +116 -0
- package/src/react-web-integration/services/Scraping/PageScraperService.js +6 -3
- package/src/react-web-integration/services/classification/FieldClassificationService.js +46 -40
- package/src/react-web-integration/services/classification/FieldClassificationService.test.data.js +3 -2
- package/src/react-web-integration/services/classification/FieldClassificationService.test.js +72 -0
- package/src/react-web-integration/services/classification/FieldFeatureService.js +12 -14
- package/src/react-web-integration/services/classification/FieldFeatureService.test.js +25 -11
- package/src/react-web-integration/services/classification/FieldsRationalizationService.js +1 -1
- package/src/react-web-integration/services/classification/KeywordMatchingService.js +18 -4
- package/src/react-web-integration/services/classification/KeywordMatchingService.test.js +35 -0
- package/src/react-web-integration/services/classification/KeywordsDictionary.js +21 -1
- package/src/react-web-integration/services/classification/PasswordRoleResolutionService.js +2 -2
- package/src/react-web-integration/services/classification/SegmentedOtpResolutionService.js +2 -2
- package/src/shared/utils/filterUtils.js +3 -2
- package/src/shared/utils/filterUtils.test.js +15 -0
- package/build/css/help.min.css +0 -9
- package/build/css/public.min.css +0 -8
- package/build/css/themes/default/api_cloud.min.css +0 -8
- package/build/css/themes/default/api_reports.min.css +0 -9
- package/build/css/themes/default/api_webinstaller.min.css +0 -9
- package/build/css/themes/layette/api_reports.min.css +0 -9
- package/build/css/themes/midgar/api_reports.min.css +0 -9
- package/build/css/themes/sakura/api_reports.min.css +0 -9
- package/build/css/themes/solarized_dark/api_reports.min.css +0 -9
- package/build/css/themes/solarized_light/api_reports.min.css +0 -9
|
@@ -129,6 +129,8 @@ describe("InformManager", () => {
|
|
|
129
129
|
|
|
130
130
|
beforeEach(() => {
|
|
131
131
|
jest.clearAllMocks();
|
|
132
|
+
InFormManager.host = null;
|
|
133
|
+
InFormManager.shadowRoot = null;
|
|
132
134
|
// Force to true as Jest do not provide opacity value
|
|
133
135
|
jest.spyOn(InFormManager, "isPageNotVisible").mockImplementation(() => false);
|
|
134
136
|
jest
|
|
@@ -1684,6 +1686,10 @@ describe("InformManager", () => {
|
|
|
1684
1686
|
|
|
1685
1687
|
expect(ElementVisibilityService.isElementRendered).toHaveBeenCalledWith(document.documentElement);
|
|
1686
1688
|
expect(InFormManager.destroy).not.toHaveBeenCalled();
|
|
1689
|
+
|
|
1690
|
+
ElementVisibilityService.isElementRendered.mockRestore();
|
|
1691
|
+
ElementVisibilityService.hasViewableSize.mockRestore();
|
|
1692
|
+
InFormManager.destroy.mockRestore();
|
|
1687
1693
|
});
|
|
1688
1694
|
});
|
|
1689
1695
|
|
|
@@ -2102,7 +2108,7 @@ describe("InformManager", () => {
|
|
|
2102
2108
|
let informManager;
|
|
2103
2109
|
await act(async () => (informManager = new InformManagerPage()));
|
|
2104
2110
|
|
|
2105
|
-
expect(InFormManager.host
|
|
2111
|
+
expect(InFormManager.host).toBeNull();
|
|
2106
2112
|
expect(informManager.iframesLength).toBe(0);
|
|
2107
2113
|
|
|
2108
2114
|
// A modal dialog containing a login form opens afterwards
|
|
@@ -2125,8 +2131,8 @@ describe("InformManager", () => {
|
|
|
2125
2131
|
expect(InFormManager.host.parentNode).toBe(dialog);
|
|
2126
2132
|
});
|
|
2127
2133
|
|
|
2128
|
-
it("As LU it re-appends the host as the last child of its container
|
|
2129
|
-
expect.assertions(
|
|
2134
|
+
it("As LU it re-appends the host as the last child of its container before displaying a call-to-action", async () => {
|
|
2135
|
+
expect.assertions(3);
|
|
2130
2136
|
|
|
2131
2137
|
document.body.innerHTML = domElementLoginWithNameAttributeUsername;
|
|
2132
2138
|
let informManager;
|
|
@@ -2137,14 +2143,235 @@ describe("InformManager", () => {
|
|
|
2137
2143
|
document.body.append(overlay);
|
|
2138
2144
|
expect(document.body.lastChild).not.toBe(informManager.host);
|
|
2139
2145
|
|
|
2140
|
-
|
|
2141
|
-
|
|
2146
|
+
await informManager.focusOnUsername();
|
|
2147
|
+
|
|
2148
|
+
expect(document.body.lastChild).toBe(informManager.host);
|
|
2149
|
+
expect(informManager.iframesLength).toBe(1);
|
|
2150
|
+
});
|
|
2151
|
+
|
|
2152
|
+
it("As LU it does not re-append the host on a re-scan when a page moves it among its siblings", async () => {
|
|
2153
|
+
expect.assertions(2);
|
|
2154
|
+
|
|
2155
|
+
document.body.innerHTML = `${domElementLoginWithNameAttributeUsername}<div class="ui-dialog"></div>`;
|
|
2156
|
+
let informManager;
|
|
2157
|
+
await act(async () => (informManager = new InformManagerPage()));
|
|
2158
|
+
|
|
2159
|
+
const dialog = document.querySelector(".ui-dialog");
|
|
2160
|
+
document.body.insertBefore(informManager.host, dialog);
|
|
2161
|
+
|
|
2142
2162
|
await act(async () => {
|
|
2143
2163
|
InFormManager.findAndSetInputFields();
|
|
2144
2164
|
await waitFor(() => {});
|
|
2145
2165
|
});
|
|
2146
2166
|
|
|
2147
|
-
expect(
|
|
2167
|
+
expect(informManager.host.parentNode).toBe(document.body);
|
|
2168
|
+
expect(document.body.lastChild).toBe(dialog);
|
|
2169
|
+
});
|
|
2170
|
+
|
|
2171
|
+
it("As LU it does not re-append the host while an iframe is displayed", async () => {
|
|
2172
|
+
expect.assertions(3);
|
|
2173
|
+
|
|
2174
|
+
document.body.innerHTML = domElementLoginWithNameAttributeUsername;
|
|
2175
|
+
let informManager;
|
|
2176
|
+
await act(async () => (informManager = new InformManagerPage()));
|
|
2177
|
+
await informManager.focusOnUsername();
|
|
2178
|
+
expect(informManager.iframesLength).toBe(1);
|
|
2179
|
+
|
|
2180
|
+
const overlay = document.createElement("div");
|
|
2181
|
+
document.body.append(overlay);
|
|
2182
|
+
|
|
2183
|
+
InFormManager.reappendHost();
|
|
2184
|
+
|
|
2185
|
+
expect(document.body.lastChild).toBe(overlay);
|
|
2186
|
+
expect(informManager.iframesLength).toBe(1);
|
|
2187
|
+
});
|
|
2188
|
+
});
|
|
2189
|
+
|
|
2190
|
+
describe("Lazy host mount", () => {
|
|
2191
|
+
beforeEach(() => {
|
|
2192
|
+
document.body.removeAttribute("style");
|
|
2193
|
+
document.documentElement.removeAttribute("style");
|
|
2194
|
+
});
|
|
2195
|
+
|
|
2196
|
+
it("As LU I should not have the host mounted on a page without login fields", async () => {
|
|
2197
|
+
expect.assertions(3);
|
|
2198
|
+
|
|
2199
|
+
document.body.innerHTML = domElementWithNoUsernamePassword;
|
|
2200
|
+
let informManager;
|
|
2201
|
+
await act(async () => (informManager = new InformManagerPage()));
|
|
2202
|
+
|
|
2203
|
+
expect(InFormManager.host).toBeNull();
|
|
2204
|
+
expect(document.body.querySelector(":scope > div[style*='z-index']")).toBeNull();
|
|
2205
|
+
expect(informManager.iframesLength).toBe(0);
|
|
2206
|
+
});
|
|
2207
|
+
|
|
2208
|
+
it("As LU the host integrity check should pass without remounting while no host is mounted", async () => {
|
|
2209
|
+
expect.assertions(3);
|
|
2210
|
+
|
|
2211
|
+
document.body.innerHTML = domElementWithNoUsernamePassword;
|
|
2212
|
+
await act(async () => new InformManagerPage());
|
|
2213
|
+
const retrySpy = jest.spyOn(InFormManager, "retryMountHost");
|
|
2214
|
+
|
|
2215
|
+
expect(InFormManager._ensureHostIntegrity()).toBe(true);
|
|
2216
|
+
expect(retrySpy).not.toHaveBeenCalled();
|
|
2217
|
+
expect(InFormManager.host).toBeNull();
|
|
2218
|
+
|
|
2219
|
+
retrySpy.mockRestore();
|
|
2220
|
+
});
|
|
2221
|
+
|
|
2222
|
+
it("As LU I should not have inform destroyed by DOM changes while no host is mounted", async () => {
|
|
2223
|
+
expect.assertions(2);
|
|
2224
|
+
|
|
2225
|
+
document.body.innerHTML = domElementWithNoUsernamePassword;
|
|
2226
|
+
jest.spyOn(InFormManager, "destroy");
|
|
2227
|
+
await act(async () => new InformManagerPage());
|
|
2228
|
+
|
|
2229
|
+
await act(async () => {
|
|
2230
|
+
document.body.append(document.createElement("div"));
|
|
2231
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
2232
|
+
});
|
|
2233
|
+
|
|
2234
|
+
expect(InFormManager.destroy).not.toHaveBeenCalled();
|
|
2235
|
+
expect(InFormManager.host).toBeNull();
|
|
2236
|
+
});
|
|
2237
|
+
|
|
2238
|
+
it("As LU I should have the host mounted once a login form appears", async () => {
|
|
2239
|
+
expect.assertions(4);
|
|
2240
|
+
|
|
2241
|
+
document.body.innerHTML = domElementWithNoUsernamePassword;
|
|
2242
|
+
let informManager;
|
|
2243
|
+
await act(async () => (informManager = new InformManagerPage()));
|
|
2244
|
+
expect(InFormManager.host).toBeNull();
|
|
2245
|
+
|
|
2246
|
+
const loginForm = document.createElement("div");
|
|
2247
|
+
loginForm.innerHTML = domElementLoginWithNameAttributeUsername;
|
|
2248
|
+
document.body.append(loginForm);
|
|
2249
|
+
await act(async () => {
|
|
2250
|
+
InFormManager.findAndSetInputFields();
|
|
2251
|
+
await waitFor(() => {});
|
|
2252
|
+
});
|
|
2253
|
+
|
|
2254
|
+
expect(InFormManager.host.parentNode).toBe(document.body);
|
|
2255
|
+
await informManager.focusOnUsername();
|
|
2256
|
+
expect(informManager.iframesLength).toBe(1);
|
|
2257
|
+
expect(document.body.lastChild).toBe(InFormManager.host);
|
|
2258
|
+
});
|
|
2259
|
+
|
|
2260
|
+
it("As LU I should destroy inform if opacity of a host mounted after initialization changes", async () => {
|
|
2261
|
+
expect.assertions(2);
|
|
2262
|
+
|
|
2263
|
+
document.body.innerHTML = domElementWithNoUsernamePassword;
|
|
2264
|
+
jest.spyOn(InFormManager, "destroy");
|
|
2265
|
+
await act(async () => new InformManagerPage());
|
|
2266
|
+
|
|
2267
|
+
const loginForm = document.createElement("div");
|
|
2268
|
+
loginForm.innerHTML = domElementLoginWithNameAttributeUsername;
|
|
2269
|
+
document.body.append(loginForm);
|
|
2270
|
+
await act(async () => {
|
|
2271
|
+
InFormManager.findAndSetInputFields();
|
|
2272
|
+
await waitFor(() => {});
|
|
2273
|
+
});
|
|
2274
|
+
expect(InFormManager.host).not.toBeNull();
|
|
2275
|
+
|
|
2276
|
+
await act(async () => {
|
|
2277
|
+
InFormManager.host.setAttribute("style", "opacity: 0.3 !important");
|
|
2278
|
+
await waitFor(() => {});
|
|
2279
|
+
});
|
|
2280
|
+
|
|
2281
|
+
expect(InFormManager.destroy).toHaveBeenCalled();
|
|
2282
|
+
});
|
|
2283
|
+
|
|
2284
|
+
it("As LU I should destroy inform without error while no host is mounted", async () => {
|
|
2285
|
+
expect.assertions(1);
|
|
2286
|
+
|
|
2287
|
+
document.body.innerHTML = domElementWithNoUsernamePassword;
|
|
2288
|
+
await act(async () => new InformManagerPage());
|
|
2289
|
+
|
|
2290
|
+
expect(() => InFormManager.destroy()).not.toThrow();
|
|
2291
|
+
});
|
|
2292
|
+
});
|
|
2293
|
+
|
|
2294
|
+
describe("Frameset page", () => {
|
|
2295
|
+
/**
|
|
2296
|
+
* Swap the body for a frameset holding one frame whose document contains the given login form.
|
|
2297
|
+
* @param {string} html The form markup to load inside the frame.
|
|
2298
|
+
* @returns {HTMLFrameElement} The frame element.
|
|
2299
|
+
*/
|
|
2300
|
+
const replaceBodyWithFrameset = (html) => {
|
|
2301
|
+
const frameset = document.createElement("frameset");
|
|
2302
|
+
const frame = document.createElement("frame");
|
|
2303
|
+
|
|
2304
|
+
frameset.appendChild(frame);
|
|
2305
|
+
document.documentElement.replaceChild(frameset, document.body);
|
|
2306
|
+
|
|
2307
|
+
frame.contentDocument.body.innerHTML = html;
|
|
2308
|
+
|
|
2309
|
+
// The frame document is a separate realm, so the getBoundingClientRect mock must be set here as well
|
|
2310
|
+
[...frame.contentDocument.querySelectorAll("input")].forEach((input) => {
|
|
2311
|
+
jest
|
|
2312
|
+
.spyOn(input, "getBoundingClientRect")
|
|
2313
|
+
.mockReturnValue({ x: 0, y: 0, top: 0, left: 0, right: 100, bottom: 20, width: 100, height: 20 });
|
|
2314
|
+
});
|
|
2315
|
+
|
|
2316
|
+
return frame;
|
|
2317
|
+
};
|
|
2318
|
+
|
|
2319
|
+
beforeEach(() => {
|
|
2320
|
+
jest.spyOn(DomUtils, "isRequestInitiatedFromSameOrigin").mockImplementation(() => true);
|
|
2321
|
+
});
|
|
2322
|
+
|
|
2323
|
+
afterEach(() => {
|
|
2324
|
+
document.documentElement.replaceChild(document.createElement("body"), document.body);
|
|
2325
|
+
});
|
|
2326
|
+
|
|
2327
|
+
it("should return the document element as container when the body is a frameset", async () => {
|
|
2328
|
+
expect.assertions(2);
|
|
2329
|
+
|
|
2330
|
+
replaceBodyWithFrameset(domElementLoginWithIdAttributeLogin);
|
|
2331
|
+
|
|
2332
|
+
let informManager;
|
|
2333
|
+
await act(async () => (informManager = new InformManagerPage()));
|
|
2334
|
+
|
|
2335
|
+
expect(document.body.nodeName).toBe("FRAMESET");
|
|
2336
|
+
expect(InFormManager.getContainerElement(informManager.usernames, informManager.passwords)).toBe(
|
|
2337
|
+
document.documentElement,
|
|
2338
|
+
);
|
|
2339
|
+
});
|
|
2340
|
+
|
|
2341
|
+
it("should mount the host under the document element when the body is a frameset", async () => {
|
|
2342
|
+
expect.assertions(4);
|
|
2343
|
+
|
|
2344
|
+
replaceBodyWithFrameset(domElementLoginWithIdAttributeLogin);
|
|
2345
|
+
|
|
2346
|
+
let informManager;
|
|
2347
|
+
await act(async () => (informManager = new InformManagerPage()));
|
|
2348
|
+
|
|
2349
|
+
expect(InFormManager.host.parentNode).toBe(document.documentElement);
|
|
2350
|
+
expect(informManager.iframesLength).toBe(0);
|
|
2351
|
+
|
|
2352
|
+
await informManager.focusOnUsernameIframe();
|
|
2353
|
+
expect(informManager.iframesLength).toBe(1);
|
|
2354
|
+
await informManager.blurOnUsernameIframe();
|
|
2355
|
+
expect(informManager.iframesLength).toBe(0);
|
|
2356
|
+
});
|
|
2357
|
+
|
|
2358
|
+
it("should not destroy inform when the host is legitimately under the document element of a frameset page and the DOM changes", async () => {
|
|
2359
|
+
expect.assertions(3);
|
|
2360
|
+
|
|
2361
|
+
replaceBodyWithFrameset(domElementLoginWithIdAttributeLogin);
|
|
2362
|
+
|
|
2363
|
+
jest.spyOn(InFormManager, "destroy");
|
|
2364
|
+
let informManager;
|
|
2365
|
+
await act(async () => (informManager = new InformManagerPage()));
|
|
2366
|
+
|
|
2367
|
+
expect(InFormManager.host.parentNode).toBe(document.documentElement);
|
|
2368
|
+
|
|
2369
|
+
// A DOM change elsewhere triggers the mutation observer
|
|
2370
|
+
document.documentElement.append(document.createElement("div"));
|
|
2371
|
+
await informManager.focusOnUsernameIframe();
|
|
2372
|
+
|
|
2373
|
+
expect(InFormManager.destroy).not.toHaveBeenCalled();
|
|
2374
|
+
expect(InFormManager.host.parentNode).toBe(document.documentElement);
|
|
2148
2375
|
});
|
|
2149
2376
|
});
|
|
2150
2377
|
|
|
@@ -2368,6 +2595,28 @@ describe("InformManager", () => {
|
|
|
2368
2595
|
|
|
2369
2596
|
expect(ctaElements()).toContain(document.getElementById("email"));
|
|
2370
2597
|
});
|
|
2598
|
+
|
|
2599
|
+
it("should not attach a call-to-action to a readonly field until it is editable", async () => {
|
|
2600
|
+
expect.assertions(3);
|
|
2601
|
+
|
|
2602
|
+
// Second step of a multi-step login: the identifier is recalled in a readonly field above the password.
|
|
2603
|
+
document.body.innerHTML = `<form>
|
|
2604
|
+
<input type='email' id='email' name='email' readonly value='admin@passbolt.com'/>
|
|
2605
|
+
<input type='password' id='password' name='password'/>
|
|
2606
|
+
</form>`;
|
|
2607
|
+
await act(async () => new InformManagerPage());
|
|
2608
|
+
const ctaElements = () => InFormManager.callToActionFields.map(({ field }) => field);
|
|
2609
|
+
expect(ctaElements()).not.toContain(document.getElementById("email"));
|
|
2610
|
+
expect(ctaElements()).toContain(document.getElementById("password"));
|
|
2611
|
+
|
|
2612
|
+
// The site makes the field editable: the next scan attaches its call-to-action.
|
|
2613
|
+
await act(async () => {
|
|
2614
|
+
document.getElementById("email").removeAttribute("readonly");
|
|
2615
|
+
});
|
|
2616
|
+
InFormManager.findAndSetAuthenticationFields();
|
|
2617
|
+
|
|
2618
|
+
expect(ctaElements()).toContain(document.getElementById("email"));
|
|
2619
|
+
});
|
|
2371
2620
|
});
|
|
2372
2621
|
|
|
2373
2622
|
describe("Focus healer integration", () => {
|
|
@@ -46,10 +46,10 @@ export default class InformManagerPage {
|
|
|
46
46
|
* Returns the username in iframe element
|
|
47
47
|
*/
|
|
48
48
|
get usernameIframe() {
|
|
49
|
-
// The detected username field that lives inside the same-origin iframe. Same source as
|
|
50
|
-
// (the classification result), scoped to the iframe document so it is unambiguous when
|
|
51
|
-
// holds fields outside the iframe.
|
|
52
|
-
const iframeDocument = document.querySelector("iframe").contentDocument;
|
|
49
|
+
// The detected username field that lives inside the same-origin iframe (or frame). Same source as
|
|
50
|
+
// `username` (the classification result), scoped to the iframe document so it is unambiguous when
|
|
51
|
+
// the page also holds fields outside the iframe.
|
|
52
|
+
const iframeDocument = document.querySelector("iframe,frame").contentDocument;
|
|
53
53
|
const username = InFormManager.callToActionFields.find(
|
|
54
54
|
(field) => field.fieldType === "username" && iframeDocument.contains(field.field),
|
|
55
55
|
);
|
|
@@ -77,8 +77,8 @@ export default class InformManagerPage {
|
|
|
77
77
|
* Returns the password in iframe element
|
|
78
78
|
*/
|
|
79
79
|
get passwordIframe() {
|
|
80
|
-
// The detected password field that lives inside the same-origin iframe (see usernameIframe).
|
|
81
|
-
const iframeDocument = document.querySelector("iframe").contentDocument;
|
|
80
|
+
// The detected password field that lives inside the same-origin iframe or frame (see usernameIframe).
|
|
81
|
+
const iframeDocument = document.querySelector("iframe,frame").contentDocument;
|
|
82
82
|
const password = InFormManager.callToActionFields.find(
|
|
83
83
|
(field) => field.fieldType === "password" && iframeDocument.contains(field.field),
|
|
84
84
|
);
|
|
@@ -129,7 +129,7 @@ export default class InformManagerPage {
|
|
|
129
129
|
* Returns the iframe length
|
|
130
130
|
*/
|
|
131
131
|
get iframesLength() {
|
|
132
|
-
return InFormManager.shadowRoot
|
|
132
|
+
return InFormManager.shadowRoot?.querySelectorAll("iframe").length ?? 0;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
@@ -108,7 +108,7 @@ export const LABEL_ANCESTOR_TAGS = ["LABEL", "DIV", "TD", "TH", "DD", "LI"];
|
|
|
108
108
|
* Maximum number of ancestors walked up from a field while looking for its label.
|
|
109
109
|
* @type {number}
|
|
110
110
|
*/
|
|
111
|
-
export const MAX_LABEL_ANCESTOR_HOPS =
|
|
111
|
+
export const MAX_LABEL_ANCESTOR_HOPS = 10;
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* Heading tags used to derive a field's contextual title.
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import ScrapingIdentityService from "./ScrapingIdentityService";
|
|
16
16
|
import LabelScraperService from "./LabelScraperService";
|
|
17
|
+
import LabelIndex from "./LabelIndex";
|
|
17
18
|
import { MAX_SCRAPED_STRING_LENGTH, AUTOCOMPLETE_ATTRS, OPT_OUT_ATTRS } from "../../lib/InForm/ScrapingDictionary";
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -25,9 +26,10 @@ class FieldScraperService {
|
|
|
25
26
|
*
|
|
26
27
|
* @param {Element} element The field element.
|
|
27
28
|
* @param {string} formId The id of the container.
|
|
29
|
+
* @param {LabelIndex} [labelIndex] The label index of the scrape.
|
|
28
30
|
* @returns {FieldScraping} The record, without the element.
|
|
29
31
|
*/
|
|
30
|
-
static build(element, formId) {
|
|
32
|
+
static build(element, formId, labelIndex = new LabelIndex()) {
|
|
31
33
|
const tagName = element.nodeName.toUpperCase();
|
|
32
34
|
// Only `input` has a type
|
|
33
35
|
const type = tagName === "INPUT" ? (element.type || "text").toLowerCase() : "";
|
|
@@ -70,7 +72,7 @@ class FieldScraperService {
|
|
|
70
72
|
optOut: FieldScraperService._optOut(element),
|
|
71
73
|
};
|
|
72
74
|
|
|
73
|
-
LabelScraperService.enrich(record);
|
|
75
|
+
LabelScraperService.enrich(record, labelIndex);
|
|
74
76
|
|
|
75
77
|
// Remove the element so the record is serializable
|
|
76
78
|
delete record.element;
|
|
@@ -83,10 +85,11 @@ class FieldScraperService {
|
|
|
83
85
|
*
|
|
84
86
|
* @param {Element} element The field element.
|
|
85
87
|
* @param {string} formId The id of the container the field is in.
|
|
88
|
+
* @param {LabelIndex} [labelIndex] The label index of the scrape.
|
|
86
89
|
* @returns {FieldScraping} The record.
|
|
87
90
|
*/
|
|
88
|
-
static scrape(element, formId) {
|
|
89
|
-
return FieldScraperService.build(element, formId);
|
|
91
|
+
static scrape(element, formId, labelIndex) {
|
|
92
|
+
return FieldScraperService.build(element, formId, labelIndex);
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
/**
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passbolt ~ Open source password manager for teams
|
|
3
|
+
* Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
4
|
+
*
|
|
5
|
+
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
|
6
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
7
|
+
* Redistributions of files must retain the above copyright notice.
|
|
8
|
+
*
|
|
9
|
+
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
10
|
+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
|
11
|
+
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
|
+
* @since 5.18.0
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Index of the `<label for>` of each root, built once per scrape.
|
|
17
|
+
* Replaces the per-field `querySelector` and `element.labels`, which both scan the whole root.
|
|
18
|
+
*/
|
|
19
|
+
class LabelIndex {
|
|
20
|
+
/**
|
|
21
|
+
* Default constructor
|
|
22
|
+
*/
|
|
23
|
+
constructor() {
|
|
24
|
+
/**
|
|
25
|
+
* The labels by `for` value, by root.
|
|
26
|
+
* @type {WeakMap<Node, Map<string, Element[]>>}
|
|
27
|
+
*/
|
|
28
|
+
this.indexes = new WeakMap();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns the first label whose `for` attribute equals the value.
|
|
33
|
+
* Same result as `root.querySelector('label[for="value"]')`, without walking the whole root on each call.
|
|
34
|
+
* @param {Document|ShadowRoot|Element|DocumentFragment} root The root to search in.
|
|
35
|
+
* @param {string} value The `for` value.
|
|
36
|
+
* @returns {Element|null} The label, or null.
|
|
37
|
+
*/
|
|
38
|
+
labelFor(root, value) {
|
|
39
|
+
return this._indexOf(root).get(value)?.[0] ?? null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the labels of the element in tree order.
|
|
44
|
+
* Same result as `element.labels`, which walks the whole tree for each element.
|
|
45
|
+
* @param {Element} element The labelable element.
|
|
46
|
+
* @returns {Element[]} The labels.
|
|
47
|
+
*/
|
|
48
|
+
labelsOf(element) {
|
|
49
|
+
const labels = [];
|
|
50
|
+
const id = element.getAttribute("id");
|
|
51
|
+
if (id) {
|
|
52
|
+
const forLabels = this._indexOf(element.getRootNode()).get(id) ?? [];
|
|
53
|
+
labels.push(...forLabels.filter((label) => label.control === element));
|
|
54
|
+
}
|
|
55
|
+
for (let ancestor = element.parentElement; ancestor; ancestor = ancestor.parentElement) {
|
|
56
|
+
if (ancestor.nodeName === "LABEL" && !ancestor.hasAttribute("for") && ancestor.control === element) {
|
|
57
|
+
labels.push(ancestor);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return labels.sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns the index of the root, building it on first use.
|
|
65
|
+
* @private
|
|
66
|
+
* @param {Document|ShadowRoot|Element|DocumentFragment} root The root.
|
|
67
|
+
* @returns {Map<string, Element[]>} The labels by `for` value, in tree order.
|
|
68
|
+
*/
|
|
69
|
+
_indexOf(root) {
|
|
70
|
+
let index = this.indexes.get(root);
|
|
71
|
+
if (!index) {
|
|
72
|
+
index = new Map();
|
|
73
|
+
for (const label of root.querySelectorAll("label[for]")) {
|
|
74
|
+
const value = label.getAttribute("for");
|
|
75
|
+
if (!index.has(value)) {
|
|
76
|
+
index.set(value, []);
|
|
77
|
+
}
|
|
78
|
+
index.get(value).push(label);
|
|
79
|
+
}
|
|
80
|
+
this.indexes.set(root, index);
|
|
81
|
+
}
|
|
82
|
+
return index;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default LabelIndex;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passbolt ~ Open source password manager for teams
|
|
3
|
+
* Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
4
|
+
*
|
|
5
|
+
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
|
6
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
7
|
+
* Redistributions of files must retain the above copyright notice.
|
|
8
|
+
*
|
|
9
|
+
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
10
|
+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
|
11
|
+
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
|
+
* @since 5.18.0
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import LabelIndex from "./LabelIndex";
|
|
16
|
+
|
|
17
|
+
describe("LabelIndex", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
document.body.innerHTML = "";
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("LabelIndex::labelsOf", () => {
|
|
23
|
+
const fixtures = [
|
|
24
|
+
"<label for='a'>A</label><input id='a'>",
|
|
25
|
+
"<label for='a'>A1</label><input id='a'><label for='a'>A2</label>",
|
|
26
|
+
"<label>Wrapped <input id='a'></label>",
|
|
27
|
+
"<label for='a'>For</label><label>Wrapped <input id='a'></label>",
|
|
28
|
+
"<label for='other'>Elsewhere <input id='a'></label><input id='other'>",
|
|
29
|
+
"<label for='a'>Name only</label><input name='a'>",
|
|
30
|
+
"<label for='a'>Duplicate</label><input id='a'><input id='a'>",
|
|
31
|
+
"<label for='a'>Not labelable</label><div id='a'><input></div>",
|
|
32
|
+
"<label>Outer <span><label>Inner <input id='a'></label></span></label>",
|
|
33
|
+
"<label for=''>Empty for</label><label><input id='a'></label>",
|
|
34
|
+
"<label><input id='a'><input id='b'></label>",
|
|
35
|
+
"<input id='a'>",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
it.each(fixtures)("should return the same labels as element.labels for %s", (html) => {
|
|
39
|
+
// eslint-disable-next-line no-unsanitized/property
|
|
40
|
+
document.body.innerHTML = html;
|
|
41
|
+
const elements = document.querySelectorAll("input, div[id]");
|
|
42
|
+
expect.assertions(elements.length);
|
|
43
|
+
|
|
44
|
+
const labelIndex = new LabelIndex();
|
|
45
|
+
for (const element of elements) {
|
|
46
|
+
expect(labelIndex.labelsOf(element)).toEqual(Array.from(element.labels ?? []));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should only return the labels of the element's own shadow root", () => {
|
|
51
|
+
expect.assertions(2);
|
|
52
|
+
|
|
53
|
+
document.body.innerHTML = "<label for='a'>Light</label><div id='host'></div>";
|
|
54
|
+
const shadowRoot = document.getElementById("host").attachShadow({ mode: "open" });
|
|
55
|
+
shadowRoot.innerHTML = "<label for='a'>Shadow</label><input id='a'>";
|
|
56
|
+
const input = shadowRoot.getElementById("a");
|
|
57
|
+
|
|
58
|
+
const labels = new LabelIndex().labelsOf(input);
|
|
59
|
+
|
|
60
|
+
expect(labels).toEqual(Array.from(input.labels));
|
|
61
|
+
expect(labels.map((label) => label.textContent)).toEqual(["Shadow"]);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("LabelIndex::labelFor", () => {
|
|
66
|
+
it("should return the first label in tree order, as querySelector", () => {
|
|
67
|
+
expect.assertions(2);
|
|
68
|
+
|
|
69
|
+
document.body.innerHTML = "<label for='a'>First</label><label for='a'>Second</label><input name='a'>";
|
|
70
|
+
|
|
71
|
+
const label = new LabelIndex().labelFor(document, "a");
|
|
72
|
+
|
|
73
|
+
expect(label).toBe(document.querySelector("label[for='a']"));
|
|
74
|
+
expect(label.textContent).toEqual("First");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should return null when no label has the value", () => {
|
|
78
|
+
expect.assertions(1);
|
|
79
|
+
|
|
80
|
+
document.body.innerHTML = "<label for='a'>A</label>";
|
|
81
|
+
|
|
82
|
+
expect(new LabelIndex().labelFor(document, "b")).toBeNull();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should match the value exactly, special characters included", () => {
|
|
86
|
+
expect.assertions(2);
|
|
87
|
+
|
|
88
|
+
document.body.innerHTML = `<label for='a"b c'>Quoted</label><label for='A'>Upper</label>`;
|
|
89
|
+
const labelIndex = new LabelIndex();
|
|
90
|
+
|
|
91
|
+
expect(labelIndex.labelFor(document, 'a"b c').textContent).toEqual("Quoted");
|
|
92
|
+
expect(labelIndex.labelFor(document, "a")).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("should query each root only once", () => {
|
|
96
|
+
expect.assertions(2);
|
|
97
|
+
|
|
98
|
+
document.body.innerHTML = "<label for='a'>A</label><label for='b'>B</label>";
|
|
99
|
+
const spy = jest.spyOn(document, "querySelectorAll");
|
|
100
|
+
const labelIndex = new LabelIndex();
|
|
101
|
+
|
|
102
|
+
labelIndex.labelFor(document, "a");
|
|
103
|
+
labelIndex.labelFor(document, "b");
|
|
104
|
+
labelIndex.labelFor(document, "c");
|
|
105
|
+
|
|
106
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(spy).toHaveBeenCalledWith("label[for]");
|
|
108
|
+
spy.mockRestore();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|