1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-30 23:23:52 +00:00

Get clientType via service.

This commit is contained in:
Alec Rippberger
2024-10-09 22:31:43 -05:00
parent 982da467b4
commit 3868dcbc60
8 changed files with 205 additions and 64 deletions

View File

@@ -1,13 +1,17 @@
import { TestBed } from "@angular/core/testing";
import { MockProxy } from "jest-mock-extended";
import { MockProxy, mock } from "jest-mock-extended";
import { DefaultLoginComponentService } from "@bitwarden/auth/angular";
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { ElectronPlatformUtilsService } from "../../platform/services/electron-platform-utils.service";
import { DesktopLoginComponentService } from "./desktop-login-component.service";
(global as any).ipc = {
@@ -23,22 +27,46 @@ import { DesktopLoginComponentService } from "./desktop-login-component.service"
describe("DesktopLoginComponentService", () => {
let service: DesktopLoginComponentService;
let cryptoFunctionService: MockProxy<CryptoFunctionService>;
let environmentService: MockProxy<EnvironmentService>;
let passwordGenerationService: MockProxy<PasswordGenerationServiceAbstraction>;
let platformUtilsService: MockProxy<ElectronPlatformUtilsService>;
let ssoLoginService: MockProxy<SsoLoginServiceAbstraction>;
let i18nService: MockProxy<I18nService>;
let toastService: MockProxy<ToastService>;
let ssoLoginService: MockProxy<SsoLoginServiceAbstraction>;
let passwordGenerationService: MockProxy<PasswordGenerationServiceAbstraction>;
let cryptoFunctionService: MockProxy<CryptoFunctionService>;
beforeEach(() => {
cryptoFunctionService = mock<CryptoFunctionService>();
environmentService = mock<EnvironmentService>();
passwordGenerationService = mock<PasswordGenerationServiceAbstraction>();
platformUtilsService = mock<ElectronPlatformUtilsService>();
ssoLoginService = mock<SsoLoginServiceAbstraction>();
i18nService = mock<I18nService>();
toastService = mock<ToastService>();
TestBed.configureTestingModule({
providers: [
DesktopLoginComponentService,
{ provide: DefaultLoginComponentService, useClass: DesktopLoginComponentService },
{
provide: DesktopLoginComponentService,
useFactory: () =>
new DesktopLoginComponentService(
cryptoFunctionService,
environmentService,
passwordGenerationService,
platformUtilsService,
ssoLoginService,
i18nService,
toastService,
),
},
{ provide: DefaultLoginComponentService, useExisting: DesktopLoginComponentService },
{ provide: CryptoFunctionService, useValue: cryptoFunctionService },
{ provide: EnvironmentService, useValue: environmentService },
{ provide: PasswordGenerationServiceAbstraction, useValue: passwordGenerationService },
{ provide: PlatformUtilsService, useValue: platformUtilsService },
{ provide: SsoLoginServiceAbstraction, useValue: ssoLoginService },
{ provide: I18nService, useValue: i18nService },
{ provide: ToastService, useValue: toastService },
{ provide: SsoLoginServiceAbstraction, useValue: ssoLoginService },
{ provide: PasswordGenerationServiceAbstraction, useValue: passwordGenerationService },
{ provide: CryptoFunctionService, useValue: cryptoFunctionService },
],
});

View File

@@ -1,18 +1,38 @@
import { inject } from "@angular/core";
import { Injectable } from "@angular/core";
import { DefaultLoginComponentService, LoginComponentService } from "@bitwarden/auth/angular";
import { ClientType } from "@bitwarden/common/enums";
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
@Injectable()
export class DesktopLoginComponentService
extends DefaultLoginComponentService
implements LoginComponentService
{
i18nService = inject(I18nService);
toastService = inject(ToastService);
clientType = ClientType.Desktop;
constructor(
protected cryptoFunctionService: CryptoFunctionService,
protected environmentService: EnvironmentService,
protected passwordGenerationService: PasswordGenerationServiceAbstraction,
protected platformUtilsService: PlatformUtilsService,
protected ssoLoginService: SsoLoginServiceAbstraction,
protected i18nService: I18nService,
protected toastService: ToastService,
) {
super(
cryptoFunctionService,
environmentService,
passwordGenerationService,
platformUtilsService,
ssoLoginService,
);
this.clientType = this.platformUtilsService.getClientType();
}
override async launchSsoBrowserWindow(email: string, clientId: "desktop"): Promise<void | null> {
if (!ipc.platform.isAppImage && !ipc.platform.isSnapStore && !ipc.platform.isDev) {