OIDC: retrieve refreshToken
from storage (#11250)
* test persistCredentials without a pickle key * test setLoggedIn with pickle key * lint * type error * extract token persisting code into function, persist refresh token * store has_refresh_token too * pass refreshToken from oidcAuthGrant into credentials * rest restore session with pickle key * retreive stored refresh token and add to credentials * extract token decryption into function * remove TODO * comments * prettier * comment pedantry * fix code smell - nullish coalesce instead of || * more comments
This commit is contained in:
parent
fa377cbade
commit
ef5a93b702
2 changed files with 155 additions and 28 deletions
|
@ -161,6 +161,8 @@ describe("Lifecycle", () => {
|
|||
accessToken,
|
||||
};
|
||||
|
||||
const refreshToken = "test-refresh-token";
|
||||
|
||||
const encryptedTokenShapedObject = {
|
||||
ciphertext: expect.any(String),
|
||||
iv: expect.any(String),
|
||||
|
@ -285,6 +287,45 @@ describe("Lifecycle", () => {
|
|||
|
||||
expect(MatrixClientPeg.start).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("with a refresh token", () => {
|
||||
beforeEach(() => {
|
||||
initLocalStorageMock({
|
||||
...localStorageSession,
|
||||
mx_refresh_token: refreshToken,
|
||||
});
|
||||
initIdbMock(idbStorageSession);
|
||||
});
|
||||
|
||||
it("should persist credentials", async () => {
|
||||
expect(await restoreFromLocalStorage()).toEqual(true);
|
||||
|
||||
// refresh token from storage is re-persisted
|
||||
expect(localStorage.setItem).toHaveBeenCalledWith("mx_has_refresh_token", "true");
|
||||
expect(StorageManager.idbSave).toHaveBeenCalledWith(
|
||||
"account",
|
||||
"mx_refresh_token",
|
||||
refreshToken,
|
||||
);
|
||||
});
|
||||
|
||||
it("should create new matrix client with credentials", async () => {
|
||||
expect(await restoreFromLocalStorage()).toEqual(true);
|
||||
|
||||
expect(MatrixClientPeg.replaceUsingCreds).toHaveBeenCalledWith({
|
||||
userId,
|
||||
accessToken,
|
||||
// refreshToken included in credentials
|
||||
refreshToken,
|
||||
homeserverUrl,
|
||||
identityServerUrl,
|
||||
deviceId,
|
||||
freshLogin: false,
|
||||
guest: false,
|
||||
pickleKey: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("with a pickle key", () => {
|
||||
|
@ -344,6 +385,47 @@ describe("Lifecycle", () => {
|
|||
pickleKey: expect.any(String),
|
||||
});
|
||||
});
|
||||
|
||||
describe("with a refresh token", () => {
|
||||
beforeEach(async () => {
|
||||
initLocalStorageMock({});
|
||||
initIdbMock({});
|
||||
// setup storage with a session with encrypted token
|
||||
await setLoggedIn({
|
||||
...credentials,
|
||||
refreshToken,
|
||||
});
|
||||
});
|
||||
|
||||
it("should persist credentials", async () => {
|
||||
expect(await restoreFromLocalStorage()).toEqual(true);
|
||||
|
||||
// refresh token from storage is re-persisted
|
||||
expect(localStorage.setItem).toHaveBeenCalledWith("mx_has_refresh_token", "true");
|
||||
expect(StorageManager.idbSave).toHaveBeenCalledWith(
|
||||
"account",
|
||||
"mx_refresh_token",
|
||||
encryptedTokenShapedObject,
|
||||
);
|
||||
});
|
||||
|
||||
it("should create new matrix client with credentials", async () => {
|
||||
expect(await restoreFromLocalStorage()).toEqual(true);
|
||||
|
||||
expect(MatrixClientPeg.replaceUsingCreds).toHaveBeenCalledWith({
|
||||
userId,
|
||||
accessToken,
|
||||
// refreshToken included in credentials
|
||||
refreshToken,
|
||||
homeserverUrl,
|
||||
identityServerUrl,
|
||||
deviceId,
|
||||
freshLogin: false,
|
||||
guest: false,
|
||||
pickleKey: expect.any(String),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should show a toast if the matrix server version is unsupported", async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue