feat(auth): persist cookie based apiKey in document.cookie (#8689)

Refs #8683
This commit is contained in:
Vladimír Gorej
2023-05-22 14:46:30 +02:00
committed by GitHub
parent 26709c3ea6
commit 7ac9a8f070
10 changed files with 269 additions and 64 deletions

View File

@@ -1,5 +1,4 @@
import { downloadConfig } from "corePlugins/configs/spec-actions"
import { loaded } from "corePlugins/configs/actions"
describe("configs plugin - actions", () => {
@@ -23,43 +22,4 @@ describe("configs plugin - actions", () => {
expect(fetchSpy).toHaveBeenCalledWith(req)
})
})
describe("loaded hook", () => {
describe("authorization data restoration", () => {
beforeEach(() => {
localStorage.clear()
})
it("retrieve `authorized` value from `localStorage`", () => {
const system = {
getConfigs: () => ({
persistAuthorization: true
}),
authActions: {
}
}
jest.spyOn(Object.getPrototypeOf(window.localStorage), "getItem")
loaded()(system)
expect(localStorage.getItem).toHaveBeenCalled()
expect(localStorage.getItem).toHaveBeenCalledWith("authorized")
})
it("restore authorization data when a value exists", () => {
const system = {
getConfigs: () => ({
persistAuthorization: true
}),
authActions: {
restoreAuthorization: jest.fn(() => {})
}
}
const mockData = {"api_key": {}}
localStorage.setItem("authorized", JSON.stringify(mockData))
loaded()(system)
expect(system.authActions.restoreAuthorization).toHaveBeenCalled()
expect(system.authActions.restoreAuthorization).toHaveBeenCalledWith({
authorized: mockData
})
})
})
})
})