1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 10:13:31 +00:00

feat(accounts): Add creationDate of account to AccountInfo

* Add creationDate of account to AccountInfo

* Added initialization of creationDate.

* Removed extra changes.

* Fixed tests to initialize creation date

* Added helper method to abstract account initialization in tests.

* More test updates.

* Linting

* Additional test fixes.

* Fixed spec reference

* Fixed imports

* Linting.

* Fixed browser test.

* Modified tsconfig to reference spec file.

* Fixed import.

* Removed dependency on os.  This is necessary so that the @bitwarden/common/spec lib package can be referenced in tests without node.

* Revert "Removed dependency on os.  This is necessary so that the @bitwarden/common/spec lib package can be referenced in tests without node."

This reverts commit 669f6557b6.

* Updated stories to hard-code new field.

* Removed changes to tsconfig

* Revert "Removed changes to tsconfig"

This reverts commit b7d916e8dc.
This commit is contained in:
Todd Martin
2025-12-12 10:03:31 -05:00
committed by GitHub
parent be9d0c0291
commit 27d82aaf28
60 changed files with 491 additions and 276 deletions

View File

@@ -15,6 +15,7 @@ import {
} from "@bitwarden/common/platform/abstractions/environment.service"; } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { AccountSwitcherService } from "./account-switcher.service"; import { AccountSwitcherService } from "./account-switcher.service";
@@ -71,11 +72,10 @@ describe("AccountSwitcherService", () => {
describe("availableAccounts$", () => { describe("availableAccounts$", () => {
it("should return all logged in accounts and an add account option when accounts are less than 5", async () => { it("should return all logged in accounts and an add account option when accounts are less than 5", async () => {
const accountInfo: AccountInfo = { const accountInfo = mockAccountInfoWith({
name: "Test User 1", name: "Test User 1",
email: "test1@email.com", email: "test1@email.com",
emailVerified: true, });
};
avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc")); avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc"));
accountsSubject.next({ ["1" as UserId]: accountInfo, ["2" as UserId]: accountInfo }); accountsSubject.next({ ["1" as UserId]: accountInfo, ["2" as UserId]: accountInfo });
@@ -109,11 +109,10 @@ describe("AccountSwitcherService", () => {
const seedAccounts: Record<UserId, AccountInfo> = {}; const seedAccounts: Record<UserId, AccountInfo> = {};
const seedStatuses: Record<UserId, AuthenticationStatus> = {}; const seedStatuses: Record<UserId, AuthenticationStatus> = {};
for (let i = 0; i < numberOfAccounts; i++) { for (let i = 0; i < numberOfAccounts; i++) {
seedAccounts[`${i}` as UserId] = { seedAccounts[`${i}` as UserId] = mockAccountInfoWith({
email: `test${i}@email.com`, email: `test${i}@email.com`,
emailVerified: true,
name: "Test User ${i}", name: "Test User ${i}",
}; });
seedStatuses[`${i}` as UserId] = AuthenticationStatus.Unlocked; seedStatuses[`${i}` as UserId] = AuthenticationStatus.Unlocked;
} }
avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc")); avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc"));
@@ -133,11 +132,10 @@ describe("AccountSwitcherService", () => {
); );
it("excludes logged out accounts", async () => { it("excludes logged out accounts", async () => {
const user1AccountInfo: AccountInfo = { const user1AccountInfo = mockAccountInfoWith({
name: "Test User 1", name: "Test User 1",
email: "", email: "",
emailVerified: true, });
};
accountsSubject.next({ ["1" as UserId]: user1AccountInfo }); accountsSubject.next({ ["1" as UserId]: user1AccountInfo });
authStatusSubject.next({ ["1" as UserId]: AuthenticationStatus.LoggedOut }); authStatusSubject.next({ ["1" as UserId]: AuthenticationStatus.LoggedOut });
accountsSubject.next({ accountsSubject.next({

View File

@@ -4,7 +4,7 @@ import { BehaviorSubject, firstValueFrom, of } from "rxjs";
import { CollectionService } from "@bitwarden/admin-console/common"; import { CollectionService } from "@bitwarden/admin-console/common";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { AuthService } from "@bitwarden/common/auth/services/auth.service"; import { AuthService } from "@bitwarden/common/auth/services/auth.service";
import { ExtensionCommand } from "@bitwarden/common/autofill/constants"; import { ExtensionCommand } from "@bitwarden/common/autofill/constants";
@@ -17,6 +17,7 @@ import { MessagingService } from "@bitwarden/common/platform/abstractions/messag
import { ThemeTypes } from "@bitwarden/common/platform/enums"; import { ThemeTypes } from "@bitwarden/common/platform/enums";
import { SelfHostedEnvironment } from "@bitwarden/common/platform/services/default-environment.service"; import { SelfHostedEnvironment } from "@bitwarden/common/platform/services/default-environment.service";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service"; import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { CipherRepromptType } from "@bitwarden/common/vault/enums/cipher-reprompt-type"; import { CipherRepromptType } from "@bitwarden/common/vault/enums/cipher-reprompt-type";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
@@ -80,11 +81,12 @@ describe("NotificationBackground", () => {
const organizationService = mock<OrganizationService>(); const organizationService = mock<OrganizationService>();
const userId = "testId" as UserId; const userId = "testId" as UserId;
const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({ const activeAccountSubject = new BehaviorSubject({
id: userId, id: userId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
beforeEach(() => { beforeEach(() => {

View File

@@ -18,6 +18,7 @@ import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/s
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { CipherType } from "@bitwarden/common/vault/enums"; import { CipherType } from "@bitwarden/common/vault/enums";
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher"; import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
@@ -123,9 +124,10 @@ describe("context-menu", () => {
autofillSettingsService.enableContextMenu$ = of(true); autofillSettingsService.enableContextMenu$ = of(true);
accountService.activeAccount$ = of({ accountService.activeAccount$ = of({
id: "userId" as UserId, id: "userId" as UserId,
...mockAccountInfoWith({
email: "", email: "",
emailVerified: false,
name: undefined, name: undefined,
}),
}); });
}); });

View File

@@ -76,11 +76,14 @@ const decorators = (options: {
{ {
provide: AccountService, provide: AccountService,
useValue: { useValue: {
// We can't use mockAccountInfoWith() here because we can't take a dependency on @bitwarden/common/spec.
// This is because that package relies on jest dependencies that aren't available here.
activeAccount$: of({ activeAccount$: of({
id: "test-user-id" as UserId, id: "test-user-id" as UserId,
name: "Test User 1", name: "Test User 1",
email: "test@email.com", email: "test@email.com",
emailVerified: true, emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
}), }),
}, },
}, },

View File

@@ -16,6 +16,7 @@ import { EnvironmentService } from "@bitwarden/common/platform/abstractions/envi
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type"; import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
@@ -96,10 +97,11 @@ describe("SendV2Component", () => {
useValue: { useValue: {
activeAccount$: of({ activeAccount$: of({
id: "123", id: "123",
...mockAccountInfoWith({
email: "test@email.com", email: "test@email.com",
emailVerified: true,
name: "Test User", name: "Test User",
}), }),
}),
}, },
}, },
{ provide: AuthService, useValue: mock<AuthService>() }, { provide: AuthService, useValue: mock<AuthService>() },

View File

@@ -11,6 +11,7 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
import { ProductTierType } from "@bitwarden/common/billing/enums"; import { ProductTierType } from "@bitwarden/common/billing/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { CipherId, OrganizationId, UserId } from "@bitwarden/common/types/guid"; import { CipherId, OrganizationId, UserId } from "@bitwarden/common/types/guid";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { PremiumUpgradePromptService } from "@bitwarden/common/vault/abstractions/premium-upgrade-prompt.service"; import { PremiumUpgradePromptService } from "@bitwarden/common/vault/abstractions/premium-upgrade-prompt.service";
@@ -60,10 +61,11 @@ describe("OpenAttachmentsComponent", () => {
const accountService = { const accountService = {
activeAccount$: of({ activeAccount$: of({
id: mockUserId, id: mockUserId,
...mockAccountInfoWith({
email: "test@email.com", email: "test@email.com",
emailVerified: true,
name: "Test User", name: "Test User",
}), }),
}),
}; };
const formStatusChange$ = new BehaviorSubject<"enabled" | "disabled">("enabled"); const formStatusChange$ = new BehaviorSubject<"enabled" | "disabled">("enabled");

View File

@@ -15,6 +15,7 @@ import { ConfigService } from "@bitwarden/common/platform/abstractions/config/co
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { CsprngArray } from "@bitwarden/common/types/csprng"; import { CsprngArray } from "@bitwarden/common/types/csprng";
import { MasterKey, UserKey } from "@bitwarden/common/types/key"; import { MasterKey, UserKey } from "@bitwarden/common/types/key";
import { KeyService } from "@bitwarden/key-management"; import { KeyService } from "@bitwarden/key-management";
@@ -48,9 +49,10 @@ describe("UnlockCommand", () => {
const mockMasterPassword = "testExample"; const mockMasterPassword = "testExample";
const activeAccount: Account = { const activeAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "user@example.com", email: "user@example.com",
emailVerified: true,
name: "User", name: "User",
}),
}; };
const mockUserKey = new SymmetricCryptoKey(new Uint8Array(64)) as UserKey; const mockUserKey = new SymmetricCryptoKey(new Uint8Array(64)) as UserKey;
const mockSessionKey = new Uint8Array(64) as CsprngArray; const mockSessionKey = new Uint8Array(64) as CsprngArray;

View File

@@ -7,6 +7,7 @@ import { AccountService, Account } from "@bitwarden/common/auth/abstractions/acc
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { CipherRepromptType, CipherType } from "@bitwarden/common/vault/enums"; import { CipherRepromptType, CipherType } from "@bitwarden/common/vault/enums";
@@ -40,9 +41,10 @@ describe("Fido2CreateComponent", () => {
const activeAccountSubject = new BehaviorSubject<Account | null>({ const activeAccountSubject = new BehaviorSubject<Account | null>({
id: "test-user-id" as UserId, id: "test-user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
beforeEach(async () => { beforeEach(async () => {

View File

@@ -10,6 +10,7 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { Account, UserId } from "@bitwarden/common/platform/models/domain/account"; import { Account, UserId } from "@bitwarden/common/platform/models/domain/account";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { DesktopAutotypeDefaultSettingPolicy } from "./desktop-autotype-policy.service"; import { DesktopAutotypeDefaultSettingPolicy } from "./desktop-autotype-policy.service";
@@ -30,9 +31,10 @@ describe("DesktopAutotypeDefaultSettingPolicy", () => {
beforeEach(() => { beforeEach(() => {
mockAccountSubject = new BehaviorSubject<Account | null>({ mockAccountSubject = new BehaviorSubject<Account | null>({
id: mockUserId, id: mockUserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
mockFeatureFlagSubject = new BehaviorSubject<boolean>(true); mockFeatureFlagSubject = new BehaviorSubject<boolean>(true);
mockAuthStatusSubject = new BehaviorSubject<AuthenticationStatus>( mockAuthStatusSubject = new BehaviorSubject<AuthenticationStatus>(

View File

@@ -2,7 +2,7 @@ import { NgZone } from "@angular/core";
import { mock, MockProxy } from "jest-mock-extended"; import { mock, MockProxy } from "jest-mock-extended";
import { BehaviorSubject, filter, firstValueFrom, of, take, timeout, timer } from "rxjs"; import { BehaviorSubject, filter, firstValueFrom, of, take, timeout, timer } from "rxjs";
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { CryptoFunctionService } from "@bitwarden/common/key-management/crypto/abstractions/crypto-function.service"; import { CryptoFunctionService } from "@bitwarden/common/key-management/crypto/abstractions/crypto-function.service";
@@ -10,7 +10,7 @@ import { EncryptService } from "@bitwarden/common/key-management/crypto/abstract
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { FakeAccountService } from "@bitwarden/common/spec"; import { mockAccountInfoWith, FakeAccountService } from "@bitwarden/common/spec";
import { CsprngArray } from "@bitwarden/common/types/csprng"; import { CsprngArray } from "@bitwarden/common/types/csprng";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { DialogService } from "@bitwarden/components"; import { DialogService } from "@bitwarden/components";
@@ -23,17 +23,15 @@ import { BiometricMessageHandlerService } from "./biometric-message-handler.serv
const SomeUser = "SomeUser" as UserId; const SomeUser = "SomeUser" as UserId;
const AnotherUser = "SomeOtherUser" as UserId; const AnotherUser = "SomeOtherUser" as UserId;
const accounts: Record<UserId, AccountInfo> = { const accounts = {
[SomeUser]: { [SomeUser]: mockAccountInfoWith({
name: "some user", name: "some user",
email: "some.user@example.com", email: "some.user@example.com",
emailVerified: true, }),
}, [AnotherUser]: mockAccountInfoWith({
[AnotherUser]: {
name: "some other user", name: "some other user",
email: "some.other.user@example.com", email: "some.other.user@example.com",
emailVerified: true, }),
},
}; };
describe("BiometricMessageHandlerService", () => { describe("BiometricMessageHandlerService", () => {

View File

@@ -10,6 +10,7 @@ import {
PersonalSubscriptionPricingTierId, PersonalSubscriptionPricingTierId,
PersonalSubscriptionPricingTierIds, PersonalSubscriptionPricingTierIds,
} from "@bitwarden/common/billing/types/subscription-pricing-tier"; } from "@bitwarden/common/billing/types/subscription-pricing-tier";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { DIALOG_DATA, DialogRef } from "@bitwarden/components"; import { DIALOG_DATA, DialogRef } from "@bitwarden/components";
@@ -63,9 +64,10 @@ describe("UnifiedUpgradeDialogComponent", () => {
const mockAccount: Account = { const mockAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}; };
const defaultDialogData: UnifiedUpgradeDialogParams = { const defaultDialogData: UnifiedUpgradeDialogParams = {

View File

@@ -7,6 +7,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { DialogRef, DialogService } from "@bitwarden/components"; import { DialogRef, DialogService } from "@bitwarden/components";
@@ -32,9 +33,10 @@ describe("UpgradeNavButtonComponent", () => {
const mockAccount: Account = { const mockAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}; };
beforeEach(async () => { beforeEach(async () => {

View File

@@ -13,6 +13,7 @@ import { PaymentMethodType, PlanType } from "@bitwarden/common/billing/enums";
import { PersonalSubscriptionPricingTierIds } from "@bitwarden/common/billing/types/subscription-pricing-tier"; import { PersonalSubscriptionPricingTierIds } from "@bitwarden/common/billing/types/subscription-pricing-tier";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { SyncService } from "@bitwarden/common/platform/sync"; import { SyncService } from "@bitwarden/common/platform/sync";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { LogService } from "@bitwarden/logging"; import { LogService } from "@bitwarden/logging";
@@ -46,11 +47,12 @@ describe("UpgradePaymentService", () => {
let sut: UpgradePaymentService; let sut: UpgradePaymentService;
const mockAccount = { const mockAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}; };
const mockTokenizedPaymentMethod: TokenizedPaymentMethod = { const mockTokenizedPaymentMethod: TokenizedPaymentMethod = {
@@ -151,9 +153,10 @@ describe("UpgradePaymentService", () => {
const mockAccount: Account = { const mockAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
name: "Test User", name: "Test User",
emailVerified: true, }),
}; };
const paidOrgData = { const paidOrgData = {
@@ -203,9 +206,10 @@ describe("UpgradePaymentService", () => {
const mockAccount: Account = { const mockAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
name: "Test User", name: "Test User",
emailVerified: true, }),
}; };
const paidOrgData = { const paidOrgData = {
@@ -255,9 +259,10 @@ describe("UpgradePaymentService", () => {
const mockAccount: Account = { const mockAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
name: "Test User", name: "Test User",
emailVerified: true, }),
}; };
mockAccountService.activeAccount$ = of(mockAccount); mockAccountService.activeAccount$ = of(mockAccount);
@@ -289,9 +294,10 @@ describe("UpgradePaymentService", () => {
const mockAccount: Account = { const mockAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
name: "Test User", name: "Test User",
emailVerified: true, }),
}; };
const expectedCredit = 25.5; const expectedCredit = 25.5;
@@ -353,9 +359,10 @@ describe("UpgradePaymentService", () => {
const mockAccount: Account = { const mockAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
name: "Test User", name: "Test User",
emailVerified: true, }),
}; };
const paidOrgData = { const paidOrgData = {

View File

@@ -10,6 +10,7 @@ import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { BreachAccountResponse } from "@bitwarden/common/dirt/models/response/breach-account.response"; import { BreachAccountResponse } from "@bitwarden/common/dirt/models/response/breach-account.response";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { BreachReportComponent } from "./breach-report.component"; import { BreachReportComponent } from "./breach-report.component";
@@ -38,9 +39,10 @@ describe("BreachReportComponent", () => {
let accountService: MockProxy<AccountService>; let accountService: MockProxy<AccountService>;
const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({ const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({
id: "testId" as UserId, id: "testId" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
beforeEach(async () => { beforeEach(async () => {

View File

@@ -30,6 +30,7 @@ import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-
import { HashPurpose } from "@bitwarden/common/platform/enums"; import { HashPurpose } from "@bitwarden/common/platform/enums";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { SendWithIdRequest } from "@bitwarden/common/tools/send/models/request/send-with-id.request"; import { SendWithIdRequest } from "@bitwarden/common/tools/send/models/request/send-with-id.request";
import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
@@ -286,9 +287,10 @@ describe("KeyRotationService", () => {
const mockUser = { const mockUser = {
id: "mockUserId" as UserId, id: "mockUserId" as UserId,
...mockAccountInfoWith({
email: "mockEmail", email: "mockEmail",
emailVerified: true,
name: "mockName", name: "mockName",
}),
}; };
const mockTrustedPublicKeys = [Utils.fromUtf8ToArray("test-public-key")]; const mockTrustedPublicKeys = [Utils.fromUtf8ToArray("test-public-key")];

View File

@@ -75,11 +75,14 @@ class MockSyncService implements Partial<SyncService> {
} }
class MockAccountService implements Partial<AccountService> { class MockAccountService implements Partial<AccountService> {
// We can't use mockAccountInfoWith() here because we can't take a dependency on @bitwarden/common/spec.
// This is because that package relies on jest dependencies that aren't available here.
activeAccount$?: Observable<Account> = of({ activeAccount$?: Observable<Account> = of({
id: "test-user-id" as UserId, id: "test-user-id" as UserId,
name: "Test User 1", name: "Test User 1",
email: "test@email.com", email: "test@email.com",
emailVerified: true, emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
}); });
} }

View File

@@ -75,11 +75,14 @@ class MockSyncService implements Partial<SyncService> {
} }
class MockAccountService implements Partial<AccountService> { class MockAccountService implements Partial<AccountService> {
// We can't use mockAccountInfoWith() here because we can't take a dependency on @bitwarden/common/spec.
// This is because that package relies on jest dependencies that aren't available here.
activeAccount$?: Observable<Account> = of({ activeAccount$?: Observable<Account> = of({
id: "test-user-id" as UserId, id: "test-user-id" as UserId,
name: "Test User 1", name: "Test User 1",
email: "test@email.com", email: "test@email.com",
emailVerified: true, emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
}); });
} }

View File

@@ -2,14 +2,18 @@ import { TestBed } from "@angular/core/testing";
import { BehaviorSubject, firstValueFrom, take, timeout } from "rxjs"; import { BehaviorSubject, firstValueFrom, take, timeout } from "rxjs";
import { AuthRequestServiceAbstraction } from "@bitwarden/auth/common"; import { AuthRequestServiceAbstraction } from "@bitwarden/auth/common";
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthRequestResponse } from "@bitwarden/common/auth/models/response/auth-request.response"; import { AuthRequestResponse } from "@bitwarden/common/auth/models/response/auth-request.response";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { DeviceType } from "@bitwarden/common/enums"; import { DeviceType } from "@bitwarden/common/enums";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { StateProvider } from "@bitwarden/common/platform/state"; import { StateProvider } from "@bitwarden/common/platform/state";
import { FakeStateProvider, mockAccountServiceWith } from "@bitwarden/common/spec"; import {
FakeStateProvider,
mockAccountServiceWith,
mockAccountInfoWith,
} from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
@@ -27,8 +31,11 @@ describe("VaultBannersService", () => {
const fakeStateProvider = new FakeStateProvider(mockAccountServiceWith(userId)); const fakeStateProvider = new FakeStateProvider(mockAccountServiceWith(userId));
const getEmailVerified = jest.fn().mockResolvedValue(true); const getEmailVerified = jest.fn().mockResolvedValue(true);
const lastSync$ = new BehaviorSubject<Date | null>(null); const lastSync$ = new BehaviorSubject<Date | null>(null);
const accounts$ = new BehaviorSubject<Record<UserId, AccountInfo>>({ const accounts$ = new BehaviorSubject({
[userId]: { email: "test@bitwarden.com", emailVerified: true, name: "name" } as AccountInfo, [userId]: mockAccountInfoWith({
email: "test@bitwarden.com",
name: "name",
}),
}); });
const pendingAuthRequests$ = new BehaviorSubject<Array<AuthRequestResponse>>([]); const pendingAuthRequests$ = new BehaviorSubject<Array<AuthRequestResponse>>([]);

View File

@@ -10,6 +10,7 @@ import { ProviderUserType } from "@bitwarden/common/admin-console/enums";
import { Provider } from "@bitwarden/common/admin-console/models/domain/provider"; import { Provider } from "@bitwarden/common/admin-console/models/domain/provider";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { ToastService } from "@bitwarden/components"; import { ToastService } from "@bitwarden/components";
import { newGuid } from "@bitwarden/guid"; import { newGuid } from "@bitwarden/guid";
@@ -41,9 +42,10 @@ describe("Provider Permissions Guard", () => {
accountService.activeAccount$ = of({ accountService.activeAccount$ = of({
id: mockUserId, id: mockUserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
route = mock<ActivatedRouteSnapshot>({ route = mock<ActivatedRouteSnapshot>({

View File

@@ -6,6 +6,7 @@ import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.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 { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { CsprngArray } from "@bitwarden/common/types/csprng"; import { CsprngArray } from "@bitwarden/common/types/csprng";
import { OrganizationId, UserId } from "@bitwarden/common/types/guid"; import { OrganizationId, UserId } from "@bitwarden/common/types/guid";
import { OrgKey } from "@bitwarden/common/types/key"; import { OrgKey } from "@bitwarden/common/types/key";
@@ -37,9 +38,11 @@ describe("SecretService", () => {
let accountService: MockProxy<AccountService> = mock<AccountService>(); let accountService: MockProxy<AccountService> = mock<AccountService>();
const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({ const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({
id: "testId" as UserId, id: "testId" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
emailVerified: true,
}),
}); });
beforeEach(() => { beforeEach(() => {

View File

@@ -7,6 +7,7 @@ import { EncryptService } from "@bitwarden/common/key-management/crypto/abstract
import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string"; import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { CsprngArray } from "@bitwarden/common/types/csprng"; import { CsprngArray } from "@bitwarden/common/types/csprng";
import { OrganizationId, UserId } from "@bitwarden/common/types/guid"; import { OrganizationId, UserId } from "@bitwarden/common/types/guid";
import { OrgKey } from "@bitwarden/common/types/key"; import { OrgKey } from "@bitwarden/common/types/key";
@@ -38,9 +39,11 @@ describe("SecretsManagerPortingApiService", () => {
let accountService: MockProxy<AccountService>; let accountService: MockProxy<AccountService>;
const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({ const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({
id: "testId" as UserId, id: "testId" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
emailVerified: true,
}),
}); });
beforeEach(() => { beforeEach(() => {

View File

@@ -31,7 +31,7 @@ import { PeopleAccessPoliciesRequest } from "./models/requests/people-access-pol
import { ProjectServiceAccountsAccessPoliciesRequest } from "./models/requests/project-service-accounts-access-policies.request"; import { ProjectServiceAccountsAccessPoliciesRequest } from "./models/requests/project-service-accounts-access-policies.request";
import { ServiceAccountGrantedPoliciesRequest } from "./models/requests/service-account-granted-policies.request"; import { ServiceAccountGrantedPoliciesRequest } from "./models/requests/service-account-granted-policies.request";
import { trackEmissions } from "@bitwarden/common/../spec"; import { trackEmissions, mockAccountInfoWith } from "@bitwarden/common/../spec";
const SomeCsprngArray = new Uint8Array(64) as CsprngArray; const SomeCsprngArray = new Uint8Array(64) as CsprngArray;
const SomeOrganization = "some organization" as OrganizationId; const SomeOrganization = "some organization" as OrganizationId;
@@ -52,9 +52,10 @@ describe("AccessPolicyService", () => {
let accountService: MockProxy<AccountService>; let accountService: MockProxy<AccountService>;
const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({ const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>({
id: "testId" as UserId, id: "testId" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
beforeEach(() => { beforeEach(() => {

View File

@@ -5,11 +5,7 @@ import { MockProxy, mock } from "jest-mock-extended";
import { BehaviorSubject, of } from "rxjs"; import { BehaviorSubject, of } from "rxjs";
import { EmptyComponent } from "@bitwarden/angular/platform/guard/feature-flag.guard.spec"; import { EmptyComponent } from "@bitwarden/angular/platform/guard/feature-flag.guard.spec";
import { import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
Account,
AccountInfo,
AccountService,
} from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason"; import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason";
@@ -18,6 +14,7 @@ import { KeyConnectorService } from "@bitwarden/common/key-management/key-connec
import { MasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction"; import { MasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { authGuard } from "./auth.guard"; import { authGuard } from "./auth.guard";
@@ -38,16 +35,13 @@ describe("AuthGuard", () => {
const accountService: MockProxy<AccountService> = mock<AccountService>(); const accountService: MockProxy<AccountService> = mock<AccountService>();
const activeAccountSubject = new BehaviorSubject<Account | null>(null); const activeAccountSubject = new BehaviorSubject<Account | null>(null);
accountService.activeAccount$ = activeAccountSubject; accountService.activeAccount$ = activeAccountSubject;
activeAccountSubject.next( activeAccountSubject.next({
Object.assign( id: "test-id" as UserId,
{ ...mockAccountInfoWith({
name: "Test User 1", name: "Test User 1",
email: "test@email.com", email: "test@email.com",
emailVerified: true, }),
} as AccountInfo, });
{ id: "test-id" as UserId },
),
);
if (featureFlag) { if (featureFlag) {
configService.getFeatureFlag.mockResolvedValue(true); configService.getFeatureFlag.mockResolvedValue(true);

View File

@@ -5,11 +5,7 @@ import { MockProxy, mock } from "jest-mock-extended";
import { BehaviorSubject, of } from "rxjs"; import { BehaviorSubject, of } from "rxjs";
import { EmptyComponent } from "@bitwarden/angular/platform/guard/feature-flag.guard.spec"; import { EmptyComponent } from "@bitwarden/angular/platform/guard/feature-flag.guard.spec";
import { import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
Account,
AccountInfo,
AccountService,
} from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction"; import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
@@ -20,6 +16,7 @@ import { KeyConnectorDomainConfirmation } from "@bitwarden/common/key-management
import { VaultTimeoutSettingsService } from "@bitwarden/common/key-management/vault-timeout"; import { VaultTimeoutSettingsService } from "@bitwarden/common/key-management/vault-timeout";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { KeyService } from "@bitwarden/key-management"; import { KeyService } from "@bitwarden/key-management";
@@ -68,16 +65,13 @@ describe("lockGuard", () => {
const accountService: MockProxy<AccountService> = mock<AccountService>(); const accountService: MockProxy<AccountService> = mock<AccountService>();
const activeAccountSubject = new BehaviorSubject<Account | null>(null); const activeAccountSubject = new BehaviorSubject<Account | null>(null);
accountService.activeAccount$ = activeAccountSubject; accountService.activeAccount$ = activeAccountSubject;
activeAccountSubject.next( activeAccountSubject.next({
Object.assign( id: "test-id" as UserId,
{ ...mockAccountInfoWith({
name: "Test User 1", name: "Test User 1",
email: "test@email.com", email: "test@email.com",
emailVerified: true, }),
} as AccountInfo, });
{ id: "test-id" as UserId },
),
);
const testBed = TestBed.configureTestingModule({ const testBed = TestBed.configureTestingModule({
imports: [ imports: [

View File

@@ -7,6 +7,7 @@ import { EmptyComponent } from "@bitwarden/angular/platform/guard/feature-flag.g
import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { redirectToVaultIfUnlockedGuard } from "./redirect-to-vault-if-unlocked.guard"; import { redirectToVaultIfUnlockedGuard } from "./redirect-to-vault-if-unlocked.guard";
@@ -14,9 +15,10 @@ import { redirectToVaultIfUnlockedGuard } from "./redirect-to-vault-if-unlocked.
describe("redirectToVaultIfUnlockedGuard", () => { describe("redirectToVaultIfUnlockedGuard", () => {
const activeUser: Account = { const activeUser: Account = {
id: "userId" as UserId, id: "userId" as UserId,
...mockAccountInfoWith({
email: "test@email.com", email: "test@email.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}; };
const setup = (activeUser: Account | null, authStatus: AuthenticationStatus | null) => { const setup = (activeUser: Account | null, authStatus: AuthenticationStatus | null) => {

View File

@@ -9,6 +9,7 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/key-management/device-trust/abstractions/device-trust.service.abstraction"; import { DeviceTrustServiceAbstraction } from "@bitwarden/common/key-management/device-trust/abstractions/device-trust.service.abstraction";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { KeyService } from "@bitwarden/key-management"; import { KeyService } from "@bitwarden/key-management";
@@ -17,9 +18,10 @@ import { tdeDecryptionRequiredGuard } from "./tde-decryption-required.guard";
describe("tdeDecryptionRequiredGuard", () => { describe("tdeDecryptionRequiredGuard", () => {
const activeUser: Account = { const activeUser: Account = {
id: "fake_user_id" as UserId, id: "fake_user_id" as UserId,
...mockAccountInfoWith({
email: "test@email.com", email: "test@email.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}; };
const setup = ( const setup = (

View File

@@ -10,6 +10,7 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/key-management/device-trust/abstractions/device-trust.service.abstraction"; import { DeviceTrustServiceAbstraction } from "@bitwarden/common/key-management/device-trust/abstractions/device-trust.service.abstraction";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { KeyService } from "@bitwarden/key-management"; import { KeyService } from "@bitwarden/key-management";
@@ -18,9 +19,10 @@ import { unauthGuardFn } from "./unauth.guard";
describe("UnauthGuard", () => { describe("UnauthGuard", () => {
const activeUser: Account = { const activeUser: Account = {
id: "fake_user_id" as UserId, id: "fake_user_id" as UserId,
...mockAccountInfoWith({
email: "test@email.com", email: "test@email.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}; };
const setup = ( const setup = (

View File

@@ -11,6 +11,7 @@ import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/d
import { AuthRequestResponse } from "@bitwarden/common/auth/models/response/auth-request.response"; import { AuthRequestResponse } from "@bitwarden/common/auth/models/response/auth-request.response";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { DialogRef, DIALOG_DATA, ToastService } from "@bitwarden/components"; import { DialogRef, DIALOG_DATA, ToastService } from "@bitwarden/components";
import { LogService } from "@bitwarden/logging"; import { LogService } from "@bitwarden/logging";
@@ -48,10 +49,11 @@ describe("LoginApprovalDialogComponent", () => {
validationService = mock<ValidationService>(); validationService = mock<ValidationService>();
accountService.activeAccount$ = of({ accountService.activeAccount$ = of({
email: testEmail,
id: "test-user-id" as UserId, id: "test-user-id" as UserId,
emailVerified: true, ...mockAccountInfoWith({
email: testEmail,
name: null, name: null,
}),
}); });
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({

View File

@@ -8,6 +8,7 @@ import { MasterPasswordApiService } from "@bitwarden/common/auth/abstractions/ma
import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string"; import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string";
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction"; import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { MasterKey, UserKey } from "@bitwarden/common/types/key"; import { MasterKey, UserKey } from "@bitwarden/common/types/key";
import { KeyService, PBKDF2KdfConfig } from "@bitwarden/key-management"; import { KeyService, PBKDF2KdfConfig } from "@bitwarden/key-management";
@@ -26,9 +27,11 @@ describe("DefaultChangePasswordService", () => {
const user: Account = { const user: Account = {
id: userId, id: userId,
...mockAccountInfoWith({
email: "email", email: "email",
emailVerified: false,
name: "name", name: "name",
emailVerified: false,
}),
}; };
const passwordInputResult: PasswordInputResult = { const passwordInputResult: PasswordInputResult = {

View File

@@ -2,14 +2,13 @@ import { Router } from "@angular/router";
import { mock } from "jest-mock-extended"; import { mock } from "jest-mock-extended";
import { of } from "rxjs"; import { of } from "rxjs";
import { AccountInfo } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { EncryptedMigrator } from "@bitwarden/common/key-management/encrypted-migrator/encrypted-migrator.abstraction"; import { EncryptedMigrator } from "@bitwarden/common/key-management/encrypted-migrator/encrypted-migrator.abstraction";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SingleUserState, StateProvider } from "@bitwarden/common/platform/state"; import { SingleUserState, StateProvider } from "@bitwarden/common/platform/state";
import { SyncService } from "@bitwarden/common/platform/sync"; import { SyncService } from "@bitwarden/common/platform/sync";
import { FakeAccountService } from "@bitwarden/common/spec"; import { mockAccountInfoWith, FakeAccountService } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { DialogService, ToastService } from "@bitwarden/components"; import { DialogService, ToastService } from "@bitwarden/components";
import { LogService } from "@bitwarden/logging"; import { LogService } from "@bitwarden/logging";
@@ -22,17 +21,15 @@ import { PromptMigrationPasswordComponent } from "./prompt-migration-password.co
const SomeUser = "SomeUser" as UserId; const SomeUser = "SomeUser" as UserId;
const AnotherUser = "SomeOtherUser" as UserId; const AnotherUser = "SomeOtherUser" as UserId;
const accounts: Record<UserId, AccountInfo> = { const accounts = {
[SomeUser]: { [SomeUser]: mockAccountInfoWith({
name: "some user", name: "some user",
email: "some.user@example.com", email: "some.user@example.com",
emailVerified: true, }),
}, [AnotherUser]: mockAccountInfoWith({
[AnotherUser]: {
name: "some other user", name: "some other user",
email: "some.other.user@example.com", email: "some.other.user@example.com",
emailVerified: true, }),
},
}; };
describe("DefaultEncryptedMigrationsSchedulerService", () => { describe("DefaultEncryptedMigrationsSchedulerService", () => {

View File

@@ -189,6 +189,7 @@ export abstract class LoginStrategy {
name: accountInformation.name, name: accountInformation.name,
email: accountInformation.email ?? "", email: accountInformation.email ?? "",
emailVerified: accountInformation.email_verified ?? false, emailVerified: accountInformation.email_verified ?? false,
creationDate: undefined, // We don't get a creation date in the token. See https://bitwarden.atlassian.net/browse/PM-29551 for consolidation plans.
}); });
// User env must be seeded from currently set env before switching to the account // User env must be seeded from currently set env before switching to the account

View File

@@ -8,7 +8,7 @@ import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key-
import { VaultTimeoutSettingsService } from "@bitwarden/common/key-management/vault-timeout"; import { VaultTimeoutSettingsService } from "@bitwarden/common/key-management/vault-timeout";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { SystemService } from "@bitwarden/common/platform/abstractions/system.service"; import { SystemService } from "@bitwarden/common/platform/abstractions/system.service";
import { mockAccountServiceWith } from "@bitwarden/common/spec"; import { mockAccountServiceWith, mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction"; import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
@@ -79,17 +79,21 @@ describe("DefaultLockService", () => {
); );
it("locks the active account last", async () => { it("locks the active account last", async () => {
await accountService.addAccount(mockUser2, { await accountService.addAccount(
mockUser2,
mockAccountInfoWith({
name: "name2", name: "name2",
email: "email2@example.com", email: "email2@example.com",
emailVerified: false, }),
}); );
await accountService.addAccount(mockUser3, { await accountService.addAccount(
mockUser3,
mockAccountInfoWith({
name: "name3", name: "name3",
email: "name3@example.com", email: "name3@example.com",
emailVerified: false, }),
}); );
const lockSpy = jest.spyOn(sut, "lock").mockResolvedValue(undefined); const lockSpy = jest.spyOn(sut, "lock").mockResolvedValue(undefined);

View File

@@ -6,19 +6,26 @@ import { ReplaySubject, combineLatest, map, Observable } from "rxjs";
import { Account, AccountInfo, AccountService } from "../src/auth/abstractions/account.service"; import { Account, AccountInfo, AccountService } from "../src/auth/abstractions/account.service";
import { UserId } from "../src/types/guid"; import { UserId } from "../src/types/guid";
/**
* Creates a mock AccountInfo object with sensible defaults that can be overridden.
* Use this when you need just an AccountInfo object in tests.
*/
export function mockAccountInfoWith(info: Partial<AccountInfo> = {}): AccountInfo {
return {
name: "name",
email: "email",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
...info,
};
}
export function mockAccountServiceWith( export function mockAccountServiceWith(
userId: UserId, userId: UserId,
info: Partial<AccountInfo> = {}, info: Partial<AccountInfo> = {},
activity: Record<UserId, Date> = {}, activity: Record<UserId, Date> = {},
): FakeAccountService { ): FakeAccountService {
const fullInfo: AccountInfo = { const fullInfo = mockAccountInfoWith(info);
...info,
...{
name: "name",
email: "email",
emailVerified: true,
},
};
const fullActivity = { [userId]: new Date(), ...activity }; const fullActivity = { [userId]: new Date(), ...activity };
@@ -104,6 +111,10 @@ export class FakeAccountService implements AccountService {
await this.mock.setAccountEmailVerified(userId, emailVerified); await this.mock.setAccountEmailVerified(userId, emailVerified);
} }
async setAccountCreationDate(userId: UserId, creationDate: string): Promise<void> {
await this.mock.setAccountCreationDate(userId, creationDate);
}
async switchAccount(userId: UserId): Promise<void> { async switchAccount(userId: UserId): Promise<void> {
const next = const next =
userId == null ? null : { id: userId, ...this.accountsSubject["_buffer"]?.[0]?.[userId] }; userId == null ? null : { id: userId, ...this.accountsSubject["_buffer"]?.[0]?.[userId] };
@@ -127,4 +138,5 @@ const loggedOutInfo: AccountInfo = {
name: undefined, name: undefined,
email: "", email: "",
emailVerified: false, emailVerified: false,
creationDate: undefined,
}; };

View File

@@ -2,14 +2,11 @@ import { Observable } from "rxjs";
import { UserId } from "../../types/guid"; import { UserId } from "../../types/guid";
/**
* Holds information about an account for use in the AccountService
* if more information is added, be sure to update the equality method.
*/
export type AccountInfo = { export type AccountInfo = {
email: string; email: string;
emailVerified: boolean; emailVerified: boolean;
name: string | undefined; name: string | undefined;
creationDate: string | undefined;
}; };
export type Account = { id: UserId } & AccountInfo; export type Account = { id: UserId } & AccountInfo;
@@ -75,6 +72,12 @@ export abstract class AccountService {
* @param emailVerified * @param emailVerified
*/ */
abstract setAccountEmailVerified(userId: UserId, emailVerified: boolean): Promise<void>; abstract setAccountEmailVerified(userId: UserId, emailVerified: boolean): Promise<void>;
/**
* updates the `accounts$` observable with the creation date for the account.
* @param userId
* @param creationDate
*/
abstract setAccountCreationDate(userId: UserId, creationDate: string): Promise<void>;
/** /**
* updates the `accounts$` observable with the new VerifyNewDeviceLogin property for the account. * updates the `accounts$` observable with the new VerifyNewDeviceLogin property for the account.
* @param userId * @param userId

View File

@@ -6,6 +6,7 @@
import { MockProxy, mock } from "jest-mock-extended"; import { MockProxy, mock } from "jest-mock-extended";
import { firstValueFrom } from "rxjs"; import { firstValueFrom } from "rxjs";
import { mockAccountInfoWith } from "../../../spec/fake-account-service";
import { FakeGlobalState } from "../../../spec/fake-state"; import { FakeGlobalState } from "../../../spec/fake-state";
import { import {
FakeGlobalStateProvider, FakeGlobalStateProvider,
@@ -27,7 +28,7 @@ import {
} from "./account.service"; } from "./account.service";
describe("accountInfoEqual", () => { describe("accountInfoEqual", () => {
const accountInfo: AccountInfo = { name: "name", email: "email", emailVerified: true }; const accountInfo = mockAccountInfoWith();
it("compares nulls", () => { it("compares nulls", () => {
expect(accountInfoEqual(null, null)).toBe(true); expect(accountInfoEqual(null, null)).toBe(true);
@@ -64,6 +65,23 @@ describe("accountInfoEqual", () => {
expect(accountInfoEqual(accountInfo, same)).toBe(true); expect(accountInfoEqual(accountInfo, same)).toBe(true);
expect(accountInfoEqual(accountInfo, different)).toBe(false); expect(accountInfoEqual(accountInfo, different)).toBe(false);
}); });
it("compares creationDate", () => {
const same = { ...accountInfo };
const different = { ...accountInfo, creationDate: "2024-12-31T00:00:00.000Z" };
expect(accountInfoEqual(accountInfo, same)).toBe(true);
expect(accountInfoEqual(accountInfo, different)).toBe(false);
});
it("compares undefined creationDate", () => {
const accountWithoutCreationDate = mockAccountInfoWith({ creationDate: undefined });
const same = { ...accountWithoutCreationDate };
const different = { ...accountWithoutCreationDate, creationDate: "2024-01-01T00:00:00.000Z" };
expect(accountInfoEqual(accountWithoutCreationDate, same)).toBe(true);
expect(accountInfoEqual(accountWithoutCreationDate, different)).toBe(false);
});
}); });
describe("accountService", () => { describe("accountService", () => {
@@ -76,7 +94,10 @@ describe("accountService", () => {
let activeAccountIdState: FakeGlobalState<UserId>; let activeAccountIdState: FakeGlobalState<UserId>;
let accountActivityState: FakeGlobalState<Record<UserId, Date>>; let accountActivityState: FakeGlobalState<Record<UserId, Date>>;
const userId = Utils.newGuid() as UserId; const userId = Utils.newGuid() as UserId;
const userInfo = { email: "email", name: "name", emailVerified: true }; const userInfo = mockAccountInfoWith({
email: "email",
name: "name",
});
beforeEach(() => { beforeEach(() => {
messagingService = mock(); messagingService = mock();
@@ -253,6 +274,56 @@ describe("accountService", () => {
}); });
}); });
describe("setCreationDate", () => {
const initialState = { [userId]: userInfo };
beforeEach(() => {
accountsState.stateSubject.next(initialState);
});
it("should update the account with a new creation date", async () => {
const newCreationDate = "2024-12-31T00:00:00.000Z";
await sut.setAccountCreationDate(userId, newCreationDate);
const currentState = await firstValueFrom(accountsState.state$);
expect(currentState).toEqual({
[userId]: { ...userInfo, creationDate: newCreationDate },
});
});
it("should not update if the creation date is the same", async () => {
await sut.setAccountCreationDate(userId, userInfo.creationDate);
const currentState = await firstValueFrom(accountsState.state$);
expect(currentState).toEqual(initialState);
});
it("should update from undefined to a defined creation date", async () => {
const accountWithoutCreationDate = mockAccountInfoWith({
...userInfo,
creationDate: undefined,
});
accountsState.stateSubject.next({ [userId]: accountWithoutCreationDate });
const newCreationDate = "2024-06-15T12:30:00.000Z";
await sut.setAccountCreationDate(userId, newCreationDate);
const currentState = await firstValueFrom(accountsState.state$);
expect(currentState).toEqual({
[userId]: { ...accountWithoutCreationDate, creationDate: newCreationDate },
});
});
it("should update to a different creation date string format", async () => {
const newCreationDate = "2023-03-15T08:45:30.123Z";
await sut.setAccountCreationDate(userId, newCreationDate);
const currentState = await firstValueFrom(accountsState.state$);
expect(currentState).toEqual({
[userId]: { ...userInfo, creationDate: newCreationDate },
});
});
});
describe("setAccountVerifyNewDeviceLogin", () => { describe("setAccountVerifyNewDeviceLogin", () => {
const initialState = true; const initialState = true;
beforeEach(() => { beforeEach(() => {
@@ -294,6 +365,7 @@ describe("accountService", () => {
email: "", email: "",
emailVerified: false, emailVerified: false,
name: undefined, name: undefined,
creationDate: undefined,
}, },
}); });
}); });

View File

@@ -62,6 +62,7 @@ const LOGGED_OUT_INFO: AccountInfo = {
email: "", email: "",
emailVerified: false, emailVerified: false,
name: undefined, name: undefined,
creationDate: undefined,
}; };
/** /**
@@ -167,6 +168,10 @@ export class AccountServiceImplementation implements InternalAccountService {
await this.setAccountInfo(userId, { emailVerified }); await this.setAccountInfo(userId, { emailVerified });
} }
async setAccountCreationDate(userId: UserId, creationDate: string): Promise<void> {
await this.setAccountInfo(userId, { creationDate });
}
async clean(userId: UserId) { async clean(userId: UserId) {
await this.setAccountInfo(userId, LOGGED_OUT_INFO); await this.setAccountInfo(userId, LOGGED_OUT_INFO);
await this.removeAccountActivity(userId); await this.removeAccountActivity(userId);

View File

@@ -15,6 +15,7 @@ import {
SystemNotificationEvent, SystemNotificationEvent,
SystemNotificationsService, SystemNotificationsService,
} from "@bitwarden/common/platform/system-notifications/system-notifications.service"; } from "@bitwarden/common/platform/system-notifications/system-notifications.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/user-core"; import { UserId } from "@bitwarden/user-core";
import { AuthRequestAnsweringService } from "./auth-request-answering.service"; import { AuthRequestAnsweringService } from "./auth-request-answering.service";
@@ -48,14 +49,16 @@ describe("AuthRequestAnsweringService", () => {
// Common defaults // Common defaults
authService.activeAccountStatus$ = of(AuthenticationStatus.Locked); authService.activeAccountStatus$ = of(AuthenticationStatus.Locked);
accountService.activeAccount$ = of({ const accountInfo = mockAccountInfoWith({
id: userId,
email: "user@example.com", email: "user@example.com",
emailVerified: true,
name: "User", name: "User",
}); });
accountService.activeAccount$ = of({
id: userId,
...accountInfo,
});
accountService.accounts$ = of({ accountService.accounts$ = of({
[userId]: { email: "user@example.com", emailVerified: true, name: "User" }, [userId]: accountInfo,
}); });
(masterPasswordService.forceSetPasswordReason$ as jest.Mock).mockReturnValue( (masterPasswordService.forceSetPasswordReason$ as jest.Mock).mockReturnValue(
of(ForceSetPasswordReason.None), of(ForceSetPasswordReason.None),

View File

@@ -10,6 +10,7 @@ import {
makeStaticByteArray, makeStaticByteArray,
mockAccountServiceWith, mockAccountServiceWith,
trackEmissions, trackEmissions,
mockAccountInfoWith,
} from "../../../spec"; } from "../../../spec";
import { ApiService } from "../../abstractions/api.service"; import { ApiService } from "../../abstractions/api.service";
import { MessagingService } from "../../platform/abstractions/messaging.service"; import { MessagingService } from "../../platform/abstractions/messaging.service";
@@ -58,9 +59,10 @@ describe("AuthService", () => {
const accountInfo = { const accountInfo = {
status: AuthenticationStatus.Unlocked, status: AuthenticationStatus.Unlocked,
id: userId, id: userId,
...mockAccountInfoWith({
email: "email", email: "email",
emailVerified: false,
name: "name", name: "name",
}),
}; };
beforeEach(() => { beforeEach(() => {
@@ -112,9 +114,10 @@ describe("AuthService", () => {
const accountInfo2 = { const accountInfo2 = {
status: AuthenticationStatus.Unlocked, status: AuthenticationStatus.Unlocked,
id: Utils.newGuid() as UserId, id: Utils.newGuid() as UserId,
...mockAccountInfoWith({
email: "email2", email: "email2",
emailVerified: false,
name: "name2", name: "name2",
}),
}; };
const emissions = trackEmissions(sut.activeAccountStatus$); const emissions = trackEmissions(sut.activeAccountStatus$);
@@ -131,11 +134,13 @@ describe("AuthService", () => {
it("requests auth status for all known users", async () => { it("requests auth status for all known users", async () => {
const userId2 = Utils.newGuid() as UserId; const userId2 = Utils.newGuid() as UserId;
await accountService.addAccount(userId2, { await accountService.addAccount(
userId2,
mockAccountInfoWith({
email: "email2", email: "email2",
emailVerified: false,
name: "name2", name: "name2",
}); }),
);
const mockFn = jest.fn().mockReturnValue(of(AuthenticationStatus.Locked)); const mockFn = jest.fn().mockReturnValue(of(AuthenticationStatus.Locked));
sut.authStatusFor$ = mockFn; sut.authStatusFor$ = mockFn;

View File

@@ -8,12 +8,13 @@ import { OrganizationUserApiService } from "@bitwarden/admin-console/common";
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import { KeyService } from "@bitwarden/key-management"; import { KeyService } from "@bitwarden/key-management";
import { mockAccountInfoWith } from "../../../spec/fake-account-service";
import { OrganizationApiServiceAbstraction } from "../../admin-console/abstractions/organization/organization-api.service.abstraction"; import { OrganizationApiServiceAbstraction } from "../../admin-console/abstractions/organization/organization-api.service.abstraction";
import { OrganizationAutoEnrollStatusResponse } from "../../admin-console/models/response/organization-auto-enroll-status.response"; import { OrganizationAutoEnrollStatusResponse } from "../../admin-console/models/response/organization-auto-enroll-status.response";
import { EncryptService } from "../../key-management/crypto/abstractions/encrypt.service"; import { EncryptService } from "../../key-management/crypto/abstractions/encrypt.service";
import { I18nService } from "../../platform/abstractions/i18n.service"; import { I18nService } from "../../platform/abstractions/i18n.service";
import { UserId } from "../../types/guid"; import { UserId } from "../../types/guid";
import { Account, AccountInfo, AccountService } from "../abstractions/account.service"; import { Account, AccountService } from "../abstractions/account.service";
import { PasswordResetEnrollmentServiceImplementation } from "./password-reset-enrollment.service.implementation"; import { PasswordResetEnrollmentServiceImplementation } from "./password-reset-enrollment.service.implementation";
@@ -96,11 +97,10 @@ describe("PasswordResetEnrollmentServiceImplementation", () => {
const encryptedKey = { encryptedString: "encryptedString" }; const encryptedKey = { encryptedString: "encryptedString" };
organizationApiService.getKeys.mockResolvedValue(orgKeyResponse as any); organizationApiService.getKeys.mockResolvedValue(orgKeyResponse as any);
const user1AccountInfo: AccountInfo = { const user1AccountInfo = mockAccountInfoWith({
name: "Test User 1", name: "Test User 1",
email: "test1@email.com", email: "test1@email.com",
emailVerified: true, });
};
activeAccountSubject.next(Object.assign(user1AccountInfo, { id: "userId" as UserId })); activeAccountSubject.next(Object.assign(user1AccountInfo, { id: "userId" as UserId }));
keyService.userKey$.mockReturnValue(of({ key: "key" } as any)); keyService.userKey$.mockReturnValue(of({ key: "key" } as any));

View File

@@ -7,7 +7,7 @@ import { BehaviorSubject, from, of } from "rxjs";
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import { LockService, LogoutService } from "@bitwarden/auth/common"; import { LockService, LogoutService } from "@bitwarden/auth/common";
import { FakeAccountService, mockAccountServiceWith } from "../../../../spec"; import { FakeAccountService, mockAccountServiceWith, mockAccountInfoWith } from "../../../../spec";
import { AccountInfo } from "../../../auth/abstractions/account.service"; import { AccountInfo } from "../../../auth/abstractions/account.service";
import { AuthService } from "../../../auth/abstractions/auth.service"; import { AuthService } from "../../../auth/abstractions/auth.service";
import { AuthenticationStatus } from "../../../auth/enums/authentication-status"; import { AuthenticationStatus } from "../../../auth/enums/authentication-status";
@@ -109,19 +109,19 @@ describe("VaultTimeoutService", () => {
if (globalSetups?.userId) { if (globalSetups?.userId) {
accountService.activeAccountSubject.next({ accountService.activeAccountSubject.next({
id: globalSetups.userId as UserId, id: globalSetups.userId as UserId,
...mockAccountInfoWith({
email: null, email: null,
emailVerified: false,
name: null, name: null,
}),
}); });
} }
accountService.accounts$ = of( accountService.accounts$ = of(
Object.entries(accounts).reduce( Object.entries(accounts).reduce(
(agg, [id]) => { (agg, [id]) => {
agg[id] = { agg[id] = mockAccountInfoWith({
email: "", email: "",
emailVerified: true,
name: "", name: "",
}; });
return agg; return agg;
}, },
{} as Record<string, AccountInfo>, {} as Record<string, AccountInfo>,

View File

@@ -7,6 +7,7 @@ import { InternalPolicyService } from "@bitwarden/common/admin-console/abstracti
import { AuthRequestAnsweringServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction"; import { AuthRequestAnsweringServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { mockAccountInfoWith } from "../../../../spec";
import { AccountService } from "../../../auth/abstractions/account.service"; import { AccountService } from "../../../auth/abstractions/account.service";
import { AuthService } from "../../../auth/abstractions/auth.service"; import { AuthService } from "../../../auth/abstractions/auth.service";
import { AuthenticationStatus } from "../../../auth/enums/authentication-status"; import { AuthenticationStatus } from "../../../auth/enums/authentication-status";
@@ -163,9 +164,10 @@ describe("DefaultServerNotificationsService (multi-user)", () => {
} else { } else {
activeUserAccount$.next({ activeUserAccount$.next({
id: userId, id: userId,
...mockAccountInfoWith({
email: "email", email: "email",
name: "Test Name", name: "Test Name",
emailVerified: true, }),
}); });
} }
} }
@@ -174,7 +176,10 @@ describe("DefaultServerNotificationsService (multi-user)", () => {
const currentAccounts = (userAccounts$.getValue() as Record<string, any>) ?? {}; const currentAccounts = (userAccounts$.getValue() as Record<string, any>) ?? {};
userAccounts$.next({ userAccounts$.next({
...currentAccounts, ...currentAccounts,
[userId]: { email: "email", name: "Test Name", emailVerified: true }, [userId]: mockAccountInfoWith({
email: "email",
name: "Test Name",
}),
} as any); } as any);
} }

View File

@@ -8,7 +8,7 @@ import { InternalPolicyService } from "@bitwarden/common/admin-console/abstracti
import { PolicyType } from "@bitwarden/common/admin-console/enums"; import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { AuthRequestAnsweringServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction"; import { AuthRequestAnsweringServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction";
import { awaitAsync } from "../../../../spec"; import { awaitAsync, mockAccountInfoWith } from "../../../../spec";
import { Matrix } from "../../../../spec/matrix"; import { Matrix } from "../../../../spec/matrix";
import { AccountService } from "../../../auth/abstractions/account.service"; import { AccountService } from "../../../auth/abstractions/account.service";
import { AuthService } from "../../../auth/abstractions/auth.service"; import { AuthService } from "../../../auth/abstractions/auth.service";
@@ -139,11 +139,18 @@ describe("NotificationsService", () => {
activeAccount.next(null); activeAccount.next(null);
accounts.next({} as any); accounts.next({} as any);
} else { } else {
activeAccount.next({ id: userId, email: "email", name: "Test Name", emailVerified: true }); const accountInfo = mockAccountInfoWith({
email: "email",
name: "Test Name",
});
activeAccount.next({
id: userId,
...accountInfo,
});
const current = (accounts.getValue() as Record<string, any>) ?? {}; const current = (accounts.getValue() as Record<string, any>) ?? {};
accounts.next({ accounts.next({
...current, ...current,
[userId]: { email: "email", name: "Test Name", emailVerified: true }, [userId]: accountInfo,
} as any); } as any);
} }
} }
@@ -349,7 +356,13 @@ describe("NotificationsService", () => {
describe("processNotification", () => { describe("processNotification", () => {
beforeEach(async () => { beforeEach(async () => {
appIdService.getAppId.mockResolvedValue("test-app-id"); appIdService.getAppId.mockResolvedValue("test-app-id");
activeAccount.next({ id: mockUser1, email: "email", name: "Test Name", emailVerified: true }); activeAccount.next({
id: mockUser1,
...mockAccountInfoWith({
email: "email",
name: "Test Name",
}),
});
}); });
describe("NotificationType.LogOut", () => { describe("NotificationType.LogOut", () => {

View File

@@ -1,6 +1,6 @@
import { firstValueFrom } from "rxjs"; import { firstValueFrom } from "rxjs";
import { FakeStateProvider, awaitAsync } from "../../../spec"; import { FakeStateProvider, awaitAsync, mockAccountInfoWith } from "../../../spec";
import { FakeAccountService } from "../../../spec/fake-account-service"; import { FakeAccountService } from "../../../spec/fake-account-service";
import { UserId } from "../../types/guid"; import { UserId } from "../../types/guid";
import { CloudRegion, Region } from "../abstractions/environment.service"; import { CloudRegion, Region } from "../abstractions/environment.service";
@@ -28,16 +28,14 @@ describe("EnvironmentService", () => {
beforeEach(async () => { beforeEach(async () => {
accountService = new FakeAccountService({ accountService = new FakeAccountService({
[testUser]: { [testUser]: mockAccountInfoWith({
name: "name", name: "name",
email: "email", email: "email",
emailVerified: false, }),
}, [alternateTestUser]: mockAccountInfoWith({
[alternateTestUser]: {
name: "name", name: "name",
email: "email", email: "email",
emailVerified: false, }),
},
}); });
stateProvider = new FakeStateProvider(accountService); stateProvider = new FakeStateProvider(accountService);
@@ -47,9 +45,10 @@ describe("EnvironmentService", () => {
const switchUser = async (userId: UserId) => { const switchUser = async (userId: UserId) => {
accountService.activeAccountSubject.next({ accountService.activeAccountSubject.next({
id: userId, id: userId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
name: `Test Name ${userId}`, name: `Test Name ${userId}`,
emailVerified: false, }),
}); });
await awaitAsync(); await awaitAsync();
}; };

View File

@@ -3,7 +3,7 @@ import { TextEncoder } from "util";
import { mock, MockProxy } from "jest-mock-extended"; import { mock, MockProxy } from "jest-mock-extended";
import { BehaviorSubject, of } from "rxjs"; import { BehaviorSubject, of } from "rxjs";
import { mockAccountServiceWith } from "../../../../spec"; import { mockAccountServiceWith, mockAccountInfoWith } from "../../../../spec";
import { Account } from "../../../auth/abstractions/account.service"; import { Account } from "../../../auth/abstractions/account.service";
import { CipherId, UserId } from "../../../types/guid"; import { CipherId, UserId } from "../../../types/guid";
import { CipherService, EncryptionContext } from "../../../vault/abstractions/cipher.service"; import { CipherService, EncryptionContext } from "../../../vault/abstractions/cipher.service";
@@ -40,9 +40,10 @@ describe("FidoAuthenticatorService", () => {
const userId = "testId" as UserId; const userId = "testId" as UserId;
const activeAccountSubject = new BehaviorSubject<Account | null>({ const activeAccountSubject = new BehaviorSubject<Account | null>({
id: userId, id: userId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
let cipherService!: MockProxy<CipherService>; let cipherService!: MockProxy<CipherService>;

View File

@@ -12,9 +12,9 @@ import {
FakeAccountService, FakeAccountService,
FakeStateProvider, FakeStateProvider,
mockAccountServiceWith, mockAccountServiceWith,
mockAccountInfoWith,
} from "../../../../spec"; } from "../../../../spec";
import { ApiService } from "../../../abstractions/api.service"; import { ApiService } from "../../../abstractions/api.service";
import { AccountInfo } from "../../../auth/abstractions/account.service";
import { EncryptedString } from "../../../key-management/crypto/models/enc-string"; import { EncryptedString } from "../../../key-management/crypto/models/enc-string";
import { UserId } from "../../../types/guid"; import { UserId } from "../../../types/guid";
import { UserKey } from "../../../types/key"; import { UserKey } from "../../../types/key";
@@ -92,7 +92,10 @@ describe("DefaultSdkService", () => {
.calledWith(userId) .calledWith(userId)
.mockReturnValue(new BehaviorSubject(mock<Environment>())); .mockReturnValue(new BehaviorSubject(mock<Environment>()));
accountService.accounts$ = of({ accountService.accounts$ = of({
[userId]: { email: "email", emailVerified: true, name: "name" } as AccountInfo, [userId]: mockAccountInfoWith({
email: "email",
name: "name",
}),
}); });
kdfConfigService.getKdfConfig$ kdfConfigService.getKdfConfig$
.calledWith(userId) .calledWith(userId)

View File

@@ -8,9 +8,9 @@ import {
FakeAccountService, FakeAccountService,
FakeStateProvider, FakeStateProvider,
mockAccountServiceWith, mockAccountServiceWith,
mockAccountInfoWith,
} from "../../../../spec"; } from "../../../../spec";
import { ApiService } from "../../../abstractions/api.service"; import { ApiService } from "../../../abstractions/api.service";
import { AccountInfo } from "../../../auth/abstractions/account.service";
import { UserId } from "../../../types/guid"; import { UserId } from "../../../types/guid";
import { ConfigService } from "../../abstractions/config/config.service"; import { ConfigService } from "../../abstractions/config/config.service";
import { Environment, EnvironmentService } from "../../abstractions/environment.service"; import { Environment, EnvironmentService } from "../../abstractions/environment.service";
@@ -76,7 +76,10 @@ describe("DefaultRegisterSdkService", () => {
.calledWith(userId) .calledWith(userId)
.mockReturnValue(new BehaviorSubject(mock<Environment>())); .mockReturnValue(new BehaviorSubject(mock<Environment>()));
accountService.accounts$ = of({ accountService.accounts$ = of({
[userId]: { email: "email", emailVerified: true, name: "name" } as AccountInfo, [userId]: mockAccountInfoWith({
email: "email",
name: "name",
}),
}); });
}); });
@@ -125,7 +128,10 @@ describe("DefaultRegisterSdkService", () => {
it("destroys the internal SDK client when the account is removed (logout)", async () => { it("destroys the internal SDK client when the account is removed (logout)", async () => {
const accounts$ = new BehaviorSubject({ const accounts$ = new BehaviorSubject({
[userId]: { email: "email", emailVerified: true, name: "name" } as AccountInfo, [userId]: mockAccountInfoWith({
email: "email",
name: "name",
}),
}); });
accountService.accounts$ = accounts$; accountService.accounts$ = accounts$;

View File

@@ -272,6 +272,7 @@ export class DefaultSyncService extends CoreSyncService {
await this.tokenService.setSecurityStamp(response.securityStamp, response.id); await this.tokenService.setSecurityStamp(response.securityStamp, response.id);
await this.accountService.setAccountEmailVerified(response.id, response.emailVerified); await this.accountService.setAccountEmailVerified(response.id, response.emailVerified);
await this.accountService.setAccountVerifyNewDeviceLogin(response.id, response.verifyDevices); await this.accountService.setAccountVerifyNewDeviceLogin(response.id, response.verifyDevices);
await this.accountService.setAccountCreationDate(response.id, response.creationDate);
await this.billingAccountProfileStateService.setHasPremium( await this.billingAccountProfileStateService.setHasPremium(
response.premiumPersonally, response.premiumPersonally,

View File

@@ -6,6 +6,7 @@ import { ObservedValueOf, of } from "rxjs";
import { LogoutReason } from "@bitwarden/auth/common"; import { LogoutReason } from "@bitwarden/auth/common";
import { UserId } from "@bitwarden/user-core"; import { UserId } from "@bitwarden/user-core";
import { mockAccountInfoWith } from "../../spec";
import { AccountService } from "../auth/abstractions/account.service"; import { AccountService } from "../auth/abstractions/account.service";
import { TokenService } from "../auth/abstractions/token.service"; import { TokenService } from "../auth/abstractions/token.service";
import { DeviceType } from "../enums"; import { DeviceType } from "../enums";
@@ -55,9 +56,10 @@ describe("ApiService", () => {
accountService.activeAccount$ = of({ accountService.activeAccount$ = of({
id: testActiveUser, id: testActiveUser,
...mockAccountInfoWith({
email: "user1@example.com", email: "user1@example.com",
emailVerified: true,
name: "Test Name", name: "Test Name",
}),
} satisfies ObservedValueOf<AccountService["activeAccount$"]>); } satisfies ObservedValueOf<AccountService["activeAccount$"]>);
httpOperations = mock(); httpOperations = mock();

View File

@@ -1,7 +1,12 @@
import { mock } from "jest-mock-extended"; import { mock } from "jest-mock-extended";
import { BehaviorSubject, firstValueFrom } from "rxjs"; import { BehaviorSubject, firstValueFrom } from "rxjs";
import { FakeAccountService, FakeStateProvider, awaitAsync } from "../../../spec"; import {
FakeAccountService,
FakeStateProvider,
awaitAsync,
mockAccountInfoWith,
} from "../../../spec";
import { Account } from "../../auth/abstractions/account.service"; import { Account } from "../../auth/abstractions/account.service";
import { EXTENSION_DISK, UserKeyDefinition } from "../../platform/state"; import { EXTENSION_DISK, UserKeyDefinition } from "../../platform/state";
import { UserId } from "../../types/guid"; import { UserId } from "../../types/guid";
@@ -21,9 +26,10 @@ import { SimpleLogin } from "./vendor/simplelogin";
const SomeUser = "some user" as UserId; const SomeUser = "some user" as UserId;
const SomeAccount = { const SomeAccount = {
id: SomeUser, id: SomeUser,
...mockAccountInfoWith({
email: "someone@example.com", email: "someone@example.com",
emailVerified: true,
name: "Someone", name: "Someone",
}),
}; };
const SomeAccount$ = new BehaviorSubject<Account>(SomeAccount); const SomeAccount$ = new BehaviorSubject<Account>(SomeAccount);

View File

@@ -11,6 +11,7 @@ import {
FakeStateProvider, FakeStateProvider,
awaitAsync, awaitAsync,
mockAccountServiceWith, mockAccountServiceWith,
mockAccountInfoWith,
} from "../../../../spec"; } from "../../../../spec";
import { KeyGenerationService } from "../../../key-management/crypto"; import { KeyGenerationService } from "../../../key-management/crypto";
import { EncryptService } from "../../../key-management/crypto/abstractions/encrypt.service"; import { EncryptService } from "../../../key-management/crypto/abstractions/encrypt.service";
@@ -71,9 +72,10 @@ describe("SendService", () => {
accountService.activeAccountSubject.next({ accountService.activeAccountSubject.next({
id: mockUserId, id: mockUserId,
...mockAccountInfoWith({
email: "email", email: "email",
emailVerified: false,
name: "name", name: "name",
}),
}); });
// Initial encrypted state // Initial encrypted state

View File

@@ -6,6 +6,7 @@ import {
awaitAsync, awaitAsync,
FakeAccountService, FakeAccountService,
FakeStateProvider, FakeStateProvider,
mockAccountInfoWith,
ObservableTracker, ObservableTracker,
} from "../../../spec"; } from "../../../spec";
import { Account } from "../../auth/abstractions/account.service"; import { Account } from "../../auth/abstractions/account.service";
@@ -23,17 +24,19 @@ import { UserStateSubject } from "./user-state-subject";
const SomeUser = "some user" as UserId; const SomeUser = "some user" as UserId;
const SomeAccount = { const SomeAccount = {
id: SomeUser, id: SomeUser,
...mockAccountInfoWith({
email: "someone@example.com", email: "someone@example.com",
emailVerified: true,
name: "Someone", name: "Someone",
}),
}; };
const SomeAccount$ = new BehaviorSubject<Account>(SomeAccount); const SomeAccount$ = new BehaviorSubject<Account>(SomeAccount);
const SomeOtherAccount = { const SomeOtherAccount = {
id: "some other user" as UserId, id: "some other user" as UserId,
...mockAccountInfoWith({
email: "someone@example.com", email: "someone@example.com",
emailVerified: true,
name: "Someone", name: "Someone",
}),
}; };
type TestType = { foo: string }; type TestType = { foo: string };

View File

@@ -6,6 +6,7 @@ import { KeyGenerationService } from "@bitwarden/common/key-management/crypto";
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service"; 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 { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { emptyGuid, OrganizationId } from "@bitwarden/common/types/guid"; import { emptyGuid, OrganizationId } from "@bitwarden/common/types/guid";
import { OrgKey, UserKey } from "@bitwarden/common/types/key"; import { OrgKey, UserKey } from "@bitwarden/common/types/key";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
@@ -41,9 +42,10 @@ describe("BitwardenPasswordProtectedImporter", () => {
accountService.activeAccount$ = of({ accountService.activeAccount$ = of({
id: emptyGuid as UserId, id: emptyGuid as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
const mockOrgId = emptyGuid as OrganizationId; const mockOrgId = emptyGuid as OrganizationId;
@@ -96,9 +98,10 @@ describe("BitwardenPasswordProtectedImporter", () => {
beforeEach(() => { beforeEach(() => {
accountService.activeAccount$ = of({ accountService.activeAccount$ = of({
id: emptyGuid as UserId, id: emptyGuid as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
}); });
importer = new BitwardenPasswordProtectedImporter( importer = new BitwardenPasswordProtectedImporter(
keyService, keyService,

View File

@@ -11,6 +11,7 @@ import { MasterPasswordUnlockService } from "@bitwarden/common/key-management/ma
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserKey } from "@bitwarden/common/types/key"; import { UserKey } from "@bitwarden/common/types/key";
import { import {
AsyncActionsModule, AsyncActionsModule,
@@ -39,9 +40,10 @@ describe("MasterPasswordLockComponent", () => {
const mockMasterPassword = "testExample"; const mockMasterPassword = "testExample";
const activeAccount: Account = { const activeAccount: Account = {
id: "user-id" as UserId, id: "user-id" as UserId,
...mockAccountInfoWith({
email: "user@example.com", email: "user@example.com",
emailVerified: true,
name: "User", name: "User",
}),
}; };
const mockUserKey = new SymmetricCryptoKey(new Uint8Array(64)) as UserKey; const mockUserKey = new SymmetricCryptoKey(new Uint8Array(64)) as UserKey;

View File

@@ -25,7 +25,11 @@ import { deepFreeze } from "@bitwarden/common/tools/util";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { BitwardenClient } from "@bitwarden/sdk-internal"; import { BitwardenClient } from "@bitwarden/sdk-internal";
import { FakeAccountService, FakeStateProvider } from "../../../../../common/spec"; import {
FakeAccountService,
FakeStateProvider,
mockAccountInfoWith,
} from "../../../../../common/spec";
import { Algorithm, AlgorithmsByType, CredentialAlgorithm, Type, Types } from "../metadata"; import { Algorithm, AlgorithmsByType, CredentialAlgorithm, Type, Types } from "../metadata";
import catchall from "../metadata/email/catchall"; import catchall from "../metadata/email/catchall";
import plusAddress from "../metadata/email/plus-address"; import plusAddress from "../metadata/email/plus-address";
@@ -40,9 +44,10 @@ import { GeneratorMetadataProvider } from "./generator-metadata-provider";
const SomeUser = "some user" as UserId; const SomeUser = "some user" as UserId;
const SomeAccount = { const SomeAccount = {
id: SomeUser, id: SomeUser,
...mockAccountInfoWith({
email: "someone@example.com", email: "someone@example.com",
emailVerified: true,
name: "Someone", name: "Someone",
}),
}; };
const SomeAccount$ = new BehaviorSubject<Account>(SomeAccount); const SomeAccount$ = new BehaviorSubject<Account>(SomeAccount);

View File

@@ -15,7 +15,12 @@ import { UserStateSubjectDependencyProvider } from "@bitwarden/common/tools/stat
import { StateConstraints } from "@bitwarden/common/tools/types"; import { StateConstraints } from "@bitwarden/common/tools/types";
import { OrganizationId, PolicyId, UserId } from "@bitwarden/common/types/guid"; import { OrganizationId, PolicyId, UserId } from "@bitwarden/common/types/guid";
import { FakeStateProvider, FakeAccountService, awaitAsync } from "../../../../../common/spec"; import {
FakeStateProvider,
FakeAccountService,
awaitAsync,
mockAccountInfoWith,
} from "../../../../../common/spec";
import { CoreProfileMetadata, ProfileContext } from "../metadata/profile-metadata"; import { CoreProfileMetadata, ProfileContext } from "../metadata/profile-metadata";
import { GeneratorConstraints } from "../types"; import { GeneratorConstraints } from "../types";
@@ -31,21 +36,25 @@ const UnverifiedEmailUser = "UnverifiedEmailUser" as UserId;
const accounts: Record<UserId, Account> = { const accounts: Record<UserId, Account> = {
[SomeUser]: { [SomeUser]: {
id: SomeUser, id: SomeUser,
...mockAccountInfoWith({
name: "some user", name: "some user",
email: "some.user@example.com", email: "some.user@example.com",
emailVerified: true, }),
}, },
[AnotherUser]: { [AnotherUser]: {
id: AnotherUser, id: AnotherUser,
...mockAccountInfoWith({
name: "some other user", name: "some other user",
email: "some.other.user@example.com", email: "some.other.user@example.com",
emailVerified: true, }),
}, },
[UnverifiedEmailUser]: { [UnverifiedEmailUser]: {
id: UnverifiedEmailUser, id: UnverifiedEmailUser,
...mockAccountInfoWith({
name: "a user with an unverfied email", name: "a user with an unverfied email",
email: "unverified@example.com", email: "unverified@example.com",
emailVerified: false, emailVerified: false,
}),
}, },
}; };
const accountService = new FakeAccountService(accounts); const accountService = new FakeAccountService(accounts);

View File

@@ -8,7 +8,7 @@ import { Vendor } from "@bitwarden/common/tools/extension/vendor/data";
import { SemanticLogger, ifEnabledSemanticLoggerProvider } from "@bitwarden/common/tools/log"; import { SemanticLogger, ifEnabledSemanticLoggerProvider } from "@bitwarden/common/tools/log";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { awaitAsync } from "../../../../../common/spec"; import { awaitAsync, mockAccountInfoWith } from "../../../../../common/spec";
import { import {
Algorithm, Algorithm,
CredentialAlgorithm, CredentialAlgorithm,
@@ -56,9 +56,10 @@ describe("DefaultCredentialGeneratorService", () => {
// Use a hard-coded value for mockAccount // Use a hard-coded value for mockAccount
account = { account = {
id: "test-account-id" as UserId, id: "test-account-id" as UserId,
emailVerified: true, ...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
name: "Test User", name: "Test User",
}),
}; };
system = { system = {

View File

@@ -8,6 +8,7 @@ import { JslibModule } from "@bitwarden/angular/jslib.module";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { ChipSelectComponent } from "@bitwarden/components"; import { ChipSelectComponent } from "@bitwarden/components";
@@ -31,9 +32,11 @@ describe("SendListFiltersComponent", () => {
accountService.activeAccount$ = of({ accountService.activeAccount$ = of({
id: userId, id: userId,
...mockAccountInfoWith({
email: "test@email.com", email: "test@email.com",
emailVerified: true,
name: "Test User", name: "Test User",
emailVerified: true,
}),
}); });
billingAccountProfileStateService.hasPremiumFromAnySource$.mockReturnValue(of(true)); billingAccountProfileStateService.hasPremiumFromAnySource$.mockReturnValue(of(true));

View File

@@ -11,6 +11,7 @@ import { EventType } from "@bitwarden/common/enums";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { PremiumUpgradePromptService } from "@bitwarden/common/vault/abstractions/premium-upgrade-prompt.service"; import { PremiumUpgradePromptService } from "@bitwarden/common/vault/abstractions/premium-upgrade-prompt.service";
import { CipherType } from "@bitwarden/common/vault/enums"; import { CipherType } from "@bitwarden/common/vault/enums";
@@ -34,9 +35,10 @@ describe("LoginCredentialsViewComponent", () => {
const hasPremiumFromAnySource$ = new BehaviorSubject<boolean>(true); const hasPremiumFromAnySource$ = new BehaviorSubject<boolean>(true);
const mockAccount = { const mockAccount = {
id: "test-user-id" as UserId, id: "test-user-id" as UserId,
...mockAccountInfoWith({
email: "test@example.com", email: "test@example.com",
emailVerified: true,
name: "Test User", name: "Test User",
}),
type: 0, type: 0,
status: 0, status: 0,
kdf: 0, kdf: 0,

View File

@@ -2,9 +2,10 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
import { NoopAnimationsModule } from "@angular/platform-browser/animations"; import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { BehaviorSubject } from "rxjs"; import { BehaviorSubject } from "rxjs";
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { mockAccountInfoWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction"; import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction"; import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
@@ -47,11 +48,7 @@ describe("AddEditFolderDialogComponent", () => {
showToast.mockClear(); showToast.mockClear();
const userId = "" as UserId; const userId = "" as UserId;
const accountInfo: AccountInfo = { const accountInfo = mockAccountInfoWith();
email: "",
emailVerified: true,
name: undefined,
};
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [AddEditFolderDialogComponent, NoopAnimationsModule], imports: [AddEditFolderDialogComponent, NoopAnimationsModule],

View File

@@ -29,6 +29,7 @@
"@bitwarden/browser/*": ["./apps/browser/src/*"], "@bitwarden/browser/*": ["./apps/browser/src/*"],
"@bitwarden/cli/*": ["./apps/cli/src/*"], "@bitwarden/cli/*": ["./apps/cli/src/*"],
"@bitwarden/client-type": ["libs/client-type/src/index.ts"], "@bitwarden/client-type": ["libs/client-type/src/index.ts"],
"@bitwarden/common/spec": ["./libs/common/spec"],
"@bitwarden/common/*": ["./libs/common/src/*"], "@bitwarden/common/*": ["./libs/common/src/*"],
"@bitwarden/components": ["./libs/components/src"], "@bitwarden/components": ["./libs/components/src"],
"@bitwarden/core-test-utils": ["libs/core-test-utils/src/index.ts"], "@bitwarden/core-test-utils": ["libs/core-test-utils/src/index.ts"],