1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-5574] sends state provider (#8373)

* Adding the key definitions and tests and initial send state service

* Adding the abstraction and implementing

* Planning comments

* Everything but fixing the send tests

* Moving send tests over to the state provider

* jslib needed name refactor

* removing get/set encrypted sends from web vault state service

* browser send state service factory

* Fixing conflicts

* Removing send service from services module and fixing send service observable

* Commenting the migrator to be clear on why only encrypted

* No need for service factories in browser

* browser send service is no longer needed

* Key def test cases to use toStrictEqual

* Running prettier

* Creating send test data to avoid code duplication

* Adding state provider and account service to send in cli

* Fixing the send service test cases

* Fixing state definition keys

* Moving to observables and implementing encryption service

* Fixing key def tests

* The cli was using the deprecated get method

* The observables init doesn't need to happen in constructor

* Missed commented out code

* If enc key is null get user key

* Service factory fix
This commit is contained in:
Tom
2024-04-02 12:39:06 -04:00
committed by GitHub
parent 9956f020e7
commit a6e178f1e6
25 changed files with 767 additions and 327 deletions

View File

@@ -146,6 +146,7 @@ import {
} from "@bitwarden/common/tools/password-strength";
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service";
import { SendApiService as SendApiServiceAbstraction } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
import { SendStateProvider } from "@bitwarden/common/tools/send/services/send-state.provider";
import { SendService } from "@bitwarden/common/tools/send/services/send.service";
import { InternalSendService as InternalSendServiceAbstraction } from "@bitwarden/common/tools/send/services/send.service.abstraction";
import { UserId } from "@bitwarden/common/types/guid";
@@ -276,6 +277,7 @@ export default class MainBackground {
eventUploadService: EventUploadServiceAbstraction;
policyService: InternalPolicyServiceAbstraction;
sendService: InternalSendServiceAbstraction;
sendStateProvider: SendStateProvider;
fileUploadService: FileUploadServiceAbstraction;
cipherFileUploadService: CipherFileUploadServiceAbstraction;
organizationService: InternalOrganizationServiceAbstraction;
@@ -707,11 +709,14 @@ export default class MainBackground {
logoutCallback,
);
this.containerService = new ContainerService(this.cryptoService, this.encryptService);
this.sendStateProvider = new SendStateProvider(this.stateProvider);
this.sendService = new SendService(
this.cryptoService,
this.i18nService,
this.keyGenerationService,
this.stateService,
this.sendStateProvider,
this.encryptService,
);
this.sendApiService = new SendApiService(
this.apiService,

View File

@@ -5,6 +5,10 @@ import {
CryptoServiceInitOptions,
cryptoServiceFactory,
} from "../../platform/background/service-factories/crypto-service.factory";
import {
EncryptServiceInitOptions,
encryptServiceFactory,
} from "../../platform/background/service-factories/encrypt-service.factory";
import {
FactoryOptions,
CachedServices,
@@ -18,10 +22,11 @@ import {
KeyGenerationServiceInitOptions,
keyGenerationServiceFactory,
} from "../../platform/background/service-factories/key-generation-service.factory";
import {
stateServiceFactory,
StateServiceInitOptions,
} from "../../platform/background/service-factories/state-service.factory";
SendStateProviderInitOptions,
sendStateProviderFactory,
} from "./send-state-provider.factory";
type SendServiceFactoryOptions = FactoryOptions;
@@ -29,7 +34,8 @@ export type SendServiceInitOptions = SendServiceFactoryOptions &
CryptoServiceInitOptions &
I18nServiceInitOptions &
KeyGenerationServiceInitOptions &
StateServiceInitOptions;
SendStateProviderInitOptions &
EncryptServiceInitOptions;
export function sendServiceFactory(
cache: { sendService?: InternalSendService } & CachedServices,
@@ -44,7 +50,8 @@ export function sendServiceFactory(
await cryptoServiceFactory(cache, opts),
await i18nServiceFactory(cache, opts),
await keyGenerationServiceFactory(cache, opts),
await stateServiceFactory(cache, opts),
await sendStateProviderFactory(cache, opts),
await encryptServiceFactory(cache, opts),
),
);
}

View File

@@ -0,0 +1,28 @@
import { SendStateProvider } from "@bitwarden/common/tools/send/services/send-state.provider";
import {
CachedServices,
FactoryOptions,
factory,
} from "../../platform/background/service-factories/factory-options";
import {
StateProviderInitOptions,
stateProviderFactory,
} from "../../platform/background/service-factories/state-provider.factory";
type SendStateProviderFactoryOptions = FactoryOptions;
export type SendStateProviderInitOptions = SendStateProviderFactoryOptions &
StateProviderInitOptions;
export function sendStateProviderFactory(
cache: { sendStateProvider?: SendStateProvider } & CachedServices,
opts: SendStateProviderInitOptions,
): Promise<SendStateProvider> {
return factory(
cache,
"sendStateProvider",
opts,
async () => new SendStateProvider(await stateProviderFactory(cache, opts)),
);
}

View File

@@ -106,6 +106,7 @@ import {
PasswordStrengthServiceAbstraction,
} from "@bitwarden/common/tools/password-strength";
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service";
import { SendStateProvider } from "@bitwarden/common/tools/send/services/send-state.provider";
import { SendService } from "@bitwarden/common/tools/send/services/send.service";
import { UserId } from "@bitwarden/common/types/guid";
import { InternalFolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
@@ -194,6 +195,7 @@ export class Main {
sendProgram: SendProgram;
logService: ConsoleLogService;
sendService: SendService;
sendStateProvider: SendStateProvider;
fileUploadService: FileUploadService;
cipherFileUploadService: CipherFileUploadService;
keyConnectorService: KeyConnectorService;
@@ -388,11 +390,14 @@ export class Main {
this.fileUploadService = new FileUploadService(this.logService);
this.sendStateProvider = new SendStateProvider(this.stateProvider);
this.sendService = new SendService(
this.cryptoService,
this.i18nService,
this.keyGenerationService,
this.stateService,
this.sendStateProvider,
this.encryptService,
);
this.cipherFileUploadService = new CipherFileUploadService(

View File

@@ -18,7 +18,7 @@ export class SendRemovePasswordCommand {
try {
await this.sendApiService.removePassword(id);
const updatedSend = await this.sendService.get(id);
const updatedSend = await firstValueFrom(this.sendService.get$(id));
const decSend = await updatedSend.decrypt();
const env = await firstValueFrom(this.environmentService.environment$);
const webVaultUrl = env.getWebVaultUrl();

View File

@@ -18,7 +18,6 @@ import { StateFactory } from "@bitwarden/common/platform/factories/state-factory
import { StorageOptions } from "@bitwarden/common/platform/models/domain/storage-options";
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
import { StateService as BaseStateService } from "@bitwarden/common/platform/services/state.service";
import { SendData } from "@bitwarden/common/tools/send/models/data/send.data";
import { CipherData } from "@bitwarden/common/vault/models/data/cipher.data";
import { Account } from "./account";
@@ -71,19 +70,6 @@ export class StateService extends BaseStateService<GlobalState, Account> {
return await super.setEncryptedCiphers(value, options);
}
async getEncryptedSends(options?: StorageOptions): Promise<{ [id: string]: SendData }> {
options = this.reconcileOptions(options, await this.defaultInMemoryOptions());
return await super.getEncryptedSends(options);
}
async setEncryptedSends(
value: { [id: string]: SendData },
options?: StorageOptions,
): Promise<void> {
options = this.reconcileOptions(options, await this.defaultInMemoryOptions());
return await super.setEncryptedSends(value, options);
}
override async getLastSync(options?: StorageOptions): Promise<string> {
options = this.reconcileOptions(options, await this.defaultInMemoryOptions());
return await super.getLastSync(options);