feat(auth): persist cookie based apiKey in document.cookie (#8689)
Refs #8683
This commit is contained in:
@@ -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
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user