@@ -329,6 +329,96 @@ describe('HttpRoute', () => {
329
329
} ) ;
330
330
} ) ;
331
331
332
+ test ( 'can create route without an authorizer when api has defaultAuthorizer' , ( ) => {
333
+ const stack = new Stack ( ) ;
334
+
335
+ const authorizer = new DummyAuthorizer ( ) ;
336
+ const httpApi = new HttpApi ( stack , 'HttpApi' , {
337
+ defaultAuthorizer : authorizer ,
338
+ defaultAuthorizationScopes : [ 'read:books' ] ,
339
+ } ) ;
340
+
341
+ const route = new HttpRoute ( stack , 'HttpRoute' , {
342
+ httpApi,
343
+ integration : new DummyIntegration ( ) ,
344
+ routeKey : HttpRouteKey . with ( '/books' , HttpMethod . GET ) ,
345
+ } ) ;
346
+
347
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGatewayV2::Integration' , {
348
+ ApiId : stack . resolve ( httpApi . apiId ) ,
349
+ IntegrationType : 'HTTP_PROXY' ,
350
+ PayloadFormatVersion : '2.0' ,
351
+ IntegrationUri : 'some-uri' ,
352
+ } ) ;
353
+
354
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGatewayV2::Authorizer' , 1 ) ;
355
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGatewayV2::Route' , {
356
+ AuthorizerId : stack . resolve ( authorizer . bind ( { scope : stack , route : route } ) . authorizerId ) ,
357
+ AuthorizationType : 'JWT' ,
358
+ AuthorizationScopes : [ 'read:books' ] ,
359
+ } ) ;
360
+ } ) ;
361
+
362
+ test ( 'authorizationScopes can be applied to route without authorizer when api has defaultAuthorizer' , ( ) => {
363
+ const stack = new Stack ( ) ;
364
+
365
+ const authorizer = new DummyAuthorizer ( ) ;
366
+ const httpApi = new HttpApi ( stack , 'HttpApi' , {
367
+ defaultAuthorizer : authorizer ,
368
+ } ) ;
369
+
370
+ const route = new HttpRoute ( stack , 'HttpRoute' , {
371
+ httpApi,
372
+ integration : new DummyIntegration ( ) ,
373
+ routeKey : HttpRouteKey . with ( '/books' , HttpMethod . GET ) ,
374
+ authorizationScopes : [ 'read:books' ] ,
375
+ } ) ;
376
+
377
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGatewayV2::Integration' , {
378
+ ApiId : stack . resolve ( httpApi . apiId ) ,
379
+ IntegrationType : 'HTTP_PROXY' ,
380
+ PayloadFormatVersion : '2.0' ,
381
+ IntegrationUri : 'some-uri' ,
382
+ } ) ;
383
+
384
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGatewayV2::Authorizer' , 1 ) ;
385
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGatewayV2::Route' , {
386
+ AuthorizerId : stack . resolve ( authorizer . bind ( { scope : stack , route : route } ) . authorizerId ) ,
387
+ AuthorizationType : 'JWT' ,
388
+ AuthorizationScopes : [ 'read:books' ] ,
389
+ } ) ;
390
+ } ) ;
391
+
392
+ test ( 'defaultAuthorizationScopes can be applied to route' , ( ) => {
393
+ const stack = new Stack ( ) ;
394
+
395
+ const authorizer = new DummyAuthorizer ( ) ;
396
+ const httpApi = new HttpApi ( stack , 'HttpApi' , {
397
+ defaultAuthorizationScopes : [ 'read:books' ] ,
398
+ } ) ;
399
+
400
+ const route = new HttpRoute ( stack , 'HttpRoute' , {
401
+ httpApi,
402
+ integration : new DummyIntegration ( ) ,
403
+ routeKey : HttpRouteKey . with ( '/books' , HttpMethod . GET ) ,
404
+ authorizer,
405
+ } ) ;
406
+
407
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGatewayV2::Integration' , {
408
+ ApiId : stack . resolve ( httpApi . apiId ) ,
409
+ IntegrationType : 'HTTP_PROXY' ,
410
+ PayloadFormatVersion : '2.0' ,
411
+ IntegrationUri : 'some-uri' ,
412
+ } ) ;
413
+
414
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGatewayV2::Authorizer' , 1 ) ;
415
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGatewayV2::Route' , {
416
+ AuthorizerId : stack . resolve ( authorizer . bind ( { scope : stack , route : route } ) . authorizerId ) ,
417
+ AuthorizationType : 'JWT' ,
418
+ AuthorizationScopes : [ 'read:books' ] ,
419
+ } ) ;
420
+ } ) ;
421
+
332
422
test ( 'can attach additional scopes to a route with an authorizer attached' , ( ) => {
333
423
const stack = new Stack ( ) ;
334
424
const httpApi = new HttpApi ( stack , 'HttpApi' ) ;
0 commit comments