-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(open-next): parse cookies when converting response to cloudfront (#…
…387) * fix(open-next): parse cookies when converting response to cloudfront * chore: add cloudfront event mapper unit tests * Create short-eels-compare.md --------- Co-authored-by: conico974 <[email protected]>
- Loading branch information
1 parent
a475e9d
commit 8cfb801
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"open-next": patch | ||
--- | ||
|
||
fix(open-next): parse cookies when converting response to cloudfront |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { CloudFrontRequestResult } from "aws-lambda"; | ||
|
||
import { convertTo } from "../../open-next/src/adapters/event-mapper"; | ||
|
||
describe("convertTo", () => { | ||
describe("CloudFront Result", () => { | ||
it("Should parse the headers", () => { | ||
const response = convertTo({ | ||
body: "", | ||
headers: { | ||
"content-type": "application/json", | ||
test: "test", | ||
}, | ||
isBase64Encoded: false, | ||
statusCode: 200, | ||
type: "cf", | ||
}) as CloudFrontRequestResult; | ||
|
||
expect(response?.headers).toStrictEqual({ | ||
"content-type": [ | ||
{ | ||
key: "content-type", | ||
value: "application/json", | ||
}, | ||
], | ||
test: [ | ||
{ | ||
key: "test", | ||
value: "test", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it("Should parse the headers with arrays", () => { | ||
const response = convertTo({ | ||
body: "", | ||
headers: { | ||
test: ["test1", "test2"], | ||
}, | ||
isBase64Encoded: false, | ||
statusCode: 200, | ||
type: "cf", | ||
}) as CloudFrontRequestResult; | ||
|
||
expect(response?.headers).toStrictEqual({ | ||
test: [ | ||
{ | ||
key: "test", | ||
value: "test1", | ||
}, | ||
{ | ||
key: "test", | ||
value: "test2", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it("Should parse the headers with cookies", () => { | ||
const response = convertTo({ | ||
body: "", | ||
headers: { | ||
"set-cookie": | ||
"test=1; Path=/; HttpOnly; Secure; SameSite=None, test=2; Path=/; HttpOnly; Secure; SameSite=None", | ||
}, | ||
isBase64Encoded: false, | ||
statusCode: 200, | ||
type: "cf", | ||
}) as CloudFrontRequestResult; | ||
|
||
expect(response?.headers).toStrictEqual({ | ||
"set-cookie": [ | ||
{ | ||
key: "set-cookie", | ||
value: "test=1; Path=/; HttpOnly; Secure; SameSite=None", | ||
}, | ||
{ | ||
key: "set-cookie", | ||
value: "test=2; Path=/; HttpOnly; Secure; SameSite=None", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it("Should parse the headers with cookies + expires", () => { | ||
const response = convertTo({ | ||
body: "", | ||
headers: { | ||
"set-cookie": | ||
"test=1; Path=/; Expires=Sun, 14 Apr 2024 22:19:07 GMT; HttpOnly; Secure; SameSite=None, test=2; Path=/; Expires=Sun, 14 Apr 2024 22:19:07 GMT; HttpOnly; Secure; SameSite=None", | ||
}, | ||
isBase64Encoded: false, | ||
statusCode: 200, | ||
type: "cf", | ||
}) as CloudFrontRequestResult; | ||
|
||
expect(response?.headers).toStrictEqual({ | ||
"set-cookie": [ | ||
{ | ||
key: "set-cookie", | ||
value: | ||
"test=1; Path=/; Expires=Sun, 14 Apr 2024 22:19:07 GMT; HttpOnly; Secure; SameSite=None", | ||
}, | ||
{ | ||
key: "set-cookie", | ||
value: | ||
"test=2; Path=/; Expires=Sun, 14 Apr 2024 22:19:07 GMT; HttpOnly; Secure; SameSite=None", | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
}); |