Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-9693] Refresh - LoginDecryptionOptionsComponent #11782

Merged
merged 37 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d0bc2b9
rename legacy components to v1
rr-bw Oct 29, 2024
f453cc8
setup new component and routes
rr-bw Oct 29, 2024
d8927de
add template
rr-bw Oct 29, 2024
69a9671
Merge branch 'main' into auth/pm-9693/refresh-login-decryption-optionโ€ฆ
rr-bw Oct 31, 2024
32148cf
setup rememberDevice control methods
rr-bw Oct 31, 2024
c4fa333
use takeUntilDestroyed(this.destroyRef)
rr-bw Oct 31, 2024
335958e
migrate loadUntrustedDeviceData() and requestAdminApproval() methods
rr-bw Oct 31, 2024
d5660a9
migrate approveFromOtherDevice() method
rr-bw Oct 31, 2024
a2c3735
migrate approveWithMasterPassword() method
rr-bw Oct 31, 2024
6aa416e
migrate loadNewUserData() and restructure template
rr-bw Oct 31, 2024
b7b613b
setup services
rr-bw Nov 2, 2024
869add9
migrate and refactor createUser() method
rr-bw Nov 2, 2024
7f0ff35
remove comment
rr-bw Nov 2, 2024
ab66de1
refactor email usage and loading state
rr-bw Nov 2, 2024
eea4aac
refactor UI data properties
rr-bw Nov 2, 2024
3e66a05
refactor properties
rr-bw Nov 2, 2024
236210c
Merge branch 'main' into auth/pm-9693/refresh-login-decryption-optionโ€ฆ
rr-bw Nov 4, 2024
ff7fbc7
small reformatting and cleanup
rr-bw Nov 4, 2024
44dd2e8
Merge branch 'main' into auth/pm-9693/refresh-login-decryption-optionโ€ฆ
rr-bw Nov 4, 2024
0ff5104
add tests
rr-bw Nov 5, 2024
f72c2a0
extract functions - handleMissingEmail and handleCreateUserSuccessNavโ€ฆ
rr-bw Nov 7, 2024
ac97fae
update AnonLayout properties via AnonLayoutWrapperDataService
rr-bw Nov 7, 2024
8ff004a
Merge branch 'main' into auth/pm-9693/refresh-login-decryption-optionโ€ฆ
rr-bw Nov 7, 2024
14ffc1f
add devices icon
rr-bw Nov 7, 2024
c1a6655
remove TODO comments
rr-bw Nov 7, 2024
e94bffd
update logic for when the 'or' text is shown
rr-bw Nov 7, 2024
430d684
Merge branch 'main' into auth/pm-9693/refresh-login-decryption-optionโ€ฆ
withinfocus Nov 11, 2024
df815b1
Merge branch 'main' into auth/pm-9693/refresh-login-decryption-optionโ€ฆ
rr-bw Nov 13, 2024
aab0f60
better handling of missing email case
rr-bw Nov 19, 2024
224b1d8
add setTimeout to missingEmail handler to give user time to see toastโ€ฆ
rr-bw Nov 20, 2024
8edea2a
update error message
rr-bw Nov 20, 2024
3871a91
merge main, fix conflicts
rr-bw Nov 20, 2024
2356f6f
remove duplicate icon imports
rr-bw Nov 20, 2024
c225a20
Merge branch 'main' into auth/pm-9693/refresh-login-decryption-optionโ€ฆ
rr-bw Nov 20, 2024
58f6243
update tests for default service
rr-bw Nov 20, 2024
7e73fe3
add tests for extension service
rr-bw Nov 21, 2024
29e0745
Merge branch 'main' into auth/pm-9693/refresh-login-decryption-optionโ€ฆ
rr-bw Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/browser/src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3287,9 +3287,18 @@
"opensInANewWindow": {
"message": "Opens in a new window"
},
"rememberThisDeviceToMakeFutureLoginsSeamless": {
"message": "Remember this device to make future logins seamless"
},
"deviceApprovalRequired": {
"message": "Device approval required. Select an approval option below:"
},
"deviceApprovalRequiredV2": {
"message": "Device approval required"
},
"selectAnApprovalOptionBelow": {
"message": "Select an approval option below"
},
"rememberThisDevice": {
"message": "Remember this device"
},
Expand Down Expand Up @@ -3363,6 +3372,9 @@
"userEmailMissing": {
"message": "User email missing"
},
"activeUserEmailNotFoundLoggingYouOut": {
"message": "Active user email not found. Logging you out."
},
"deviceTrusted": {
"message": "Device trusted"
},
Expand Down Expand Up @@ -3799,6 +3811,9 @@
"accessing": {
"message": "Accessing"
},
"loggedInExclamation": {
"message": "Logged in!"
},
"passkeyNotCopied": {
"message": "Passkey will not be copied"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Router } from "@angular/router";
import { MockProxy, mock } from "jest-mock-extended";
import { BehaviorSubject } from "rxjs";

import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";

import { postLogoutMessageListener$ } from "../utils/post-logout-message-listener";

import { ExtensionLoginDecryptionOptionsService } from "./extension-login-decryption-options.service";

// Mock the module providing postLogoutMessageListener$
jest.mock("../utils/post-logout-message-listener", () => {
return {
postLogoutMessageListener$: new BehaviorSubject<string>(""), // Replace with mock subject
};
});

describe("ExtensionLoginDecryptionOptionsService", () => {
let service: ExtensionLoginDecryptionOptionsService;

let messagingService: MockProxy<MessagingService>;
let router: MockProxy<Router>;
let postLogoutMessageSubject: BehaviorSubject<string>;

beforeEach(() => {
messagingService = mock<MessagingService>();
router = mock<Router>();

// Cast postLogoutMessageListener$ to BehaviorSubject for dynamic control
postLogoutMessageSubject = postLogoutMessageListener$ as BehaviorSubject<string>;

service = new ExtensionLoginDecryptionOptionsService(messagingService, router);
});

it("should instantiate the service", () => {
expect(service).not.toBeFalsy();
});

describe("logOut()", () => {
it("should send a logout message", async () => {
postLogoutMessageSubject.next("switchAccountFinish");

await service.logOut();

expect(messagingService.send).toHaveBeenCalledWith("logout");
});

it("should navigate to root on 'switchAccountFinish'", async () => {
postLogoutMessageSubject.next("switchAccountFinish");

await service.logOut();

expect(router.navigate).toHaveBeenCalledWith(["/"]);
});

it("should not navigate for 'doneLoggingOut'", async () => {
postLogoutMessageSubject.next("doneLoggingOut");

await service.logOut();

expect(router.navigate).not.toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Router } from "@angular/router";
import { firstValueFrom } from "rxjs";

import {
DefaultLoginDecryptionOptionsService,
LoginDecryptionOptionsService,
} from "@bitwarden/auth/angular";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";

import { postLogoutMessageListener$ } from "../utils/post-logout-message-listener";

export class ExtensionLoginDecryptionOptionsService
extends DefaultLoginDecryptionOptionsService
implements LoginDecryptionOptionsService
{
constructor(
protected messagingService: MessagingService,
private router: Router,
) {
super(messagingService);
}

override async logOut(): Promise<void> {
// start listening for "switchAccountFinish" or "doneLoggingOut"
const messagePromise = firstValueFrom(postLogoutMessageListener$);

super.logOut();

// wait for messages
const command = await messagePromise;

// doneLoggingOut already has a message handler that will navigate us
if (command === "switchAccountFinish") {
await this.router.navigate(["/"]);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Component } from "@angular/core";
import { firstValueFrom } from "rxjs";

import { BaseLoginDecryptionOptionsComponent } from "@bitwarden/angular/auth/components/base-login-decryption-options.component";
import { BaseLoginDecryptionOptionsComponentV1 } from "@bitwarden/angular/auth/components/base-login-decryption-options-v1.component";

Check warning on line 4 in apps/browser/src/auth/popup/login-decryption-options/login-decryption-options-v1.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/auth/popup/login-decryption-options/login-decryption-options-v1.component.ts#L4

Added line #L4 was not covered by tests

import { postLogoutMessageListener$ } from "../utils/post-logout-message-listener";

@Component({
selector: "browser-login-decryption-options",
templateUrl: "login-decryption-options.component.html",
templateUrl: "login-decryption-options-v1.component.html",
})
export class LoginDecryptionOptionsComponent extends BaseLoginDecryptionOptionsComponent {
export class LoginDecryptionOptionsComponentV1 extends BaseLoginDecryptionOptionsComponentV1 {

Check warning on line 12 in apps/browser/src/auth/popup/login-decryption-options/login-decryption-options-v1.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/auth/popup/login-decryption-options/login-decryption-options-v1.component.ts#L12

Added line #L12 was not covered by tests
override async createUser(): Promise<void> {
try {
await super.createUser();
Expand Down
28 changes: 20 additions & 8 deletions apps/browser/src/popup/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import {
AnonLayoutWrapperComponent,
AnonLayoutWrapperData,
DevicesIcon,
LoginComponent,
LoginSecondaryContentComponent,
LockIcon,
Expand All @@ -37,6 +36,8 @@
SetPasswordJitComponent,
UserLockIcon,
VaultIcon,
LoginDecryptionOptionsComponent,
DevicesIcon,
} from "@bitwarden/auth/angular";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";

Expand All @@ -51,7 +52,7 @@
import { HintComponent } from "../auth/popup/hint.component";
import { HomeComponent } from "../auth/popup/home.component";
import { LockComponent } from "../auth/popup/lock.component";
import { LoginDecryptionOptionsComponent } from "../auth/popup/login-decryption-options/login-decryption-options.component";
import { LoginDecryptionOptionsComponentV1 } from "../auth/popup/login-decryption-options/login-decryption-options-v1.component";

Check warning on line 55 in apps/browser/src/popup/app-routing.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/popup/app-routing.module.ts#L55

Added line #L55 was not covered by tests
import { LoginComponentV1 } from "../auth/popup/login-v1.component";
import { LoginViaAuthRequestComponentV1 } from "../auth/popup/login-via-auth-request-v1.component";
import { RegisterComponent } from "../auth/popup/register.component";
Expand Down Expand Up @@ -206,12 +207,6 @@
canActivate: [unauthGuardFn(unauthRouteOverrides)],
data: { state: "2fa-options" } satisfies RouteDataProperties,
},
{
path: "login-initiated",
component: LoginDecryptionOptionsComponent,
canActivate: [tdeDecryptionRequiredGuard()],
data: { state: "login-initiated" } satisfies RouteDataProperties,
},
{
path: "sso",
component: SsoComponent,
Expand Down Expand Up @@ -534,6 +529,23 @@
],
},
),
...unauthUiRefreshSwap(
LoginDecryptionOptionsComponentV1,
ExtensionAnonLayoutWrapperComponent,
{
path: "login-initiated",
canActivate: [tdeDecryptionRequiredGuard()],
data: { state: "login-initiated" } satisfies RouteDataProperties,
},
{
path: "login-initiated",
canActivate: [tdeDecryptionRequiredGuard()],
data: {
pageIcon: DevicesIcon,
},
children: [{ path: "", component: LoginDecryptionOptionsComponent }],
},
),
{
path: "",
component: ExtensionAnonLayoutWrapperComponent,
Expand Down
4 changes: 2 additions & 2 deletions apps/browser/src/popup/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import { HintComponent } from "../auth/popup/hint.component";
import { HomeComponent } from "../auth/popup/home.component";
import { LockComponent } from "../auth/popup/lock.component";
import { LoginDecryptionOptionsComponent } from "../auth/popup/login-decryption-options/login-decryption-options.component";
import { LoginDecryptionOptionsComponentV1 } from "../auth/popup/login-decryption-options/login-decryption-options-v1.component";

Check warning on line 27 in apps/browser/src/popup/app.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/popup/app.module.ts#L27

Added line #L27 was not covered by tests
import { LoginComponentV1 } from "../auth/popup/login-v1.component";
import { LoginViaAuthRequestComponentV1 } from "../auth/popup/login-via-auth-request-v1.component";
import { RegisterComponent } from "../auth/popup/register.component";
Expand Down Expand Up @@ -161,7 +161,7 @@
LockComponent,
LoginViaAuthRequestComponentV1,
LoginComponentV1,
LoginDecryptionOptionsComponent,
LoginDecryptionOptionsComponentV1,
NotificationsSettingsV1Component,
AppearanceComponent,
GeneratorComponent,
Expand Down
8 changes: 8 additions & 0 deletions apps/browser/src/popup/services/services.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APP_INITIALIZER, NgModule, NgZone } from "@angular/core";
import { Router } from "@angular/router";

Check warning on line 2 in apps/browser/src/popup/services/services.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/popup/services/services.module.ts#L2

Added line #L2 was not covered by tests
import { Subject, merge, of } from "rxjs";

import { CollectionService } from "@bitwarden/admin-console/common";
Expand All @@ -22,6 +23,7 @@
AnonLayoutWrapperDataService,
LoginComponentService,
LockComponentService,
LoginDecryptionOptionsService,
} from "@bitwarden/auth/angular";
import { LockService, LoginEmailService, PinServiceAbstraction } from "@bitwarden/auth/common";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
Expand Down Expand Up @@ -115,6 +117,7 @@
import { ForegroundLockService } from "../../auth/popup/accounts/foreground-lock.service";
import { ExtensionAnonLayoutWrapperDataService } from "../../auth/popup/extension-anon-layout-wrapper/extension-anon-layout-wrapper-data.service";
import { ExtensionLoginComponentService } from "../../auth/popup/login/extension-login-component.service";
import { ExtensionLoginDecryptionOptionsService } from "../../auth/popup/login-decryption-options/extension-login-decryption-options.service";

Check warning on line 120 in apps/browser/src/popup/services/services.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/popup/services/services.module.ts#L120

Added line #L120 was not covered by tests
import { AutofillService as AutofillServiceAbstraction } from "../../autofill/services/abstractions/autofill.service";
import AutofillService from "../../autofill/services/autofill.service";
import { InlineMenuFieldQualificationService } from "../../autofill/services/inline-menu-field-qualification.service";
Expand Down Expand Up @@ -591,6 +594,11 @@
useExisting: PopupCompactModeService,
deps: [],
}),
safeProvider({
provide: LoginDecryptionOptionsService,
useClass: ExtensionLoginDecryptionOptionsService,
deps: [MessagingServiceAbstraction, Router],
}),
];

@NgModule({
Expand Down
26 changes: 19 additions & 7 deletions apps/desktop/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import {
AnonLayoutWrapperComponent,
AnonLayoutWrapperData,
DevicesIcon,
LoginComponent,
LoginSecondaryContentComponent,
LockIcon,
Expand All @@ -34,6 +33,8 @@
SetPasswordJitComponent,
UserLockIcon,
VaultIcon,
LoginDecryptionOptionsComponent,
DevicesIcon,
} from "@bitwarden/auth/angular";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";

Expand All @@ -42,7 +43,7 @@
import { maxAccountsGuardFn } from "../auth/guards/max-accounts.guard";
import { HintComponent } from "../auth/hint.component";
import { LockComponent } from "../auth/lock.component";
import { LoginDecryptionOptionsComponent } from "../auth/login/login-decryption-options/login-decryption-options.component";
import { LoginDecryptionOptionsComponentV1 } from "../auth/login/login-decryption-options/login-decryption-options-v1.component";

Check warning on line 46 in apps/desktop/src/app/app-routing.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/app/app-routing.module.ts#L46

Added line #L46 was not covered by tests
import { LoginComponentV1 } from "../auth/login/login-v1.component";
import { LoginViaAuthRequestComponentV1 } from "../auth/login/login-via-auth-request-v1.component";
import { RegisterComponent } from "../auth/register.component";
Expand Down Expand Up @@ -95,11 +96,6 @@
],
},
),
{
path: "login-initiated",
component: LoginDecryptionOptionsComponent,
canActivate: [tdeDecryptionRequiredGuard()],
},
{ path: "register", component: RegisterComponent },
{
path: "vault",
Expand Down Expand Up @@ -241,6 +237,22 @@
],
},
),
...unauthUiRefreshSwap(
LoginDecryptionOptionsComponentV1,
AnonLayoutWrapperComponent,
{
path: "login-initiated",
canActivate: [tdeDecryptionRequiredGuard()],
},
{
path: "login-initiated",
canActivate: [tdeDecryptionRequiredGuard()],
data: {
pageIcon: DevicesIcon,
},
children: [{ path: "", component: LoginDecryptionOptionsComponent }],
},
),
{
path: "",
component: AnonLayoutWrapperComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Component } from "@angular/core";

import { BaseLoginDecryptionOptionsComponent } from "@bitwarden/angular/auth/components/base-login-decryption-options.component";
import { BaseLoginDecryptionOptionsComponentV1 } from "@bitwarden/angular/auth/components/base-login-decryption-options-v1.component";

Check warning on line 3 in apps/desktop/src/auth/login/login-decryption-options/login-decryption-options-v1.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/auth/login/login-decryption-options/login-decryption-options-v1.component.ts#L3

Added line #L3 was not covered by tests

@Component({
selector: "desktop-login-decryption-options",
templateUrl: "login-decryption-options.component.html",
templateUrl: "login-decryption-options-v1.component.html",
})
export class LoginDecryptionOptionsComponent extends BaseLoginDecryptionOptionsComponent {
export class LoginDecryptionOptionsComponentV1 extends BaseLoginDecryptionOptionsComponentV1 {

Check warning on line 9 in apps/desktop/src/auth/login/login-decryption-options/login-decryption-options-v1.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/auth/login/login-decryption-options/login-decryption-options-v1.component.ts#L9

Added line #L9 was not covered by tests
override async createUser(): Promise<void> {
try {
await super.createUser();
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/auth/login/login.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { SharedModule } from "../../app/shared/shared.module";

import { LoginDecryptionOptionsComponent } from "./login-decryption-options/login-decryption-options.component";
import { LoginDecryptionOptionsComponentV1 } from "./login-decryption-options/login-decryption-options-v1.component";

Check warning on line 8 in apps/desktop/src/auth/login/login.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/auth/login/login.module.ts#L8

Added line #L8 was not covered by tests
import { LoginComponentV1 } from "./login-v1.component";
import { LoginViaAuthRequestComponentV1 } from "./login-via-auth-request-v1.component";

Expand All @@ -15,7 +15,7 @@
LoginComponentV1,
LoginViaAuthRequestComponentV1,
EnvironmentSelectorComponent,
LoginDecryptionOptionsComponent,
LoginDecryptionOptionsComponentV1,
],
exports: [LoginComponentV1, LoginViaAuthRequestComponentV1],
})
Expand Down
Loading
Loading