Skip to content

Commit 34bd7da

Browse files
authored
fix(http-function-runtime-v3): fix undeclared variable and added improve tests for set-cookie (#534)
1 parent 2764c09 commit 34bd7da

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

__tests__/integration.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,16 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
395395
})
396396

397397
test('set-cookie', async () => {
398+
const now = new Date(2022, 7, 11, 3, 30, 30)
399+
const maxAge = 3000
400+
const expires = new Date(+now + maxAge)
401+
const expectedExpires = expires.toUTCString()
402+
403+
jest.useFakeTimers('modern')
404+
jest.setSystemTime(now)
405+
398406
router.get('/cookie', (req, res) => {
407+
res.cookie('Zoo', 'boo', { domain: 'mafoo.com', secure: true, httpOnly: true, sameSite: 'Strict', maxAge })
399408
res.cookie('Foo', 'bar', { domain: 'example.com', secure: true, httpOnly: true, sameSite: 'Strict' })
400409
res.cookie('Fizz', 'buzz')
401410
res.json({})
@@ -408,6 +417,7 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
408417
const response = await serverlessExpressInstance(event)
409418

410419
const expectedSetCookieHeaders = [
420+
`Zoo=boo; Max-Age=3; Domain=mafoo.com; Path=/; Expires=${expectedExpires}; HttpOnly; Secure; SameSite=Strict`,
411421
'Foo=bar; Domain=example.com; Path=/; HttpOnly; Secure; SameSite=Strict',
412422
'Fizz=buzz; Path=/'
413423
]
@@ -423,10 +433,23 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
423433
statusCode: 200
424434
})
425435

436+
jest.useRealTimers()
437+
426438
switch (eventSourceName) {
427439
case 'azureHttpFunctionV4':
428440
case 'azureHttpFunctionV3':
429441
expectedResponse.cookies = [
442+
{
443+
domain: 'mafoo.com',
444+
httpOnly: true,
445+
name: 'Zoo',
446+
path: '/',
447+
sameSite: 'Strict',
448+
secure: true,
449+
value: 'boo',
450+
maxAge: maxAge / 1000,
451+
expires
452+
},
430453
{
431454
domain: 'example.com',
432455
httpOnly: true,

src/event-sources/azure/http-function-runtime-v3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function getResponseToHttpFunction ({ statusCode, body, headers = {}, isBase64En
6464
}
6565

6666
if (parsedCookie['max-age']) {
67-
cookie.maxAge = parsedCookie['max-age']
67+
cookie.maxAge = +parsedCookie['max-age']
6868
}
6969

7070
if (parsedCookie.samesite) {
@@ -73,7 +73,7 @@ function getResponseToHttpFunction ({ statusCode, body, headers = {}, isBase64En
7373

7474
if (parsedCookie.expires && typeof parsedCookie.expires === 'string') {
7575
cookie.expires = new Date(parsedCookie.expires)
76-
} else if (parsedCookie.expires && typeof value === 'number') {
76+
} else if (parsedCookie.expires && typeof parsedCookie.expires === 'number') {
7777
cookie.expires = parsedCookie.expires
7878
}
7979

0 commit comments

Comments
 (0)