Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/plugins/auth/wrap-actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @prettier
*/
import { fromJS } from "immutable"

/**
* `authorize` and `logout` wrapped actions provide capacity
Expand All @@ -18,7 +19,8 @@ export const authorize = (oriAction, system) => (payload) => {

// create cookie
try {
const [{ schema, value }] = Object.values(payload)
const [{ schema: payloadSchema, value }] = Object.values(payload)
const schema = fromJS(payloadSchema)
const isApiKeyAuth = schema.get("type") === "apiKey"
const isInCookie = schema.get("in") === "cookie"
const isApiKeyInCookie = isApiKeyAuth && isInCookie
Expand Down
24 changes: 24 additions & 0 deletions test/unit/core/plugins/auth/wrap-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ describe("Cookie based apiKey persistence in document.cookie", () => {
)
})

it("should persist cookie in document.cookie if schema is a plain object", () => {
const system = {
getConfigs: () => ({
persistAuthorization: true,
}),
}
const payload = {
api_key: {
schema: {
type: "apiKey",
name: "apiKeyCookie",
in: "cookie",
},
value: "test",
},
}

authorize(jest.fn(), system)(payload)

expect(document.cookie).toEqual(
"apiKeyCookie=test; SameSite=None; Secure"
)
})

it("should delete cookie from document.cookie", () => {
const payload = fromJS({
api_key: {
Expand Down