mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
[PM-15190] hide empty ciphers from autofill (#12491)
* hide empty ciphers from autofill --------- Co-authored-by: Evan Bassler <evanbassler@EvanBasslersMBP.attlocal.net>
This commit is contained in:
@@ -1923,7 +1923,17 @@ describe("OverlayBackground", () => {
|
|||||||
|
|
||||||
it("returns true if the overlay login ciphers are populated", async () => {
|
it("returns true if the overlay login ciphers are populated", async () => {
|
||||||
overlayBackground["inlineMenuCiphers"] = new Map([
|
overlayBackground["inlineMenuCiphers"] = new Map([
|
||||||
["inline-menu-cipher-0", mock<CipherView>({ type: CipherType.Login })],
|
[
|
||||||
|
"inline-menu-cipher-0",
|
||||||
|
mock<CipherView>({
|
||||||
|
type: CipherType.Login,
|
||||||
|
login: {
|
||||||
|
username: "username1",
|
||||||
|
password: "password1",
|
||||||
|
uri: "https://example.com",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
await overlayBackground["getInlineMenuCipherData"]();
|
await overlayBackground["getInlineMenuCipherData"]();
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import { InlineMenuFormFieldData } from "../services/abstractions/autofill-overl
|
|||||||
import { AutofillService, PageDetail } from "../services/abstractions/autofill.service";
|
import { AutofillService, PageDetail } from "../services/abstractions/autofill.service";
|
||||||
import { InlineMenuFieldQualificationService } from "../services/abstractions/inline-menu-field-qualifications.service";
|
import { InlineMenuFieldQualificationService } from "../services/abstractions/inline-menu-field-qualifications.service";
|
||||||
import {
|
import {
|
||||||
|
areKeyValuesNull,
|
||||||
generateDomainMatchPatterns,
|
generateDomainMatchPatterns,
|
||||||
generateRandomChars,
|
generateRandomChars,
|
||||||
isInvalidResponseStatusCode,
|
isInvalidResponseStatusCode,
|
||||||
@@ -556,6 +557,28 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
|
|
||||||
for (let cipherIndex = 0; cipherIndex < inlineMenuCiphersArray.length; cipherIndex++) {
|
for (let cipherIndex = 0; cipherIndex < inlineMenuCiphersArray.length; cipherIndex++) {
|
||||||
const [inlineMenuCipherId, cipher] = inlineMenuCiphersArray[cipherIndex];
|
const [inlineMenuCipherId, cipher] = inlineMenuCiphersArray[cipherIndex];
|
||||||
|
|
||||||
|
switch (cipher.type) {
|
||||||
|
case CipherType.Card:
|
||||||
|
if (areKeyValuesNull(cipher.card)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CipherType.Identity:
|
||||||
|
if (areKeyValuesNull(cipher.identity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CipherType.Login:
|
||||||
|
if (
|
||||||
|
areKeyValuesNull(cipher.login, ["username", "password", "totp", "fido2Credentials"])
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!this.focusedFieldMatchesFillType(cipher.type)) {
|
if (!this.focusedFieldMatchesFillType(cipher.type)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -544,3 +544,20 @@ export const specialCharacterToKeyMap: Record<string, string> = {
|
|||||||
"?": "questionCharacterDescriptor",
|
"?": "questionCharacterDescriptor",
|
||||||
"/": "forwardSlashCharacterDescriptor",
|
"/": "forwardSlashCharacterDescriptor",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if all the values corresponding to the specified keys in an object are null.
|
||||||
|
* If no keys are specified, checks all keys in the object.
|
||||||
|
*
|
||||||
|
* @param obj - The object to check.
|
||||||
|
* @param keys - An optional array of keys to check in the object. Defaults to all keys.
|
||||||
|
* @returns Returns true if all values for the specified keys (or all keys if none are provided) are null; otherwise, false.
|
||||||
|
*/
|
||||||
|
export function areKeyValuesNull<T extends Record<string, any>>(
|
||||||
|
obj: T,
|
||||||
|
keys?: Array<keyof T>,
|
||||||
|
): boolean {
|
||||||
|
const keysToCheck = keys && keys.length > 0 ? keys : (Object.keys(obj) as Array<keyof T>);
|
||||||
|
|
||||||
|
return keysToCheck.every((key) => obj[key] == null);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user