Skip to content

Commit

Permalink
“PM-15592
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-livefront committed Dec 19, 2024
1 parent 0f9e18b commit 8dec2b0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ describe("InlineMenuFieldQualificationService", () => {
});

describe("isFieldForLoginForm", () => {
it("does not disqualify totp fields with flag set to true", () => {
it("does not disqualify totp fields for premium users with flag set to true", () => {
inlineMenuFieldQualificationService["inlineMenuTotpFeatureFlag"] = true;
inlineMenuFieldQualificationService["premiumEnabled"] = true;
const field = mock<AutofillField>({
type: "text",
autoCompleteType: "one-time-code",
Expand All @@ -36,8 +37,25 @@ describe("InlineMenuFieldQualificationService", () => {
);
});

it("disqualify totp fields with flag set to false", () => {
it("disqualifies totp fields for premium users with flag set to false", () => {
inlineMenuFieldQualificationService["inlineMenuTotpFeatureFlag"] = false;
inlineMenuFieldQualificationService["inlineMenuTotpFeatureFlag"] = true;
const field = mock<AutofillField>({
type: "text",
autoCompleteType: "one-time-code",
htmlName: "totp",
htmlID: "totp",
placeholder: "totp",
});

expect(inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails)).toBe(
false,
);
});

it("disqualifies totp fields for non-premium users with flag set to true", () => {
inlineMenuFieldQualificationService["inlineMenuTotpFeatureFlag"] = true;
inlineMenuFieldQualificationService["premiumEnabled"] = false;
const field = mock<AutofillField>({
type: "text",
autoCompleteType: "one-time-code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,17 @@ export class InlineMenuFieldQualificationService
private totpFieldAutocompleteValue = "one-time-code";
private inlineMenuFieldQualificationFlagSet = false;
private inlineMenuTotpFeatureFlag = false;
private premiumEnabled = false;

constructor() {
void Promise.all([
sendExtensionMessage("getInlineMenuFieldQualificationFeatureFlag"),
sendExtensionMessage("getInlineMenuTotpFeatureFlag"),
]).then(([fieldQualificationFlag, totpFeatureFlag]) => {
sendExtensionMessage("getUserPremiumStatus"),
]).then(([fieldQualificationFlag, totpFeatureFlag, premiumStatus]) => {
this.inlineMenuFieldQualificationFlagSet = !!fieldQualificationFlag?.result;
this.inlineMenuTotpFeatureFlag = !!totpFeatureFlag?.result;
this.premiumEnabled = !!premiumStatus?.result;
});
}

Expand All @@ -174,10 +177,11 @@ export class InlineMenuFieldQualificationService
}

/**
* Autofill does not fill password type totp input fields
* Totp inline menu is available only for premium users.
*/
if (this.inlineMenuTotpFeatureFlag) {
if (this.inlineMenuTotpFeatureFlag && this.premiumEnabled) {
const isTotpField = this.isTotpField(field);
// Autofill does not fill totp inputs with a "password" `type` attribute value
const passwordType = field.type === "password";
if (isTotpField && !passwordType) {
return true;
Expand Down
1 change: 1 addition & 0 deletions apps/browser/src/background/main.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ export default class MainBackground {
messageListener,
this.accountService,
lockService,
this.billingAccountProfileStateService,
);
this.nativeMessagingBackground = new NativeMessagingBackground(
this.keyService,
Expand Down
9 changes: 9 additions & 0 deletions apps/browser/src/background/runtime.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NotificationsService } from "@bitwarden/common/abstractions/notificatio
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AutofillOverlayVisibility, ExtensionCommand } from "@bitwarden/common/autofill/constants";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ProcessReloadServiceAbstraction } from "@bitwarden/common/key-management/abstractions/process-reload.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
Expand Down Expand Up @@ -50,6 +51,7 @@ export default class RuntimeBackground {
private messageListener: MessageListener,
private accountService: AccountService,
private readonly lockService: LockService,
private billingAccountProfileStateService: BillingAccountProfileStateService,

Check warning on line 54 in apps/browser/src/background/runtime.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/runtime.background.ts#L54

Added line #L54 was not covered by tests
) {
// onInstalled listener must be wired up before anything else, so we do it in the ctor
chrome.runtime.onInstalled.addListener((details: any) => {
Expand All @@ -74,6 +76,7 @@ export default class RuntimeBackground {
"getUseTreeWalkerApiForPageDetailsCollectionFeatureFlag",
"getInlineMenuFieldQualificationFeatureFlag",
"getInlineMenuTotpFeatureFlag",
"getUserPremiumStatus",
];

if (messagesWithResponse.includes(msg.command)) {
Expand Down Expand Up @@ -198,6 +201,12 @@ export default class RuntimeBackground {
case "getInlineMenuFieldQualificationFeatureFlag": {
return await this.configService.getFeatureFlag(FeatureFlag.InlineMenuFieldQualification);
}
case "getUserPremiumStatus": {
const result = await firstValueFrom(

Check warning on line 205 in apps/browser/src/background/runtime.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/runtime.background.ts#L205

Added line #L205 was not covered by tests
this.billingAccountProfileStateService.hasPremiumFromAnySource$,
);
return result;

Check warning on line 208 in apps/browser/src/background/runtime.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/runtime.background.ts#L208

Added line #L208 was not covered by tests
}
case "getInlineMenuTotpFeatureFlag": {
return await this.configService.getFeatureFlag(FeatureFlag.InlineMenuTotp);
}
Expand Down

0 comments on commit 8dec2b0

Please sign in to comment.