mirror of
https://github.com/bitwarden/clients.git
synced 2026-07-07 21:10:55 +08:00
automatically autofill in search results (#19951)
This commit is contained in:
parent
92b04c24fe
commit
51a306f5cd
@ -60,6 +60,7 @@ describe("ItemMoreOptionsComponent", () => {
|
||||
|
||||
const domainSettingsService = {
|
||||
resolvedDefaultUriMatchStrategy$: uriMatchStrategy$.asObservable(),
|
||||
getUrlEquivalentDomains: jest.fn().mockReturnValue(of(new Set<string>())),
|
||||
};
|
||||
|
||||
const baseCipher = {
|
||||
@ -137,6 +138,10 @@ describe("ItemMoreOptionsComponent", () => {
|
||||
}
|
||||
|
||||
describe("doAutofill", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(component as any, "_domainMatched").mockResolvedValue(false);
|
||||
});
|
||||
|
||||
it("calls the passwordService to passwordRepromptCheck", async () => {
|
||||
autofillSvc.currentAutofillTab$.next({ url: "https://page.example.com" });
|
||||
mockConfirmDialogResult(AutofillConfirmationDialogResult.AutofilledOnly);
|
||||
@ -162,6 +167,22 @@ describe("ItemMoreOptionsComponent", () => {
|
||||
beforeEach(() => {
|
||||
uriMatchStrategy$.next(UriMatchStrategy.Domain);
|
||||
passwordRepromptService.passwordRepromptCheck.mockResolvedValue(true);
|
||||
jest.spyOn(component as any, "_domainMatched").mockResolvedValue(false);
|
||||
});
|
||||
|
||||
it("autofills directly without showing confirmation dialog when domain matches", async () => {
|
||||
autofillSvc.currentAutofillTab$.next({ url: "https://one.example.com" });
|
||||
jest.spyOn(component as any, "_domainMatched").mockResolvedValue(true);
|
||||
const openSpy = jest.spyOn(AutofillConfirmationDialogComponent, "open");
|
||||
|
||||
await component.doAutofill();
|
||||
|
||||
expect(openSpy).not.toHaveBeenCalled();
|
||||
expect(autofillSvc.doAutofill).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: "cipher-1" }),
|
||||
true,
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("calls the passwordService to passwordRepromptCheck", async () => {
|
||||
|
||||
@ -235,6 +235,11 @@ export class ItemMoreOptionsComponent {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await this._domainMatched(currentTab.url)) {
|
||||
await this.vaultPopupAutofillService.doAutofill(cipher, true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
const ref = AutofillConfirmationDialogComponent.open(this.dialogService, {
|
||||
data: {
|
||||
currentUrl: currentTab?.url || "",
|
||||
@ -257,6 +262,17 @@ export class ItemMoreOptionsComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private async _domainMatched(url: string): Promise<boolean> {
|
||||
const equivalentDomains = await firstValueFrom(
|
||||
this.domainSettingsService.getUrlEquivalentDomains(url),
|
||||
);
|
||||
const defaultMatch = await firstValueFrom(
|
||||
this.domainSettingsService.resolvedDefaultUriMatchStrategy$,
|
||||
);
|
||||
|
||||
return CipherViewLikeUtils.matchesUri(this.cipher, url, equivalentDomains, defaultMatch);
|
||||
}
|
||||
|
||||
async onView() {
|
||||
const repromptPassed = await this.passwordRepromptService.passwordRepromptCheck(this.cipher);
|
||||
if (!repromptPassed) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user