[PM-11393] Remove the need for TotpCaptureService in Autofill Options View component (#11093)
This commit is contained in:
parent
1a961ee294
commit
99ba56785d
|
@ -20,17 +20,15 @@ import { CollectionView } from "@bitwarden/common/vault/models/view/collection.v
|
||||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||||
import {
|
import {
|
||||||
AsyncActionsModule,
|
AsyncActionsModule,
|
||||||
SearchModule,
|
|
||||||
ButtonModule,
|
ButtonModule,
|
||||||
IconButtonModule,
|
|
||||||
DialogService,
|
DialogService,
|
||||||
|
IconButtonModule,
|
||||||
|
SearchModule,
|
||||||
ToastService,
|
ToastService,
|
||||||
} from "@bitwarden/components";
|
} from "@bitwarden/components";
|
||||||
import { TotpCaptureService } from "@bitwarden/vault";
|
|
||||||
|
|
||||||
import { CipherViewComponent } from "../../../../../../../../libs/vault/src/cipher-view";
|
import { CipherViewComponent } from "../../../../../../../../libs/vault/src/cipher-view";
|
||||||
import { PopOutComponent } from "../../../../../platform/popup/components/pop-out.component";
|
import { PopOutComponent } from "../../../../../platform/popup/components/pop-out.component";
|
||||||
import { BrowserTotpCaptureService } from "../../../services/browser-totp-capture.service";
|
|
||||||
|
|
||||||
import { PopupFooterComponent } from "./../../../../../platform/popup/layout/popup-footer.component";
|
import { PopupFooterComponent } from "./../../../../../platform/popup/layout/popup-footer.component";
|
||||||
import { PopupHeaderComponent } from "./../../../../../platform/popup/layout/popup-header.component";
|
import { PopupHeaderComponent } from "./../../../../../platform/popup/layout/popup-header.component";
|
||||||
|
@ -41,7 +39,6 @@ import { VaultPopupAutofillService } from "./../../../services/vault-popup-autof
|
||||||
selector: "app-view-v2",
|
selector: "app-view-v2",
|
||||||
templateUrl: "view-v2.component.html",
|
templateUrl: "view-v2.component.html",
|
||||||
standalone: true,
|
standalone: true,
|
||||||
providers: [{ provide: TotpCaptureService, useClass: BrowserTotpCaptureService }],
|
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
SearchModule,
|
SearchModule,
|
||||||
|
|
|
@ -13,15 +13,10 @@ describe("BrowserTotpCaptureService", () => {
|
||||||
let testBed: TestBed;
|
let testBed: TestBed;
|
||||||
let service: BrowserTotpCaptureService;
|
let service: BrowserTotpCaptureService;
|
||||||
let mockCaptureVisibleTab: jest.SpyInstance;
|
let mockCaptureVisibleTab: jest.SpyInstance;
|
||||||
let createNewTabSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
const validTotpUrl = "otpauth://totp/label?secret=123";
|
const validTotpUrl = "otpauth://totp/label?secret=123";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const tabReturn = new Promise<chrome.tabs.Tab>((resolve) =>
|
|
||||||
resolve({ url: "google.com", active: true } as chrome.tabs.Tab),
|
|
||||||
);
|
|
||||||
createNewTabSpy = jest.spyOn(BrowserApi, "createNewTab").mockReturnValue(tabReturn);
|
|
||||||
mockCaptureVisibleTab = jest.spyOn(BrowserApi, "captureVisibleTab");
|
mockCaptureVisibleTab = jest.spyOn(BrowserApi, "captureVisibleTab");
|
||||||
mockCaptureVisibleTab.mockResolvedValue("screenshot");
|
mockCaptureVisibleTab.mockResolvedValue("screenshot");
|
||||||
|
|
||||||
|
@ -71,10 +66,4 @@ describe("BrowserTotpCaptureService", () => {
|
||||||
|
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call BrowserApi.createNewTab with a given loginURI", async () => {
|
|
||||||
await service.openAutofillNewTab("www.google.com");
|
|
||||||
|
|
||||||
expect(createNewTabSpy).toHaveBeenCalledWith("www.google.com");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,8 +20,4 @@ export class BrowserTotpCaptureService implements TotpCaptureService {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async openAutofillNewTab(loginUri: string) {
|
|
||||||
await BrowserApi.createNewTab(loginUri);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
/**
|
|
||||||
* TODO: PM-10727 - Rename and Refactor this service
|
|
||||||
* This service is being used in both CipherForm and CipherView. Update this service to reflect that
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to capture TOTP secret from a client application.
|
* Service to capture TOTP secret from a client application.
|
||||||
*/
|
*/
|
||||||
|
@ -11,5 +6,4 @@ export abstract class TotpCaptureService {
|
||||||
* Captures a TOTP secret and returns it as a string. Returns null if no TOTP secret was found.
|
* Captures a TOTP secret and returns it as a string. Returns null if no TOTP secret was found.
|
||||||
*/
|
*/
|
||||||
abstract captureTotpSecret(): Promise<string | null>;
|
abstract captureTotpSecret(): Promise<string | null>;
|
||||||
abstract openAutofillNewTab(loginUri: string): void;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,17 @@ import { CommonModule } from "@angular/common";
|
||||||
import { Component, Input } from "@angular/core";
|
import { Component, Input } from "@angular/core";
|
||||||
|
|
||||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||||
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
|
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
|
||||||
import {
|
import {
|
||||||
CardComponent,
|
CardComponent,
|
||||||
FormFieldModule,
|
FormFieldModule,
|
||||||
|
IconButtonModule,
|
||||||
SectionComponent,
|
SectionComponent,
|
||||||
SectionHeaderComponent,
|
SectionHeaderComponent,
|
||||||
TypographyModule,
|
TypographyModule,
|
||||||
IconButtonModule,
|
|
||||||
} from "@bitwarden/components";
|
} from "@bitwarden/components";
|
||||||
|
|
||||||
import { TotpCaptureService } from "../../cipher-form";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-autofill-options-view",
|
selector: "app-autofill-options-view",
|
||||||
templateUrl: "autofill-options-view.component.html",
|
templateUrl: "autofill-options-view.component.html",
|
||||||
|
@ -32,9 +31,9 @@ import { TotpCaptureService } from "../../cipher-form";
|
||||||
export class AutofillOptionsViewComponent {
|
export class AutofillOptionsViewComponent {
|
||||||
@Input() loginUris: LoginUriView[];
|
@Input() loginUris: LoginUriView[];
|
||||||
|
|
||||||
constructor(private totpCaptureService: TotpCaptureService) {}
|
constructor(private platformUtilsService: PlatformUtilsService) {}
|
||||||
|
|
||||||
async openWebsite(selectedUri: string) {
|
openWebsite(selectedUri: string) {
|
||||||
await this.totpCaptureService.openAutofillNewTab(selectedUri);
|
this.platformUtilsService.launchUri(selectedUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue