mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
Get clientType via service.
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
import { TestBed } from "@angular/core/testing";
|
import { TestBed } from "@angular/core/testing";
|
||||||
|
import { MockProxy, mock } from "jest-mock-extended";
|
||||||
|
|
||||||
import { DefaultLoginComponentService } from "@bitwarden/auth/angular";
|
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 { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
import { flagEnabled } from "../../../platform/flags";
|
import { flagEnabled } from "../../../platform/flags";
|
||||||
|
import { BrowserPlatformUtilsService } from "../../../platform/services/platform-utils/browser-platform-utils.service";
|
||||||
|
|
||||||
import { ExtensionLoginComponentService } from "./extension-login-component.service";
|
import { ExtensionLoginComponentService } from "./extension-login-component.service";
|
||||||
|
|
||||||
@@ -12,12 +19,38 @@ jest.mock("../../../platform/flags", () => ({
|
|||||||
|
|
||||||
describe("ExtensionLoginComponentService", () => {
|
describe("ExtensionLoginComponentService", () => {
|
||||||
let service: ExtensionLoginComponentService;
|
let service: ExtensionLoginComponentService;
|
||||||
|
let cryptoFunctionService: MockProxy<CryptoFunctionService>;
|
||||||
|
let environmentService: MockProxy<EnvironmentService>;
|
||||||
|
let passwordGenerationService: MockProxy<PasswordGenerationServiceAbstraction>;
|
||||||
|
let platformUtilsService: MockProxy<BrowserPlatformUtilsService>;
|
||||||
|
let ssoLoginService: MockProxy<SsoLoginServiceAbstraction>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
cryptoFunctionService = mock<CryptoFunctionService>();
|
||||||
|
environmentService = mock<EnvironmentService>();
|
||||||
|
passwordGenerationService = mock<PasswordGenerationServiceAbstraction>();
|
||||||
|
platformUtilsService = mock<BrowserPlatformUtilsService>();
|
||||||
|
ssoLoginService = mock<SsoLoginServiceAbstraction>();
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
ExtensionLoginComponentService,
|
{
|
||||||
{ provide: DefaultLoginComponentService, useClass: ExtensionLoginComponentService },
|
provide: ExtensionLoginComponentService,
|
||||||
|
useFactory: () =>
|
||||||
|
new ExtensionLoginComponentService(
|
||||||
|
cryptoFunctionService,
|
||||||
|
environmentService,
|
||||||
|
passwordGenerationService,
|
||||||
|
platformUtilsService,
|
||||||
|
ssoLoginService,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ provide: DefaultLoginComponentService, useExisting: ExtensionLoginComponentService },
|
||||||
|
{ provide: CryptoFunctionService, useValue: cryptoFunctionService },
|
||||||
|
{ provide: EnvironmentService, useValue: environmentService },
|
||||||
|
{ provide: PasswordGenerationServiceAbstraction, useValue: passwordGenerationService },
|
||||||
|
{ provide: PlatformUtilsService, useValue: platformUtilsService },
|
||||||
|
{ provide: SsoLoginServiceAbstraction, useValue: ssoLoginService },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
service = TestBed.inject(ExtensionLoginComponentService);
|
service = TestBed.inject(ExtensionLoginComponentService);
|
||||||
|
|||||||
@@ -1,13 +1,36 @@
|
|||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
|
||||||
import { DefaultLoginComponentService, LoginComponentService } from "@bitwarden/auth/angular";
|
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 { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
import { flagEnabled } from "../../../platform/flags";
|
import { flagEnabled } from "../../../platform/flags";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
export class ExtensionLoginComponentService
|
export class ExtensionLoginComponentService
|
||||||
extends DefaultLoginComponentService
|
extends DefaultLoginComponentService
|
||||||
implements LoginComponentService
|
implements LoginComponentService
|
||||||
{
|
{
|
||||||
clientType = ClientType.Browser;
|
constructor(
|
||||||
|
cryptoFunctionService: CryptoFunctionService,
|
||||||
|
environmentService: EnvironmentService,
|
||||||
|
passwordGenerationService: PasswordGenerationServiceAbstraction,
|
||||||
|
platformUtilsService: PlatformUtilsService,
|
||||||
|
ssoLoginService: SsoLoginServiceAbstraction,
|
||||||
|
) {
|
||||||
|
super(
|
||||||
|
cryptoFunctionService,
|
||||||
|
environmentService,
|
||||||
|
passwordGenerationService,
|
||||||
|
platformUtilsService,
|
||||||
|
ssoLoginService,
|
||||||
|
);
|
||||||
|
this.clientType = this.platformUtilsService.getClientType();
|
||||||
|
}
|
||||||
|
|
||||||
isLoginViaAuthRequestSupported(): boolean {
|
isLoginViaAuthRequestSupported(): boolean {
|
||||||
return flagEnabled("showPasswordless");
|
return flagEnabled("showPasswordless");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ import { MemoryStorageService as MemoryStorageServiceForStateProviders } from "@
|
|||||||
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
|
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
|
||||||
import { VaultTimeoutStringType } from "@bitwarden/common/types/vault-timeout.type";
|
import { VaultTimeoutStringType } from "@bitwarden/common/types/vault-timeout.type";
|
||||||
import { CipherService as CipherServiceAbstraction } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService as CipherServiceAbstraction } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { DialogService } from "@bitwarden/components";
|
import { DialogService, ToastService } from "@bitwarden/components";
|
||||||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
import { BiometricStateService, BiometricsService } from "@bitwarden/key-management";
|
import { BiometricStateService, BiometricsService } from "@bitwarden/key-management";
|
||||||
|
|
||||||
@@ -329,6 +329,8 @@ const safeProviders: SafeProvider[] = [
|
|||||||
PasswordGenerationServiceAbstraction,
|
PasswordGenerationServiceAbstraction,
|
||||||
PlatformUtilsServiceAbstraction,
|
PlatformUtilsServiceAbstraction,
|
||||||
SsoLoginServiceAbstraction,
|
SsoLoginServiceAbstraction,
|
||||||
|
I18nServiceAbstraction,
|
||||||
|
ToastService,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import { TestBed } from "@angular/core/testing";
|
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 { DefaultLoginComponentService } from "@bitwarden/auth/angular";
|
||||||
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
|
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
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 { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { ToastService } from "@bitwarden/components";
|
import { ToastService } from "@bitwarden/components";
|
||||||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
|
import { ElectronPlatformUtilsService } from "../../platform/services/electron-platform-utils.service";
|
||||||
|
|
||||||
import { DesktopLoginComponentService } from "./desktop-login-component.service";
|
import { DesktopLoginComponentService } from "./desktop-login-component.service";
|
||||||
|
|
||||||
(global as any).ipc = {
|
(global as any).ipc = {
|
||||||
@@ -23,22 +27,46 @@ import { DesktopLoginComponentService } from "./desktop-login-component.service"
|
|||||||
|
|
||||||
describe("DesktopLoginComponentService", () => {
|
describe("DesktopLoginComponentService", () => {
|
||||||
let service: 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 i18nService: MockProxy<I18nService>;
|
||||||
let toastService: MockProxy<ToastService>;
|
let toastService: MockProxy<ToastService>;
|
||||||
let ssoLoginService: MockProxy<SsoLoginServiceAbstraction>;
|
|
||||||
let passwordGenerationService: MockProxy<PasswordGenerationServiceAbstraction>;
|
|
||||||
let cryptoFunctionService: MockProxy<CryptoFunctionService>;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
cryptoFunctionService = mock<CryptoFunctionService>();
|
||||||
|
environmentService = mock<EnvironmentService>();
|
||||||
|
passwordGenerationService = mock<PasswordGenerationServiceAbstraction>();
|
||||||
|
platformUtilsService = mock<ElectronPlatformUtilsService>();
|
||||||
|
ssoLoginService = mock<SsoLoginServiceAbstraction>();
|
||||||
|
i18nService = mock<I18nService>();
|
||||||
|
toastService = mock<ToastService>();
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
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: I18nService, useValue: i18nService },
|
||||||
{ provide: ToastService, useValue: toastService },
|
{ provide: ToastService, useValue: toastService },
|
||||||
{ provide: SsoLoginServiceAbstraction, useValue: ssoLoginService },
|
|
||||||
{ provide: PasswordGenerationServiceAbstraction, useValue: passwordGenerationService },
|
|
||||||
{ provide: CryptoFunctionService, useValue: cryptoFunctionService },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,38 @@
|
|||||||
import { inject } from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
|
|
||||||
import { DefaultLoginComponentService, LoginComponentService } from "@bitwarden/auth/angular";
|
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 { 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 { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { ToastService } from "@bitwarden/components";
|
import { ToastService } from "@bitwarden/components";
|
||||||
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
export class DesktopLoginComponentService
|
export class DesktopLoginComponentService
|
||||||
extends DefaultLoginComponentService
|
extends DefaultLoginComponentService
|
||||||
implements LoginComponentService
|
implements LoginComponentService
|
||||||
{
|
{
|
||||||
i18nService = inject(I18nService);
|
constructor(
|
||||||
toastService = inject(ToastService);
|
protected cryptoFunctionService: CryptoFunctionService,
|
||||||
clientType = ClientType.Desktop;
|
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> {
|
override async launchSsoBrowserWindow(email: string, clientId: "desktop"): Promise<void | null> {
|
||||||
if (!ipc.platform.isAppImage && !ipc.platform.isSnapStore && !ipc.platform.isDev) {
|
if (!ipc.platform.isAppImage && !ipc.platform.isSnapStore && !ipc.platform.isDev) {
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { TestBed } from "@angular/core/testing";
|
import { TestBed } from "@angular/core/testing";
|
||||||
import { UrlTree } from "@angular/router";
|
import { UrlTree } from "@angular/router";
|
||||||
|
import { MockProxy, mock } from "jest-mock-extended";
|
||||||
|
|
||||||
import { DefaultLoginComponentService } from "@bitwarden/auth/angular";
|
import { DefaultLoginComponentService } from "@bitwarden/auth/angular";
|
||||||
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
||||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
|
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 { 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 { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
import { RouterService } from "../../../../../../../../apps/web/src/app/core";
|
import { RouterService } from "../../../../../../../../apps/web/src/app/core";
|
||||||
import { flagEnabled } from "../../../../../utils/flags";
|
import { flagEnabled } from "../../../../../utils/flags";
|
||||||
@@ -18,37 +24,43 @@ jest.mock("../../../../../utils/flags", () => ({
|
|||||||
|
|
||||||
describe("WebLoginComponentService", () => {
|
describe("WebLoginComponentService", () => {
|
||||||
let service: WebLoginComponentService;
|
let service: WebLoginComponentService;
|
||||||
|
let acceptOrganizationInviteService: MockProxy<AcceptOrganizationInviteService>;
|
||||||
|
let logService: MockProxy<LogService>;
|
||||||
|
let policyApiService: MockProxy<PolicyApiServiceAbstraction>;
|
||||||
|
let internalPolicyService: MockProxy<InternalPolicyService>;
|
||||||
|
let routerService: MockProxy<RouterService>;
|
||||||
|
let cryptoFunctionService: MockProxy<CryptoFunctionService>;
|
||||||
|
let environmentService: MockProxy<EnvironmentService>;
|
||||||
|
let passwordGenerationService: MockProxy<PasswordGenerationServiceAbstraction>;
|
||||||
|
let platformUtilsService: MockProxy<PlatformUtilsService>;
|
||||||
|
let ssoLoginService: MockProxy<SsoLoginServiceAbstraction>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
acceptOrganizationInviteService = mock<AcceptOrganizationInviteService>();
|
||||||
|
logService = mock<LogService>();
|
||||||
|
policyApiService = mock<PolicyApiServiceAbstraction>();
|
||||||
|
internalPolicyService = mock<InternalPolicyService>();
|
||||||
|
routerService = mock<RouterService>();
|
||||||
|
cryptoFunctionService = mock<CryptoFunctionService>();
|
||||||
|
environmentService = mock<EnvironmentService>();
|
||||||
|
passwordGenerationService = mock<PasswordGenerationServiceAbstraction>();
|
||||||
|
platformUtilsService = mock<PlatformUtilsService>();
|
||||||
|
ssoLoginService = mock<SsoLoginServiceAbstraction>();
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
WebLoginComponentService,
|
WebLoginComponentService,
|
||||||
{ provide: DefaultLoginComponentService, useClass: WebLoginComponentService },
|
{ provide: DefaultLoginComponentService, useClass: WebLoginComponentService },
|
||||||
{
|
{ provide: AcceptOrganizationInviteService, useValue: acceptOrganizationInviteService },
|
||||||
provide: AcceptOrganizationInviteService,
|
{ provide: LogService, useValue: logService },
|
||||||
useValue: {
|
{ provide: PolicyApiServiceAbstraction, useValue: policyApiService },
|
||||||
getOrganizationInvite: jest.fn(),
|
{ provide: InternalPolicyService, useValue: internalPolicyService },
|
||||||
},
|
{ provide: RouterService, useValue: routerService },
|
||||||
},
|
{ provide: CryptoFunctionService, useValue: cryptoFunctionService },
|
||||||
{
|
{ provide: EnvironmentService, useValue: environmentService },
|
||||||
provide: LogService,
|
{ provide: PasswordGenerationServiceAbstraction, useValue: passwordGenerationService },
|
||||||
useValue: {
|
{ provide: PlatformUtilsService, useValue: platformUtilsService },
|
||||||
error: jest.fn(),
|
{ provide: SsoLoginServiceAbstraction, useValue: ssoLoginService },
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: PolicyApiServiceAbstraction,
|
|
||||||
useValue: {
|
|
||||||
getPoliciesByToken: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ provide: InternalPolicyService, useValue: {} },
|
|
||||||
{
|
|
||||||
provide: RouterService,
|
|
||||||
useValue: {
|
|
||||||
setPreviousUrl: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
service = TestBed.inject(WebLoginComponentService);
|
service = TestBed.inject(WebLoginComponentService);
|
||||||
@@ -72,22 +84,19 @@ describe("WebLoginComponentService", () => {
|
|||||||
|
|
||||||
it("sets the previous URL", () => {
|
it("sets the previous URL", () => {
|
||||||
const route = { toString: () => "test-url" } as UrlTree;
|
const route = { toString: () => "test-url" } as UrlTree;
|
||||||
const routerServiceSpy = jest.spyOn(service.routerService, "setPreviousUrl");
|
|
||||||
service.setPreviousUrl(route);
|
service.setPreviousUrl(route);
|
||||||
expect(routerServiceSpy).toHaveBeenCalledWith("test-url");
|
expect(routerService.setPreviousUrl).toHaveBeenCalledWith("test-url");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns undefined if organization invite is null", async () => {
|
it("returns undefined if organization invite is null", async () => {
|
||||||
jest
|
acceptOrganizationInviteService.getOrganizationInvite.mockResolvedValue(null);
|
||||||
.spyOn(service.acceptOrganizationInviteService, "getOrganizationInvite")
|
|
||||||
.mockResolvedValue(null);
|
|
||||||
const result = await service.getOrgPolicies();
|
const result = await service.getOrgPolicies();
|
||||||
expect(result).toBeUndefined();
|
expect(result).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("logs an error if getPoliciesByToken throws an error", async () => {
|
it("logs an error if getPoliciesByToken throws an error", async () => {
|
||||||
const error = new Error("Test error");
|
const error = new Error("Test error");
|
||||||
jest.spyOn(service.acceptOrganizationInviteService, "getOrganizationInvite").mockResolvedValue({
|
acceptOrganizationInviteService.getOrganizationInvite.mockResolvedValue({
|
||||||
organizationId: "org-id",
|
organizationId: "org-id",
|
||||||
token: "token",
|
token: "token",
|
||||||
email: "email",
|
email: "email",
|
||||||
@@ -97,9 +106,8 @@ describe("WebLoginComponentService", () => {
|
|||||||
orgUserHasExistingUser: false,
|
orgUserHasExistingUser: false,
|
||||||
organizationName: "org-name",
|
organizationName: "org-name",
|
||||||
});
|
});
|
||||||
jest.spyOn(service.policyApiService, "getPoliciesByToken").mockRejectedValue(error);
|
policyApiService.getPoliciesByToken.mockRejectedValue(error);
|
||||||
const logServiceSpy = jest.spyOn(service.logService, "error");
|
|
||||||
await service.getOrgPolicies();
|
await service.getOrgPolicies();
|
||||||
expect(logServiceSpy).toHaveBeenCalledWith(error);
|
expect(logService.error).toHaveBeenCalledWith(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { inject } from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
import { Router, UrlTree } from "@angular/router";
|
import { UrlTree } from "@angular/router";
|
||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -10,24 +10,43 @@ import {
|
|||||||
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
||||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||||
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 { 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 { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
import { flagEnabled } from "../../../../../utils/flags";
|
import { flagEnabled } from "../../../../../utils/flags";
|
||||||
import { RouterService } from "../../../../core/router.service";
|
import { RouterService } from "../../../../core/router.service";
|
||||||
import { AcceptOrganizationInviteService } from "../../../organization-invite/accept-organization.service";
|
import { AcceptOrganizationInviteService } from "../../../organization-invite/accept-organization.service";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
export class WebLoginComponentService
|
export class WebLoginComponentService
|
||||||
extends DefaultLoginComponentService
|
extends DefaultLoginComponentService
|
||||||
implements LoginComponentService
|
implements LoginComponentService
|
||||||
{
|
{
|
||||||
acceptOrganizationInviteService = inject(AcceptOrganizationInviteService);
|
constructor(
|
||||||
logService = inject(LogService);
|
protected acceptOrganizationInviteService: AcceptOrganizationInviteService,
|
||||||
policyApiService = inject(PolicyApiServiceAbstraction);
|
protected logService: LogService,
|
||||||
policyService = inject(InternalPolicyService);
|
protected policyApiService: PolicyApiServiceAbstraction,
|
||||||
router = inject(Router);
|
protected policyService: InternalPolicyService,
|
||||||
routerService = inject(RouterService);
|
protected routerService: RouterService,
|
||||||
clientType = ClientType.Web;
|
cryptoFunctionService: CryptoFunctionService,
|
||||||
|
environmentService: EnvironmentService,
|
||||||
|
passwordGenerationService: PasswordGenerationServiceAbstraction,
|
||||||
|
platformUtilsService: PlatformUtilsService,
|
||||||
|
ssoLoginService: SsoLoginServiceAbstraction,
|
||||||
|
) {
|
||||||
|
super(
|
||||||
|
cryptoFunctionService,
|
||||||
|
environmentService,
|
||||||
|
passwordGenerationService,
|
||||||
|
platformUtilsService,
|
||||||
|
ssoLoginService,
|
||||||
|
);
|
||||||
|
this.clientType = this.platformUtilsService.getClientType();
|
||||||
|
}
|
||||||
|
|
||||||
isLoginViaAuthRequestSupported(): boolean {
|
isLoginViaAuthRequestSupported(): boolean {
|
||||||
return flagEnabled("showPasswordless");
|
return flagEnabled("showPasswordless");
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ import {
|
|||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
|
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
|
||||||
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
||||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import {
|
||||||
|
InternalPolicyService,
|
||||||
|
PolicyService,
|
||||||
|
} from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { AccountApiService as AccountApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/account-api.service";
|
import { AccountApiService as AccountApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/account-api.service";
|
||||||
import { 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";
|
||||||
@@ -257,6 +260,11 @@ const safeProviders: SafeProvider[] = [
|
|||||||
provide: LoginComponentService,
|
provide: LoginComponentService,
|
||||||
useClass: WebLoginComponentService,
|
useClass: WebLoginComponentService,
|
||||||
deps: [
|
deps: [
|
||||||
|
AcceptOrganizationInviteService,
|
||||||
|
LogService,
|
||||||
|
PolicyApiServiceAbstraction,
|
||||||
|
InternalPolicyService,
|
||||||
|
RouterService,
|
||||||
CryptoFunctionServiceAbstraction,
|
CryptoFunctionServiceAbstraction,
|
||||||
EnvironmentService,
|
EnvironmentService,
|
||||||
PasswordGenerationServiceAbstraction,
|
PasswordGenerationServiceAbstraction,
|
||||||
|
|||||||
Reference in New Issue
Block a user