chore: pretty
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Yusuke Wada · committed by Yusuke Wada · parent c2cbc0a · Browse files · 1 file·+307 added−314 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+307 added−314 removed
- tests:+307 added−314 removed
Provenance
- Commit
9fd3cd3- Tree
d41c3a9- Author
Yusuke Wada <yusuke@cloudflare.com>- Committer
Yusuke Wada <yusuke@cloudflare.com>- Parent
c2cbc0a
1 file changed+307 added−314 removed
modified:runtime_tests/lambda-edge/index.test.ts+307 added-314 removed
27 unmodified lines28 const handler = handle(app)29 30 it('Should handle a GET request and return a 200 response (Lambda@Edge viewer request)', async () => {31 const event = {32- "Records": [32+ Records: [33 {34- "cf": {35- "config": {36- "distributionDomainName": "d111111abcdef8.cloudfront.net",37- "distributionId": "EDFDVBD6EXAMPLE",38- "eventType": "viewer-request",39- "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ=="34+ cf: {35+ config: {36+ distributionDomainName: 'd111111abcdef8.cloudfront.net',37+ distributionId: 'EDFDVBD6EXAMPLE',38+ eventType: 'viewer-request',39+ requestId: '4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==',40 },41- "request": {42- "clientIp": "203.0.113.178",43- "headers": {44- "host": [41+ request: {42+ clientIp: '203.0.113.178',43+ headers: {44+ host: [45 {46- "key": "Host",47- "value": "d111111abcdef8.cloudfront.net"48- }46+ key: 'Host',47+ value: 'd111111abcdef8.cloudfront.net',48+ },49 ],50- "user-agent": [50+ 'user-agent': [51 {52- "key": "User-Agent",53- "value": "curl/7.66.0"54- }52+ key: 'User-Agent',53+ value: 'curl/7.66.0',54+ },55 ],56- "accept": [56+ accept: [57 {58- "key": "accept",59- "value": "*/*"60- }61- ]58+ key: 'accept',59+ value: '*/*',60+ },61+ ],62 },63- "method": "GET",64- "querystring": "",65- "uri": "/"66- }67- }68- }69- ]63+ method: 'GET',64+ querystring: '',65+ uri: '/',66+ },67+ },68+ },69+ ],70 }71 const response = await handler(event)72- expect(response.status).toBe('200');73- expect(response.body).toBe('Hello Lambda!');74- expect(response.headers['content-type'][0].value).toMatch(/^text\/plain/);72+ expect(response.status).toBe('200')73+ expect(response.body).toBe('Hello Lambda!')74+ expect(response.headers['content-type'][0].value).toMatch(/^text\/plain/)75 })76 77 it('Should handle a GET request and return a 200 response (Lambda@Edge origin request)', async () => {78 const event = {79- "Records": [79+ Records: [80 {81- "cf": {82- "config": {83- "distributionDomainName": "d111111abcdef8.cloudfront.net",84- "distributionId": "EDFDVBD6EXAMPLE",85- "eventType": "origin-request",86- "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ=="81+ cf: {82+ config: {83+ distributionDomainName: 'd111111abcdef8.cloudfront.net',84+ distributionId: 'EDFDVBD6EXAMPLE',85+ eventType: 'origin-request',86+ requestId: '4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==',87 },88- "request": {89- "clientIp": "203.0.113.178",90- "headers": {91- "x-forwarded-for": [88+ request: {89+ clientIp: '203.0.113.178',90+ headers: {91+ 'x-forwarded-for': [92 {93- "key": "X-Forwarded-For",94- "value": "203.0.113.178"95- }93+ key: 'X-Forwarded-For',94+ value: '203.0.113.178',95+ },96 ],97- "user-agent": [97+ 'user-agent': [98 {99- "key": "User-Agent",100- "value": "Amazon CloudFront"101- }99+ key: 'User-Agent',100+ value: 'Amazon CloudFront',101+ },102 ],103- "via": [103+ via: [104 {105- "key": "Via",106- "value": "2.0 2afae0d44e2540f472c0635ab62c232b.cloudfront.net (CloudFront)"107- }105+ key: 'Via',106+ value: '2.0 2afae0d44e2540f472c0635ab62c232b.cloudfront.net (CloudFront)',107+ },108 ],109- "host": [109+ host: [110 {111- "key": "Host",112- "value": "example.org"113- }111+ key: 'Host',112+ value: 'example.org',113+ },114 ],115- "cache-control": [115+ 'cache-control': [116 {117- "key": "Cache-Control",118- "value": "no-cache"119- }120- ]117+ key: 'Cache-Control',118+ value: 'no-cache',119+ },120+ ],121 },122- "method": "GET",123- "origin": {124- "custom": {125- "customHeaders": {},126- "domainName": "example.org",127- "keepaliveTimeout": 5,128- "path": "",129- "port": 443,130- "protocol": "https",131- "readTimeout": 30,132- "sslProtocols": [133- "TLSv1",134- "TLSv1.1",135- "TLSv1.2"136- ]137- }122+ method: 'GET',123+ origin: {124+ custom: {125+ customHeaders: {},126+ domainName: 'example.org',127+ keepaliveTimeout: 5,128+ path: '',129+ port: 443,130+ protocol: 'https',131+ readTimeout: 30,132+ sslProtocols: ['TLSv1', 'TLSv1.1', 'TLSv1.2'],133+ },134 },139- "querystring": "",140- "uri": "/"141- }142- }143- }144- ]135+ querystring: '',136+ uri: '/',137+ },138+ },139+ },140+ ],141 }142 const response = await handler(event)147- expect(response.status).toBe('200');148- expect(response.body).toBe('Hello Lambda!');149- expect(response.headers['content-type'][0].value).toMatch(/^text\/plain/);143+ expect(response.status).toBe('200')144+ expect(response.body).toBe('Hello Lambda!')145+ expect(response.headers['content-type'][0].value).toMatch(/^text\/plain/)146 })147 148 it('Should handle a GET request and return a 200 response (Lambda@Edge viewer response)', async () => {149 const event = {154- "Records": [150+ Records: [151 {156- "cf": {157- "config": {158- "distributionDomainName": "d111111abcdef8.cloudfront.net",159- "distributionId": "EDFDVBD6EXAMPLE",160- "eventType": "viewer-response",161- "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ=="152+ cf: {153+ config: {154+ distributionDomainName: 'd111111abcdef8.cloudfront.net',155+ distributionId: 'EDFDVBD6EXAMPLE',156+ eventType: 'viewer-response',157+ requestId: '4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==',158 },163- "request": {164- "clientIp": "203.0.113.178",165- "headers": {166- "host": [159+ request: {160+ clientIp: '203.0.113.178',161+ headers: {162+ host: [163 {168- "key": "Host",169- "value": "d111111abcdef8.cloudfront.net"170- }164+ key: 'Host',165+ value: 'd111111abcdef8.cloudfront.net',166+ },167 ],172- "user-agent": [168+ 'user-agent': [169 {174- "key": "User-Agent",175- "value": "curl/7.66.0"176- }170+ key: 'User-Agent',171+ value: 'curl/7.66.0',172+ },173 ],178- "accept": [174+ accept: [175 {180- "key": "accept",181- "value": "*/*"182- }183- ]176+ key: 'accept',177+ value: '*/*',178+ },179+ ],180 },185- "method": "GET",186- "querystring": "",187- "uri": "/"181+ method: 'GET',182+ querystring: '',183+ uri: '/',184 },189- "response": {190- "headers": {191- "access-control-allow-credentials": [185+ response: {186+ headers: {187+ 'access-control-allow-credentials': [188 {193- "key": "Access-Control-Allow-Credentials",194- "value": "true"195- }189+ key: 'Access-Control-Allow-Credentials',190+ value: 'true',191+ },192 ],197- "access-control-allow-origin": [193+ 'access-control-allow-origin': [194 {199- "key": "Access-Control-Allow-Origin",200- "value": "*"201- }195+ key: 'Access-Control-Allow-Origin',196+ value: '*',197+ },198 ],203- "date": [199+ date: [200 {205- "key": "Date",206- "value": "Mon, 13 Jan 2020 20:14:56 GMT"207- }201+ key: 'Date',202+ value: 'Mon, 13 Jan 2020 20:14:56 GMT',203+ },204 ],209- "referrer-policy": [205+ 'referrer-policy': [206 {211- "key": "Referrer-Policy",212- "value": "no-referrer-when-downgrade"213- }207+ key: 'Referrer-Policy',208+ value: 'no-referrer-when-downgrade',209+ },210 ],215- "server": [211+ server: [212 {217- "key": "Server",218- "value": "ExampleCustomOriginServer"219- }213+ key: 'Server',214+ value: 'ExampleCustomOriginServer',215+ },216 ],221- "x-content-type-options": [217+ 'x-content-type-options': [218 {223- "key": "X-Content-Type-Options",224- "value": "nosniff"225- }219+ key: 'X-Content-Type-Options',220+ value: 'nosniff',221+ },222 ],227- "x-frame-options": [223+ 'x-frame-options': [224 {229- "key": "X-Frame-Options",230- "value": "DENY"231- }225+ key: 'X-Frame-Options',226+ value: 'DENY',227+ },228 ],233- "x-xss-protection": [229+ 'x-xss-protection': [230 {235- "key": "X-XSS-Protection",236- "value": "1; mode=block"237- }231+ key: 'X-XSS-Protection',232+ value: '1; mode=block',233+ },234 ],239- "age": [235+ age: [236 {241- "key": "Age",242- "value": "2402"243- }237+ key: 'Age',238+ value: '2402',239+ },240 ],245- "content-type": [241+ 'content-type': [242 {247- "key": "Content-Type",248- "value": "text/html; charset=utf-8"249- }243+ key: 'Content-Type',244+ value: 'text/html; charset=utf-8',245+ },246 ],251- "content-length": [247+ 'content-length': [248 {253- "key": "Content-Length",254- "value": "9593"255- }256- ]249+ key: 'Content-Length',250+ value: '9593',251+ },252+ ],253 },258- "status": "200", "statusDescription": "OK"259- }260- }261- }262- ]254+ status: '200',255+ statusDescription: 'OK',256+ },257+ },258+ },259+ ],260 }261 const response = await handler(event)265- expect(response.status).toBe('200');266- expect(response.body).toBe('Hello Lambda!');267- expect(response.headers['content-type'][0].value).toMatch(/^text\/plain/);262+ expect(response.status).toBe('200')263+ expect(response.body).toBe('Hello Lambda!')264+ expect(response.headers['content-type'][0].value).toMatch(/^text\/plain/)265 })266 267 it('Should handle a GET request and return a 200 response (Lambda@Edge origin response)', async () => {268 const event = {272- "Records": [269+ Records: [270 {274- "cf": {275- "config": {276- "distributionDomainName": "d111111abcdef8.cloudfront.net",277- "distributionId": "EDFDVBD6EXAMPLE",278- "eventType": "origin-response",279- "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ=="271+ cf: {272+ config: {273+ distributionDomainName: 'd111111abcdef8.cloudfront.net',274+ distributionId: 'EDFDVBD6EXAMPLE',275+ eventType: 'origin-response',276+ requestId: '4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==',277 },281- "request": {282- "clientIp": "203.0.113.178",283- "headers": {284- "x-forwarded-for": [278+ request: {279+ clientIp: '203.0.113.178',280+ headers: {281+ 'x-forwarded-for': [282 {286- "key": "X-Forwarded-For",287- "value": "203.0.113.178"288- }283+ key: 'X-Forwarded-For',284+ value: '203.0.113.178',285+ },286 ],290- "user-agent": [287+ 'user-agent': [288 {292- "key": "User-Agent",293- "value": "Amazon CloudFront"294- }289+ key: 'User-Agent',290+ value: 'Amazon CloudFront',291+ },292 ],296- "via": [293+ via: [294 {298- "key": "Via",299- "value": "2.0 8f22423015641505b8c857a37450d6c0.cloudfront.net (CloudFront)"300- }295+ key: 'Via',296+ value: '2.0 8f22423015641505b8c857a37450d6c0.cloudfront.net (CloudFront)',297+ },298 ],302- "host": [299+ host: [300 {304- "key": "Host",305- "value": "example.org"306- }301+ key: 'Host',302+ value: 'example.org',303+ },304 ],308- "cache-control": [305+ 'cache-control': [306 {310- "key": "Cache-Control",311- "value": "no-cache"312- }313- ]307+ key: 'Cache-Control',308+ value: 'no-cache',309+ },310+ ],311 },315- "method": "GET",316- "origin": {317- "custom": {318- "customHeaders": {},319- "domainName": "example.org",320- "keepaliveTimeout": 5,321- "path": "",322- "port": 443,323- "protocol": "https",324- "readTimeout": 30,325- "sslProtocols": [326- "TLSv1",327- "TLSv1.1",328- "TLSv1.2"329- ]330- }312+ method: 'GET',313+ origin: {314+ custom: {315+ customHeaders: {},316+ domainName: 'example.org',317+ keepaliveTimeout: 5,318+ path: '',319+ port: 443,320+ protocol: 'https',321+ readTimeout: 30,322+ sslProtocols: ['TLSv1', 'TLSv1.1', 'TLSv1.2'],323+ },324 },332- "querystring": "",333- "uri": "/"325+ querystring: '',326+ uri: '/',327 },335- "response": {336- "headers": {337- "access-control-allow-credentials": [328+ response: {329+ headers: {330+ 'access-control-allow-credentials': [331 {339- "key": "Access-Control-Allow-Credentials",340- "value": "true"341- }332+ key: 'Access-Control-Allow-Credentials',333+ value: 'true',334+ },335 ],343- "access-control-allow-origin": [336+ 'access-control-allow-origin': [337 {345- "key": "Access-Control-Allow-Origin",346- "value": "*"347- }338+ key: 'Access-Control-Allow-Origin',339+ value: '*',340+ },341 ],349- "date": [342+ date: [343 {351- "key": "Date",352- "value": "Mon, 13 Jan 2020 20:12:38 GMT"353- }344+ key: 'Date',345+ value: 'Mon, 13 Jan 2020 20:12:38 GMT',346+ },347 ],355- "referrer-policy": [348+ 'referrer-policy': [349 {357- "key": "Referrer-Policy",358- "value": "no-referrer-when-downgrade"359- }350+ key: 'Referrer-Policy',351+ value: 'no-referrer-when-downgrade',352+ },353 ],361- "server": [354+ server: [355 {363- "key": "Server",364- "value": "ExampleCustomOriginServer"365- }356+ key: 'Server',357+ value: 'ExampleCustomOriginServer',358+ },359 ],367- "x-content-type-options": [360+ 'x-content-type-options': [361 {369- "key": "X-Content-Type-Options",370- "value": "nosniff"371- }362+ key: 'X-Content-Type-Options',363+ value: 'nosniff',364+ },365 ],373- "x-frame-options": [366+ 'x-frame-options': [367 {375- "key": "X-Frame-Options",376- "value": "DENY"377- }368+ key: 'X-Frame-Options',369+ value: 'DENY',370+ },371 ],379- "x-xss-protection": [372+ 'x-xss-protection': [373 {381- "key": "X-XSS-Protection",382- "value": "1; mode=block"383- }374+ key: 'X-XSS-Protection',375+ value: '1; mode=block',376+ },377 ],385- "content-type": [378+ 'content-type': [379 {387- "key": "Content-Type",388- "value": "text/html; charset=utf-8"389- }380+ key: 'Content-Type',381+ value: 'text/html; charset=utf-8',382+ },383 ],391- "content-length": [384+ 'content-length': [385 {393- "key": "Content-Length",394- "value": "9593"395- }396- ]386+ key: 'Content-Length',387+ value: '9593',388+ },389+ ],390 },398- "status": "200",399- "statusDescription": "OK"400- }401- }402- }403- ]391+ status: '200',392+ statusDescription: 'OK',393+ },394+ },395+ },396+ ],397 }398 const response = await handler(event)406- expect(response.status).toBe('200');407- expect(response.body).toBe('Hello Lambda!');408- expect(response.headers['content-type'][0].value).toMatch(/^text\/plain/);399+ expect(response.status).toBe('200')400+ expect(response.body).toBe('Hello Lambda!')401+ expect(response.headers['content-type'][0].value).toMatch(/^text\/plain/)402 })403 404 it('Should handle a GET request and return a 200 response with binary', async () => {405 const event = {8 unmodified lines414 },415 request: {416 clientIp: '123.123.123.123',417 headers: {425- 'host': [418+ host: [419 {420 key: 'Host',421 value: 'example.com',422 },5 unmodified lines428 },429 },430 },431 ],439- };440- 441- const response = await handler(event);442- 443- expect(response.status).toBe('200');444- expect(response.body).toBe('RmFrZSBJbWFnZQ=='); // base64 encoded fake image445- expect(response.headers['content-type'][0].value).toMatch(/^image\/png/);446- });447- 432+ }433+434+ const response = await handler(event)435+436+ expect(response.status).toBe('200')437+ expect(response.body).toBe('RmFrZSBJbWFnZQ==') // base64 encoded fake image438+ expect(response.headers['content-type'][0].value).toMatch(/^image\/png/)439+ })440+441 it('Should handle a GET request and return a 404 response', async () => {442 const event = {443 Records: [444 {6 unmodified lines451 },452 request: {453 clientIp: '123.123.123.123',454 headers: {462- 'host': [455+ host: [456 {457 key: 'Host',458 value: 'example.com',459 },5 unmodified lines465 },466 },467 },468 ],476- };477- 478- const response = await handler(event);479- 480- expect(response.status).toBe('404');481- });469+ }470 471+ const response = await handler(event)472+473+ expect(response.status).toBe('404')474+ })475+476 it('Should handle a POST request and return a 200 response', async () => {484- const searchParam = new URLSearchParams();485- searchParam.append('message', 'Good Morning Lambda!');486- 477+ const searchParam = new URLSearchParams()478+ searchParam.append('message', 'Good Morning Lambda!')479+480 const event = {481 Records: [482 {483 cf: {5 unmodified lines489 },490 request: {491 clientIp: '123.123.123.123',492 headers: {500- 'host': [493+ host: [494 {495 key: 'Host',496 value: 'example.com',497 },17 unmodified lines515 },516 },517 },518 ],526- };519+ }520 528- const response = await handler(event);529- 530- expect(response.status).toBe('200');531- expect(response.body).toBe('Good Morning Lambda!');532- });521+ const response = await handler(event)522 523+ expect(response.status).toBe('200')524+ expect(response.body).toBe('Good Morning Lambda!')525+ })526+527 it('Should handle a request and return a 401 response with Basic auth', async () => {528 const event = {529 Records: [530 {6 unmodified lines537 },538 request: {539 clientIp: '123.123.123.123',540 headers: {548- 'host': [541+ host: [542 {543 key: 'Host',544 value: 'example.com',545 },11 unmodified lines557 },558 },559 },560 ],568- };569- 570- const response = await handler(event);571- 572- expect(response.status).toBe('401');573- });574- 561+ }562+563+ const response = await handler(event)564+565+ expect(response.status).toBe('401')566+ })567+568 it('Should handle a request and return a 401 response with Basic auth', async () => {569 const event = {570 Records: [571 {6 unmodified lines578 },579 request: {580 clientIp: '123.123.123.123',581 headers: {589- 'host': [582+ host: [583 {584 key: 'Host',585 value: 'example.com',586 },11 unmodified lines598 },599 },600 },601 ],609- };610- 611- const response = await handler(event);612- 613- expect(response.status).toBe('401');614- });615-});602+ }603+604+ const response = await handler(event)605+606+ expect(response.status).toBe('401')607+ })608+})