mirror of
https://github.com/bitwarden/browser
synced 2026-02-20 19:34:03 +00:00
[PM-27086] Changing direction: remove new methods
This commit is contained in:
@@ -2,9 +2,7 @@ import { MockProxy, mock } from "jest-mock-extended";
|
||||
import { BehaviorSubject, of } from "rxjs";
|
||||
|
||||
import { OrganizationUserApiService } from "@bitwarden/admin-console/common";
|
||||
import { DefaultSetInitialPasswordService } from "@bitwarden/angular/auth/password-management/set-initial-password/default-set-initial-password.service.implementation";
|
||||
import {
|
||||
SetInitialPasswordCredentials,
|
||||
SetInitialPasswordCredentialsOld,
|
||||
SetInitialPasswordService,
|
||||
SetInitialPasswordUserType,
|
||||
@@ -22,7 +20,6 @@ import { AccountCryptographicStateService } from "@bitwarden/common/key-manageme
|
||||
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
|
||||
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 { MasterPasswordSalt } from "@bitwarden/common/key-management/master-password/types/master-password.types";
|
||||
import { KeysRequest } from "@bitwarden/common/models/request/keys.request";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||
@@ -214,58 +211,4 @@ describe("WebSetInitialPasswordService", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("setInitialPassword()", () => {
|
||||
let credentials: SetInitialPasswordCredentials;
|
||||
let userType: SetInitialPasswordUserType;
|
||||
let userId: UserId;
|
||||
|
||||
beforeEach(() => {
|
||||
credentials = {
|
||||
newPassword: "newPassword",
|
||||
newPasswordHint: "newPasswordHint",
|
||||
kdfConfig: DEFAULT_KDF_CONFIG,
|
||||
salt: "salt" as MasterPasswordSalt,
|
||||
orgSsoIdentifier: "orgSsoIdentifier",
|
||||
orgId: "orgId",
|
||||
resetPasswordAutoEnroll: false,
|
||||
};
|
||||
userId = "userId" as UserId;
|
||||
userType = SetInitialPasswordUserType.JIT_PROVISIONED_MP_ORG_USER;
|
||||
});
|
||||
|
||||
describe("given the initial password was successfully set", () => {
|
||||
it("should call additional state clearing methods", async () => {
|
||||
// Arrange
|
||||
jest
|
||||
.spyOn(DefaultSetInitialPasswordService.prototype, "setInitialPassword")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
// Act
|
||||
await sut.setInitialPassword(credentials, userType, userId);
|
||||
|
||||
// Assert
|
||||
expect(routerService.getAndClearLoginRedirectUrl).toHaveBeenCalledTimes(1);
|
||||
expect(organizationInviteService.clearOrganizationInvitation).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("given the initial password was NOT successfully set (due to parent method failure)", () => {
|
||||
it("should NOT call any further methods", async () => {
|
||||
// Arrange
|
||||
const parentError = new Error("Parent setInitialPassword failed");
|
||||
jest
|
||||
.spyOn(DefaultSetInitialPasswordService.prototype, "setInitialPassword")
|
||||
.mockRejectedValue(parentError);
|
||||
|
||||
// Act
|
||||
const promise = sut.setInitialPassword(credentials, userType, userId);
|
||||
|
||||
// Assert
|
||||
await expect(promise).rejects.toThrow(parentError);
|
||||
expect(routerService.getAndClearLoginRedirectUrl).not.toHaveBeenCalled();
|
||||
expect(organizationInviteService.clearOrganizationInvitation).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { OrganizationUserApiService } from "@bitwarden/admin-console/common";
|
||||
import { DefaultSetInitialPasswordService } from "@bitwarden/angular/auth/password-management/set-initial-password/default-set-initial-password.service.implementation";
|
||||
import {
|
||||
SetInitialPasswordCredentials,
|
||||
SetInitialPasswordCredentialsOld,
|
||||
SetInitialPasswordService,
|
||||
SetInitialPasswordUserType,
|
||||
@@ -87,36 +86,4 @@ export class WebSetInitialPasswordService
|
||||
await this.routerService.getAndClearLoginRedirectUrl();
|
||||
await this.organizationInviteService.clearOrganizationInvitation();
|
||||
}
|
||||
|
||||
override async setInitialPassword(
|
||||
credentials: SetInitialPasswordCredentials,
|
||||
userType: SetInitialPasswordUserType,
|
||||
userId: UserId,
|
||||
) {
|
||||
await super.setInitialPassword(credentials, userType, userId);
|
||||
|
||||
/**
|
||||
* TODO: Investigate refactoring the following logic in https://bitwarden.atlassian.net/browse/PM-22615
|
||||
* ---
|
||||
* When a user has been invited to an org, they can be accepted into the org in two different ways:
|
||||
*
|
||||
* 1) By clicking the email invite link, which triggers the normal AcceptOrganizationComponent flow
|
||||
* a. This flow sets an org invite in state
|
||||
* b. However, if the user does not already have an account AND the org has SSO enabled AND the require
|
||||
* SSO policy enabled, the AcceptOrganizationComponent will send the user to /sso to accelerate
|
||||
* the user through the SSO JIT provisioning process (see #2 below)
|
||||
*
|
||||
* 2) By logging in via SSO, which triggers the JIT provisioning process
|
||||
* a. This flow does NOT (itself) set an org invite in state
|
||||
* b. The set initial password process on the server accepts the user into the org after successfully
|
||||
* setting the password (see server - SetInitialMasterPasswordCommand.cs)
|
||||
*
|
||||
* If a user clicks the email link but gets accelerated through the SSO JIT process (see 1b),
|
||||
* the SSO JIT process will accept the user into the org upon setting their initial password (see 2b),
|
||||
* at which point we must remember to clear the deep linked URL used for accepting the org invite, as well
|
||||
* as clear the org invite itself that was originally set in state by the AcceptOrganizationComponent.
|
||||
*/
|
||||
await this.routerService.getAndClearLoginRedirectUrl();
|
||||
await this.organizationInviteService.clearOrganizationInvitation();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user