-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-17751] Store SSO email in state on web client (#13295)
* Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. --------- Co-authored-by: Bernd Schoolmann <[email protected]>
- Loading branch information
Showing
26 changed files
with
532 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { TestBed } from "@angular/core/testing"; | ||
import { MockProxy, mock } from "jest-mock-extended"; | ||
import { BehaviorSubject } from "rxjs"; | ||
|
||
import { DefaultLoginComponentService } from "@bitwarden/auth/angular"; | ||
import { SsoUrlService } from "@bitwarden/auth/common"; | ||
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction"; | ||
import { ClientType } from "@bitwarden/common/enums"; | ||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service"; | ||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; | ||
import { | ||
Environment, | ||
EnvironmentService, | ||
} from "@bitwarden/common/platform/abstractions/environment.service"; | ||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; | ||
import { Utils } from "@bitwarden/common/platform/misc/utils"; | ||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; | ||
|
||
import { BrowserPlatformUtilsService } from "../../../platform/services/platform-utils/browser-platform-utils.service"; | ||
|
@@ -18,20 +25,28 @@ jest.mock("../../../platform/flags", () => ({ | |
})); | ||
|
||
describe("ExtensionLoginComponentService", () => { | ||
const baseUrl = "https://webvault.bitwarden.com"; | ||
let service: ExtensionLoginComponentService; | ||
let cryptoFunctionService: MockProxy<CryptoFunctionService>; | ||
let environmentService: MockProxy<EnvironmentService>; | ||
let passwordGenerationService: MockProxy<PasswordGenerationServiceAbstraction>; | ||
let platformUtilsService: MockProxy<BrowserPlatformUtilsService>; | ||
let ssoLoginService: MockProxy<SsoLoginServiceAbstraction>; | ||
let extensionAnonLayoutWrapperDataService: MockProxy<ExtensionAnonLayoutWrapperDataService>; | ||
let ssoUrlService: MockProxy<SsoUrlService>; | ||
beforeEach(() => { | ||
cryptoFunctionService = mock<CryptoFunctionService>(); | ||
environmentService = mock<EnvironmentService>(); | ||
passwordGenerationService = mock<PasswordGenerationServiceAbstraction>(); | ||
platformUtilsService = mock<BrowserPlatformUtilsService>(); | ||
ssoLoginService = mock<SsoLoginServiceAbstraction>(); | ||
ssoUrlService = mock<SsoUrlService>(); | ||
extensionAnonLayoutWrapperDataService = mock<ExtensionAnonLayoutWrapperDataService>(); | ||
environmentService.environment$ = new BehaviorSubject<Environment>({ | ||
getWebVaultUrl: () => baseUrl, | ||
} as Environment); | ||
platformUtilsService.getClientType.mockReturnValue(ClientType.Browser); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
|
@@ -44,6 +59,7 @@ describe("ExtensionLoginComponentService", () => { | |
platformUtilsService, | ||
ssoLoginService, | ||
extensionAnonLayoutWrapperDataService, | ||
ssoUrlService, | ||
), | ||
}, | ||
{ provide: DefaultLoginComponentService, useExisting: ExtensionLoginComponentService }, | ||
|
@@ -52,6 +68,11 @@ describe("ExtensionLoginComponentService", () => { | |
{ provide: PasswordGenerationServiceAbstraction, useValue: passwordGenerationService }, | ||
{ provide: PlatformUtilsService, useValue: platformUtilsService }, | ||
{ provide: SsoLoginServiceAbstraction, useValue: ssoLoginService }, | ||
{ | ||
provide: ExtensionAnonLayoutWrapperDataService, | ||
useValue: extensionAnonLayoutWrapperDataService, | ||
}, | ||
{ provide: SsoUrlService, useValue: ssoUrlService }, | ||
], | ||
}); | ||
service = TestBed.inject(ExtensionLoginComponentService); | ||
|
@@ -61,6 +82,26 @@ describe("ExtensionLoginComponentService", () => { | |
expect(service).toBeTruthy(); | ||
}); | ||
|
||
describe("redirectToSso", () => { | ||
it("launches SSO browser window", async () => { | ||
const email = "[email protected]"; | ||
const state = "testState"; | ||
const expectedState = "testState:clientId=browser"; | ||
const codeVerifier = "testCodeVerifier"; | ||
const codeChallenge = "testCodeChallenge"; | ||
|
||
passwordGenerationService.generatePassword.mockResolvedValueOnce(state); | ||
passwordGenerationService.generatePassword.mockResolvedValueOnce(codeVerifier); | ||
jest.spyOn(Utils, "fromBufferToUrlB64").mockReturnValue(codeChallenge); | ||
|
||
await service.redirectToSsoLogin(email); | ||
|
||
expect(ssoLoginService.setSsoState).toHaveBeenCalledWith(expectedState); | ||
expect(ssoLoginService.setCodeVerifier).toHaveBeenCalledWith(codeVerifier); | ||
expect(platformUtilsService.launchUri).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("showBackButton", () => { | ||
it("sets showBackButton in extensionAnonLayoutWrapperDataService", () => { | ||
service.showBackButton(true); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.