mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
[PM-6078] Remove Username Masking From Inline Autofill Menu (#7951)
This commit is contained in:
parent
ae1b6e84be
commit
c6b0f70a26
@ -202,7 +202,7 @@ describe("OverlayBackground", () => {
|
||||
},
|
||||
id: "overlay-cipher-0",
|
||||
login: {
|
||||
username: "us*******2",
|
||||
username: "username-2",
|
||||
},
|
||||
name: "name-2",
|
||||
reprompt: cipher2.reprompt,
|
||||
@ -219,7 +219,7 @@ describe("OverlayBackground", () => {
|
||||
},
|
||||
id: "overlay-cipher-1",
|
||||
login: {
|
||||
username: "us*******1",
|
||||
username: "username-1",
|
||||
},
|
||||
name: "name-1",
|
||||
reprompt: cipher1.reprompt,
|
||||
@ -288,7 +288,7 @@ describe("OverlayBackground", () => {
|
||||
},
|
||||
id: "overlay-cipher-0",
|
||||
login: {
|
||||
username: "us*******2",
|
||||
username: "username-2",
|
||||
},
|
||||
name: "name-2",
|
||||
reprompt: cipher2.reprompt,
|
||||
@ -305,7 +305,7 @@ describe("OverlayBackground", () => {
|
||||
},
|
||||
id: "overlay-cipher-1",
|
||||
login: {
|
||||
username: "us*******1",
|
||||
username: "username-1",
|
||||
},
|
||||
name: "name-1",
|
||||
reprompt: cipher1.reprompt,
|
||||
@ -345,48 +345,6 @@ describe("OverlayBackground", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("obscureName", () => {
|
||||
it("returns an empty string if the name is falsy", () => {
|
||||
const name: string = undefined;
|
||||
|
||||
const obscureName = overlayBackground["obscureName"](name);
|
||||
|
||||
expect(obscureName).toBe("");
|
||||
});
|
||||
|
||||
it("will not attempt to obscure a username that is only a domain", () => {
|
||||
const name = "@domain.com";
|
||||
|
||||
const obscureName = overlayBackground["obscureName"](name);
|
||||
|
||||
expect(obscureName).toBe(name);
|
||||
});
|
||||
|
||||
it("will obscure all characters of a name that is less than 5 characters expect for the first character", () => {
|
||||
const name = "name@domain.com";
|
||||
|
||||
const obscureName = overlayBackground["obscureName"](name);
|
||||
|
||||
expect(obscureName).toBe("n***@domain.com");
|
||||
});
|
||||
|
||||
it("will obscure all characters of a name that is greater than 4 characters by less than 6 ", () => {
|
||||
const name = "name1@domain.com";
|
||||
|
||||
const obscureName = overlayBackground["obscureName"](name);
|
||||
|
||||
expect(obscureName).toBe("na***@domain.com");
|
||||
});
|
||||
|
||||
it("will obscure all characters of a name that is greater than 5 characters except for the first two characters and the last character", () => {
|
||||
const name = "name12@domain.com";
|
||||
|
||||
const obscureName = overlayBackground["obscureName"](name);
|
||||
|
||||
expect(obscureName).toBe("na***2@domain.com");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAuthStatus", () => {
|
||||
it("will update the user's auth status but will not update the overlay ciphers", async () => {
|
||||
const authStatus = AuthenticationStatus.Unlocked;
|
||||
|
@ -179,10 +179,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
||||
cipher.type === CipherType.Login
|
||||
? loginCipherIcon
|
||||
: buildCipherIcon(this.iconsServerUrl, cipher, isFaviconDisabled),
|
||||
login:
|
||||
cipher.type === CipherType.Login
|
||||
? { username: this.obscureName(cipher.login.username) }
|
||||
: null,
|
||||
login: cipher.type === CipherType.Login ? { username: cipher.login.username } : null,
|
||||
card: cipher.type === CipherType.Card ? cipher.card.subTitle : null,
|
||||
});
|
||||
}
|
||||
@ -426,39 +423,6 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Obscures the username by replacing all but the first and last characters with asterisks.
|
||||
* If the username is less than 4 characters, only the first character will be shown.
|
||||
* If the username is 6 or more characters, the first and last characters will be shown.
|
||||
* The domain will not be obscured.
|
||||
*
|
||||
* @param name - The username to obscure
|
||||
*/
|
||||
private obscureName(name: string): string {
|
||||
if (!name) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const [username, domain] = name.split("@");
|
||||
const usernameLength = username?.length;
|
||||
if (!usernameLength) {
|
||||
return name;
|
||||
}
|
||||
|
||||
const startingCharacters = username.slice(0, usernameLength > 4 ? 2 : 1);
|
||||
let numberStars = usernameLength;
|
||||
if (usernameLength > 4) {
|
||||
numberStars = usernameLength < 6 ? numberStars - 1 : numberStars - 2;
|
||||
}
|
||||
|
||||
let obscureName = `${startingCharacters}${new Array(numberStars).join("*")}`;
|
||||
if (usernameLength >= 6) {
|
||||
obscureName = `${obscureName}${username.slice(-1)}`;
|
||||
}
|
||||
|
||||
return domain ? `${obscureName}@${domain}` : obscureName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the overlay's visibility setting from the settings service.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user