1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 07:13:32 +00:00

Auth/PM-7092 - Fix CLI login via API key not working due to TokenService changes (#8499)

* PM-7092 - Fix CLI login via API key not working (it apparently receives an undefined refresh token which was rejected by setTokens)

* PM-7092 - Fix base login strategy tests

* PM-7092 - per discucssion with jake, refactor setTokens to accept optional refresh token instead of exposing setRefreshToken as public.
This commit is contained in:
Jared Snider
2024-03-27 17:46:56 -04:00
committed by GitHub
parent d9bec7f984
commit 8cdc94076e
7 changed files with 26 additions and 25 deletions

View File

@@ -991,6 +991,7 @@ describe("TokenService", () => {
refreshToken,
VaultTimeoutAction.Lock,
null,
null,
);
// Assert
await expect(result).rejects.toThrow("User id not found. Cannot save refresh token.");
@@ -1854,7 +1855,7 @@ describe("TokenService", () => {
// Act
// Note: passing a valid access token so that a valid user id can be determined from the access token
await tokenService.setTokens(accessTokenJwt, refreshToken, vaultTimeoutAction, vaultTimeout, [
await tokenService.setTokens(accessTokenJwt, vaultTimeoutAction, vaultTimeout, refreshToken, [
clientId,
clientSecret,
]);
@@ -1901,7 +1902,7 @@ describe("TokenService", () => {
tokenService.setClientSecret = jest.fn();
// Act
await tokenService.setTokens(accessTokenJwt, refreshToken, vaultTimeoutAction, vaultTimeout);
await tokenService.setTokens(accessTokenJwt, vaultTimeoutAction, vaultTimeout, refreshToken);
// Assert
expect((tokenService as any)._setAccessToken).toHaveBeenCalledWith(
@@ -1933,9 +1934,9 @@ describe("TokenService", () => {
// Act
const result = tokenService.setTokens(
accessToken,
refreshToken,
vaultTimeoutAction,
vaultTimeout,
refreshToken,
);
// Assert
@@ -1952,32 +1953,27 @@ describe("TokenService", () => {
// Act
const result = tokenService.setTokens(
accessToken,
refreshToken,
vaultTimeoutAction,
vaultTimeout,
refreshToken,
);
// Assert
await expect(result).rejects.toThrow("Access token and refresh token are required.");
await expect(result).rejects.toThrow("Access token is required.");
});
it("should throw an error if the refresh token is missing", async () => {
it("should not throw an error if the refresh token is missing and it should just not set it", async () => {
// Arrange
const accessToken = "accessToken";
const refreshToken: string = null;
const vaultTimeoutAction = VaultTimeoutAction.Lock;
const vaultTimeout = 30;
(tokenService as any).setRefreshToken = jest.fn();
// Act
const result = tokenService.setTokens(
accessToken,
refreshToken,
vaultTimeoutAction,
vaultTimeout,
);
await tokenService.setTokens(accessTokenJwt, vaultTimeoutAction, vaultTimeout, refreshToken);
// Assert
await expect(result).rejects.toThrow("Access token and refresh token are required.");
expect((tokenService as any).setRefreshToken).not.toHaveBeenCalled();
});
});