-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorsHeaders.spec.ts
More file actions
44 lines (41 loc) · 1.15 KB
/
corsHeaders.spec.ts
File metadata and controls
44 lines (41 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import assert from 'node:assert/strict'
import { describe, test as it } from 'node:test'
import { corsHeaders } from './corsHeaders.ts'
void describe('corsHeaders()', () => {
void it('should send the correct headers', () =>
assert.deepEqual(
corsHeaders({
headers: {
origin: 'https://hello.nrfcloud.com',
},
}),
{
'Access-Control-Allow-Headers':
'accept, authorization, content-type, if-match, origin',
'Access-Control-Expose-Headers':
'x-amzn-requestid, etag, apigw-requestid',
'Access-Control-Allow-Methods': 'PUT, DELETE, POST, GET, PATCH',
'Access-Control-Allow-Origin': 'https://hello.nrfcloud.com',
'Access-Control-Max-Age': 600,
Vary: 'Origin',
},
))
void it('should allow localhost', () =>
assert.deepEqual(
corsHeaders({
headers: {
origin: 'http://localhost:8080',
},
})['Access-Control-Allow-Origin'],
'http://localhost:8080',
))
void it('should not allow other domains', () =>
assert.deepEqual(
corsHeaders({
headers: {
origin: 'https://hello-nrfcloud-com.pages.dev',
},
})['Access-Control-Allow-Origin'],
'https://hello.nrfcloud.com',
))
})