mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
Remove deprecated encstring usage from dirt code (#17100)
This commit is contained in:
@@ -8,12 +8,15 @@ import { BehaviorSubject, debounceTime, firstValueFrom, lastValueFrom } from "rx
|
|||||||
|
|
||||||
import { UserNamePipe } from "@bitwarden/angular/pipes/user-name.pipe";
|
import { UserNamePipe } from "@bitwarden/angular/pipes/user-name.pipe";
|
||||||
import { safeProvider } from "@bitwarden/angular/platform/utils/safe-provider";
|
import { safeProvider } from "@bitwarden/angular/platform/utils/safe-provider";
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions";
|
import { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions";
|
||||||
import { OrganizationMetadataServiceAbstraction } from "@bitwarden/common/billing/abstractions/organization-metadata.service.abstraction";
|
import { OrganizationMetadataServiceAbstraction } from "@bitwarden/common/billing/abstractions/organization-metadata.service.abstraction";
|
||||||
|
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { OrganizationId } from "@bitwarden/common/types/guid";
|
import { OrganizationId } from "@bitwarden/common/types/guid";
|
||||||
import { DialogService, SearchModule, TableDataSource } from "@bitwarden/components";
|
import { DialogService, SearchModule, TableDataSource } from "@bitwarden/components";
|
||||||
|
import { KeyService } from "@bitwarden/key-management";
|
||||||
import { ExportHelper } from "@bitwarden/vault-export-core";
|
import { ExportHelper } from "@bitwarden/vault-export-core";
|
||||||
import { CoreOrganizationModule } from "@bitwarden/web-vault/app/admin-console/organizations/core";
|
import { CoreOrganizationModule } from "@bitwarden/web-vault/app/admin-console/organizations/core";
|
||||||
import {
|
import {
|
||||||
@@ -41,7 +44,7 @@ import { MemberAccessReportView } from "./view/member-access-report.view";
|
|||||||
safeProvider({
|
safeProvider({
|
||||||
provide: MemberAccessReportServiceAbstraction,
|
provide: MemberAccessReportServiceAbstraction,
|
||||||
useClass: MemberAccessReportService,
|
useClass: MemberAccessReportService,
|
||||||
deps: [MemberAccessReportApiService, I18nService],
|
deps: [MemberAccessReportApiService, I18nService, EncryptService, KeyService, AccountService],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import { mock } from "jest-mock-extended";
|
import { mock } from "jest-mock-extended";
|
||||||
|
import { of } from "rxjs";
|
||||||
|
|
||||||
|
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { OrganizationId } from "@bitwarden/common/types/guid";
|
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||||
|
import { mockAccountServiceWith } from "@bitwarden/common/spec";
|
||||||
|
import { OrganizationId, UserId } from "@bitwarden/common/types/guid";
|
||||||
|
import { newGuid } from "@bitwarden/guid";
|
||||||
|
import { KeyService } from "@bitwarden/key-management";
|
||||||
|
|
||||||
import { MemberAccessReportApiService } from "./member-access-report-api.service";
|
import { MemberAccessReportApiService } from "./member-access-report-api.service";
|
||||||
import {
|
import {
|
||||||
@@ -9,9 +15,14 @@ import {
|
|||||||
memberAccessWithoutAccessDetailsReportsMock,
|
memberAccessWithoutAccessDetailsReportsMock,
|
||||||
} from "./member-access-report.mock";
|
} from "./member-access-report.mock";
|
||||||
import { MemberAccessReportService } from "./member-access-report.service";
|
import { MemberAccessReportService } from "./member-access-report.service";
|
||||||
|
|
||||||
describe("ImportService", () => {
|
describe("ImportService", () => {
|
||||||
const mockOrganizationId = "mockOrgId" as OrganizationId;
|
const mockOrganizationId = "mockOrgId" as OrganizationId;
|
||||||
const reportApiService = mock<MemberAccessReportApiService>();
|
const reportApiService = mock<MemberAccessReportApiService>();
|
||||||
|
const mockEncryptService = mock<EncryptService>();
|
||||||
|
const userId = newGuid() as UserId;
|
||||||
|
const mockAccountService = mockAccountServiceWith(userId);
|
||||||
|
const mockKeyService = mock<KeyService>();
|
||||||
let memberAccessReportService: MemberAccessReportService;
|
let memberAccessReportService: MemberAccessReportService;
|
||||||
const i18nMock = mock<I18nService>({
|
const i18nMock = mock<I18nService>({
|
||||||
t(key) {
|
t(key) {
|
||||||
@@ -20,10 +31,19 @@ describe("ImportService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockKeyService.orgKeys$.mockReturnValue(
|
||||||
|
of({ mockOrgId: new SymmetricCryptoKey(new Uint8Array(64)) }),
|
||||||
|
);
|
||||||
reportApiService.getMemberAccessData.mockImplementation(() =>
|
reportApiService.getMemberAccessData.mockImplementation(() =>
|
||||||
Promise.resolve(memberAccessReportsMock),
|
Promise.resolve(memberAccessReportsMock),
|
||||||
);
|
);
|
||||||
memberAccessReportService = new MemberAccessReportService(reportApiService, i18nMock);
|
memberAccessReportService = new MemberAccessReportService(
|
||||||
|
reportApiService,
|
||||||
|
i18nMock,
|
||||||
|
mockEncryptService,
|
||||||
|
mockKeyService,
|
||||||
|
mockAccountService,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("generateMemberAccessReportView", () => {
|
describe("generateMemberAccessReportView", () => {
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
// FIXME: Update this file to be type safe and remove this and next line
|
||||||
// @ts-strict-ignore
|
// @ts-strict-ignore
|
||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
|
import { firstValueFrom, map } from "rxjs";
|
||||||
|
|
||||||
import { CollectionAccessSelectionView } from "@bitwarden/admin-console/common";
|
import { CollectionAccessSelectionView } from "@bitwarden/admin-console/common";
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
|
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
|
||||||
import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string";
|
import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { Guid, OrganizationId } from "@bitwarden/common/types/guid";
|
import { Guid, OrganizationId } from "@bitwarden/common/types/guid";
|
||||||
|
import { KeyService } from "@bitwarden/key-management";
|
||||||
import {
|
import {
|
||||||
getPermissionList,
|
getPermissionList,
|
||||||
convertToPermission,
|
convertToPermission,
|
||||||
@@ -22,6 +27,9 @@ export class MemberAccessReportService {
|
|||||||
constructor(
|
constructor(
|
||||||
private reportApiService: MemberAccessReportApiService,
|
private reportApiService: MemberAccessReportApiService,
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
|
private keyService: KeyService,
|
||||||
|
private accountService: AccountService,
|
||||||
) {}
|
) {}
|
||||||
/**
|
/**
|
||||||
* Transforms user data into a MemberAccessReportView.
|
* Transforms user data into a MemberAccessReportView.
|
||||||
@@ -78,14 +86,22 @@ export class MemberAccessReportService {
|
|||||||
async generateUserReportExportItems(
|
async generateUserReportExportItems(
|
||||||
organizationId: OrganizationId,
|
organizationId: OrganizationId,
|
||||||
): Promise<MemberAccessExportItem[]> {
|
): Promise<MemberAccessExportItem[]> {
|
||||||
|
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||||
|
const organizationSymmetricKey = await firstValueFrom(
|
||||||
|
this.keyService.orgKeys$(activeUserId).pipe(map((keys) => keys[organizationId])),
|
||||||
|
);
|
||||||
|
|
||||||
const memberAccessReports = await this.reportApiService.getMemberAccessData(organizationId);
|
const memberAccessReports = await this.reportApiService.getMemberAccessData(organizationId);
|
||||||
const collectionNames = memberAccessReports.map((item) => item.collectionName.encryptedString);
|
const collectionNames = memberAccessReports.map((item) => item.collectionName.encryptedString);
|
||||||
|
|
||||||
const collectionNameMap = new Map(collectionNames.map((col) => [col, ""]));
|
const collectionNameMap = new Map(collectionNames.map((col) => [col, ""]));
|
||||||
for await (const key of collectionNameMap.keys()) {
|
for await (const key of collectionNameMap.keys()) {
|
||||||
const decrypted = new EncString(key);
|
const encryptedCollectionName = new EncString(key);
|
||||||
await decrypted.decrypt(organizationId);
|
const collectionName = await this.encryptService.decryptString(
|
||||||
collectionNameMap.set(key, decrypted.decryptedValue);
|
encryptedCollectionName,
|
||||||
|
organizationSymmetricKey,
|
||||||
|
);
|
||||||
|
collectionNameMap.set(key, collectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportItems = memberAccessReports.map((report) => {
|
const exportItems = memberAccessReports.map((report) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user