mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
[PM-9613] port forwarders to integrations (#10075)
* introduced forwarder integrations * simply contexts * report error and message when both are present in an RPC response
This commit is contained in:
@@ -5,7 +5,8 @@ import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.se
|
||||
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { StateProvider } from "@bitwarden/common/platform/state";
|
||||
import { engine, services, strategies } from "@bitwarden/generator-core";
|
||||
import { RestClient } from "@bitwarden/common/tools/integration/rpc";
|
||||
import { engine, services, strategies, Integrations } from "@bitwarden/generator-core";
|
||||
import { DefaultGeneratorNavigationService } from "@bitwarden/generator-navigation";
|
||||
|
||||
import { LegacyUsernameGenerationService } from "./legacy-username-generation.service";
|
||||
@@ -17,12 +18,7 @@ const {
|
||||
CatchallGeneratorStrategy,
|
||||
SubaddressGeneratorStrategy,
|
||||
EffUsernameGeneratorStrategy,
|
||||
AddyIoForwarder,
|
||||
DuckDuckGoForwarder,
|
||||
FastmailForwarder,
|
||||
FirefoxRelayForwarder,
|
||||
ForwardEmailForwarder,
|
||||
SimpleLoginForwarder,
|
||||
ForwarderGeneratorStrategy,
|
||||
} = strategies;
|
||||
|
||||
export function legacyUsernameGenerationServiceFactory(
|
||||
@@ -35,6 +31,7 @@ export function legacyUsernameGenerationServiceFactory(
|
||||
stateProvider: StateProvider,
|
||||
): UsernameGenerationServiceAbstraction {
|
||||
const randomizer = new CryptoServiceRandomizer(cryptoService);
|
||||
const restClient = new RestClient(apiService, i18nService);
|
||||
const usernameRandomizer = new UsernameRandomizer(randomizer);
|
||||
const emailRandomizer = new EmailRandomizer(randomizer);
|
||||
const emailCalculator = new EmailCalculator();
|
||||
@@ -55,23 +52,45 @@ export function legacyUsernameGenerationServiceFactory(
|
||||
);
|
||||
|
||||
const addyIo = new DefaultGeneratorService(
|
||||
new AddyIoForwarder(apiService, i18nService, encryptService, cryptoService, stateProvider),
|
||||
new ForwarderGeneratorStrategy(
|
||||
Integrations.AddyIo,
|
||||
restClient,
|
||||
i18nService,
|
||||
encryptService,
|
||||
cryptoService,
|
||||
stateProvider,
|
||||
),
|
||||
policyService,
|
||||
);
|
||||
|
||||
const duckDuckGo = new DefaultGeneratorService(
|
||||
new DuckDuckGoForwarder(apiService, i18nService, encryptService, cryptoService, stateProvider),
|
||||
new ForwarderGeneratorStrategy(
|
||||
Integrations.DuckDuckGo,
|
||||
restClient,
|
||||
i18nService,
|
||||
encryptService,
|
||||
cryptoService,
|
||||
stateProvider,
|
||||
),
|
||||
policyService,
|
||||
);
|
||||
|
||||
const fastmail = new DefaultGeneratorService(
|
||||
new FastmailForwarder(apiService, i18nService, encryptService, cryptoService, stateProvider),
|
||||
new ForwarderGeneratorStrategy(
|
||||
Integrations.Fastmail,
|
||||
restClient,
|
||||
i18nService,
|
||||
encryptService,
|
||||
cryptoService,
|
||||
stateProvider,
|
||||
),
|
||||
policyService,
|
||||
);
|
||||
|
||||
const firefoxRelay = new DefaultGeneratorService(
|
||||
new FirefoxRelayForwarder(
|
||||
apiService,
|
||||
new ForwarderGeneratorStrategy(
|
||||
Integrations.FirefoxRelay,
|
||||
restClient,
|
||||
i18nService,
|
||||
encryptService,
|
||||
cryptoService,
|
||||
@@ -81,8 +100,9 @@ export function legacyUsernameGenerationServiceFactory(
|
||||
);
|
||||
|
||||
const forwardEmail = new DefaultGeneratorService(
|
||||
new ForwardEmailForwarder(
|
||||
apiService,
|
||||
new ForwarderGeneratorStrategy(
|
||||
Integrations.ForwardEmail,
|
||||
restClient,
|
||||
i18nService,
|
||||
encryptService,
|
||||
cryptoService,
|
||||
@@ -92,7 +112,14 @@ export function legacyUsernameGenerationServiceFactory(
|
||||
);
|
||||
|
||||
const simpleLogin = new DefaultGeneratorService(
|
||||
new SimpleLoginForwarder(apiService, i18nService, encryptService, cryptoService, stateProvider),
|
||||
new ForwarderGeneratorStrategy(
|
||||
Integrations.SimpleLogin,
|
||||
restClient,
|
||||
i18nService,
|
||||
encryptService,
|
||||
cryptoService,
|
||||
stateProvider,
|
||||
),
|
||||
policyService,
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { mock } from "jest-mock-extended";
|
||||
import { of } from "rxjs";
|
||||
|
||||
import { IntegrationId } from "@bitwarden/common/tools/integration";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import {
|
||||
GeneratorService,
|
||||
@@ -185,7 +186,7 @@ describe("LegacyPasswordGenerationService", () => {
|
||||
const navigation = createNavigationGenerator({
|
||||
type: "passphrase",
|
||||
username: "word",
|
||||
forwarder: "simplelogin",
|
||||
forwarder: "simplelogin" as IntegrationId,
|
||||
});
|
||||
const accountService = mockAccountServiceWith(SomeUser);
|
||||
const generator = new LegacyPasswordGenerationService(
|
||||
@@ -496,7 +497,7 @@ describe("LegacyPasswordGenerationService", () => {
|
||||
const navigation = createNavigationGenerator({
|
||||
type: "password",
|
||||
username: "forwarded",
|
||||
forwarder: "firefoxrelay",
|
||||
forwarder: "firefoxrelay" as IntegrationId,
|
||||
});
|
||||
const accountService = mockAccountServiceWith(SomeUser);
|
||||
const generator = new LegacyPasswordGenerationService(
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
DefaultSubaddressOptions,
|
||||
SubaddressGenerationOptions,
|
||||
policies,
|
||||
Integrations,
|
||||
} from "@bitwarden/generator-core";
|
||||
import {
|
||||
GeneratorNavigationPolicy,
|
||||
@@ -724,7 +725,7 @@ describe("LegacyUsernameGenerationService", () => {
|
||||
});
|
||||
|
||||
options.type = "forwarded";
|
||||
options.forwardedService = "anonaddy";
|
||||
options.forwardedService = Integrations.AddyIo.id;
|
||||
await generator.saveOptions(options);
|
||||
|
||||
expect(addyIo.saveOptions).toHaveBeenCalledWith(SomeUser, {
|
||||
@@ -735,7 +736,7 @@ describe("LegacyUsernameGenerationService", () => {
|
||||
});
|
||||
|
||||
options.type = "forwarded";
|
||||
options.forwardedService = "duckduckgo";
|
||||
options.forwardedService = Integrations.DuckDuckGo.id;
|
||||
await generator.saveOptions(options);
|
||||
|
||||
expect(duckDuckGo.saveOptions).toHaveBeenCalledWith(SomeUser, {
|
||||
@@ -744,7 +745,7 @@ describe("LegacyUsernameGenerationService", () => {
|
||||
});
|
||||
|
||||
options.type = "forwarded";
|
||||
options.forwardedService = "fastmail";
|
||||
options.forwardedService = Integrations.Fastmail.id;
|
||||
await generator.saveOptions(options);
|
||||
|
||||
expect(fastmail.saveOptions).toHaveBeenCalledWith(SomeUser, {
|
||||
@@ -753,7 +754,7 @@ describe("LegacyUsernameGenerationService", () => {
|
||||
});
|
||||
|
||||
options.type = "forwarded";
|
||||
options.forwardedService = "firefoxrelay";
|
||||
options.forwardedService = Integrations.FirefoxRelay.id;
|
||||
await generator.saveOptions(options);
|
||||
|
||||
expect(firefoxRelay.saveOptions).toHaveBeenCalledWith(SomeUser, {
|
||||
@@ -762,7 +763,7 @@ describe("LegacyUsernameGenerationService", () => {
|
||||
});
|
||||
|
||||
options.type = "forwarded";
|
||||
options.forwardedService = "forwardemail";
|
||||
options.forwardedService = Integrations.ForwardEmail.id;
|
||||
await generator.saveOptions(options);
|
||||
|
||||
expect(forwardEmail.saveOptions).toHaveBeenCalledWith(SomeUser, {
|
||||
@@ -772,7 +773,7 @@ describe("LegacyUsernameGenerationService", () => {
|
||||
});
|
||||
|
||||
options.type = "forwarded";
|
||||
options.forwardedService = "simplelogin";
|
||||
options.forwardedService = Integrations.SimpleLogin.id;
|
||||
await generator.saveOptions(options);
|
||||
|
||||
expect(simpleLogin.saveOptions).toHaveBeenCalledWith(SomeUser, {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { zip, firstValueFrom, map, concatMap, combineLatest } from "rxjs";
|
||||
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { IntegrationRequest } from "@bitwarden/common/tools/integration/rpc";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import {
|
||||
ApiOptions,
|
||||
EmailDomainOptions,
|
||||
EmailPrefixOptions,
|
||||
RequestOptions,
|
||||
SelfHostedApiOptions,
|
||||
NoPolicy,
|
||||
GeneratorService,
|
||||
@@ -30,12 +30,12 @@ type MappedOptions = {
|
||||
subaddress: SubaddressGenerationOptions;
|
||||
};
|
||||
forwarders: {
|
||||
addyIo: SelfHostedApiOptions & EmailDomainOptions & RequestOptions;
|
||||
duckDuckGo: ApiOptions & RequestOptions;
|
||||
fastmail: ApiOptions & EmailPrefixOptions & RequestOptions;
|
||||
firefoxRelay: ApiOptions & RequestOptions;
|
||||
forwardEmail: ApiOptions & EmailDomainOptions & RequestOptions;
|
||||
simpleLogin: SelfHostedApiOptions & RequestOptions;
|
||||
addyIo: SelfHostedApiOptions & EmailDomainOptions & IntegrationRequest;
|
||||
duckDuckGo: ApiOptions & IntegrationRequest;
|
||||
fastmail: ApiOptions & EmailPrefixOptions & IntegrationRequest;
|
||||
firefoxRelay: ApiOptions & IntegrationRequest;
|
||||
forwardEmail: ApiOptions & EmailDomainOptions & IntegrationRequest;
|
||||
simpleLogin: SelfHostedApiOptions & IntegrationRequest;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IntegrationRequest } from "@bitwarden/common/tools/integration/rpc";
|
||||
import {
|
||||
ForwarderId,
|
||||
RequestOptions,
|
||||
CatchallGenerationOptions,
|
||||
EffUsernameGenerationOptions,
|
||||
SubaddressGenerationOptions,
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
export type UsernameGeneratorOptions = EffUsernameGenerationOptions &
|
||||
SubaddressGenerationOptions &
|
||||
CatchallGenerationOptions &
|
||||
RequestOptions & {
|
||||
IntegrationRequest & {
|
||||
type?: UsernameGeneratorType;
|
||||
forwardedService?: ForwarderId | "";
|
||||
forwardedAnonAddyApiToken?: string;
|
||||
|
||||
Reference in New Issue
Block a user