@@ -681,4 +681,246 @@ describe('#compileMethodsToS3()', () => {
681
681
'method.request.path.key' : true
682
682
} )
683
683
} )
684
+
685
+ it ( 'should create corresponding resources when s3 GetObject proxy is given with path override' , ( ) => {
686
+ serverlessApigatewayServiceProxy . validated = {
687
+ events : [
688
+ {
689
+ serviceName : 's3' ,
690
+ http : {
691
+ path : '/{folder}/{item}' ,
692
+ method : 'get' ,
693
+ bucket : {
694
+ Ref : 'MyBucket'
695
+ } ,
696
+ action : 'GetObject' ,
697
+ key : {
698
+ pathParam : 'item'
699
+ } ,
700
+ pathOverride : '{folder}/{item}.xml' ,
701
+ auth : { authorizationType : 'NONE' } ,
702
+ requestParameters : {
703
+ 'integration.request.path.folder' : 'method.request.path.folder' ,
704
+ 'integration.request.path.item' : 'method.request.path.item'
705
+ }
706
+ }
707
+ }
708
+ ]
709
+ }
710
+ serverlessApigatewayServiceProxy . apiGatewayRestApiLogicalId = 'ApiGatewayRestApi'
711
+ serverlessApigatewayServiceProxy . apiGatewayResources = {
712
+ '/{folder}/{item}' : {
713
+ name : 'po' ,
714
+ resourceLogicalId : 'ApiGatewayPathOverrideS3'
715
+ }
716
+ }
717
+
718
+ serverlessApigatewayServiceProxy . compileMethodsToS3 ( )
719
+ expect ( serverless . service . provider . compiledCloudFormationTemplate . Resources ) . to . deep . equal ( {
720
+ ApiGatewayMethodpoGet : {
721
+ Type : 'AWS::ApiGateway::Method' ,
722
+ Properties : {
723
+ HttpMethod : 'GET' ,
724
+ RequestParameters : {
725
+ 'method.request.path.folder' : true ,
726
+ 'method.request.path.item' : true
727
+ } ,
728
+ AuthorizationType : 'NONE' ,
729
+ AuthorizationScopes : undefined ,
730
+ AuthorizerId : undefined ,
731
+ ApiKeyRequired : false ,
732
+ ResourceId : { Ref : 'ApiGatewayPathOverrideS3' } ,
733
+ RestApiId : { Ref : 'ApiGatewayRestApi' } ,
734
+ Integration : {
735
+ Type : 'AWS' ,
736
+ IntegrationHttpMethod : 'GET' ,
737
+ Credentials : { 'Fn::GetAtt' : [ 'ApigatewayToS3Role' , 'Arn' ] } ,
738
+ Uri : {
739
+ 'Fn::Sub' : [
740
+ 'arn:aws:apigateway:${AWS::Region}:s3:path/{bucket}/{folder}/{item}.xml' ,
741
+ { }
742
+ ]
743
+ } ,
744
+ PassthroughBehavior : 'WHEN_NO_MATCH' ,
745
+ RequestParameters : {
746
+ 'integration.request.path.bucket' : {
747
+ 'Fn::Sub' : [
748
+ "'${bucket}'" ,
749
+ {
750
+ bucket : {
751
+ Ref : 'MyBucket'
752
+ }
753
+ }
754
+ ]
755
+ } ,
756
+ 'integration.request.path.object' : 'method.request.path.item' ,
757
+ 'integration.request.path.folder' : 'method.request.path.folder' ,
758
+ 'integration.request.path.item' : 'method.request.path.item'
759
+ } ,
760
+ IntegrationResponses : [
761
+ {
762
+ StatusCode : 400 ,
763
+ SelectionPattern : '4\\d{2}' ,
764
+ ResponseParameters : { } ,
765
+ ResponseTemplates : { }
766
+ } ,
767
+ {
768
+ StatusCode : 500 ,
769
+ SelectionPattern : '5\\d{2}' ,
770
+ ResponseParameters : { } ,
771
+ ResponseTemplates : { }
772
+ } ,
773
+ {
774
+ StatusCode : 200 ,
775
+ SelectionPattern : '2\\d{2}' ,
776
+ ResponseParameters : {
777
+ 'method.response.header.Content-Type' : 'integration.response.header.Content-Type' ,
778
+ 'method.response.header.content-type' : 'integration.response.header.content-type'
779
+ } ,
780
+ ResponseTemplates : { }
781
+ }
782
+ ]
783
+ } ,
784
+ MethodResponses : [
785
+ {
786
+ ResponseParameters : {
787
+ 'method.response.header.Content-Type' : true ,
788
+ 'method.response.header.content-type' : true
789
+ } ,
790
+ ResponseModels : { } ,
791
+ StatusCode : 200
792
+ } ,
793
+ {
794
+ ResponseParameters : { } ,
795
+ ResponseModels : { } ,
796
+ StatusCode : 400
797
+ } ,
798
+ {
799
+ ResponseParameters : { } ,
800
+ ResponseModels : { } ,
801
+ StatusCode : 500
802
+ }
803
+ ]
804
+ }
805
+ }
806
+ } )
807
+ } )
808
+
809
+ it ( 'should create corresponding resources when s3 GetObject proxy is given with a greedy path override' , ( ) => {
810
+ serverlessApigatewayServiceProxy . validated = {
811
+ events : [
812
+ {
813
+ serviceName : 's3' ,
814
+ http : {
815
+ path : '/{myPath+}' ,
816
+ method : 'get' ,
817
+ bucket : {
818
+ Ref : 'MyBucket'
819
+ } ,
820
+ action : 'GetObject' ,
821
+ key : {
822
+ pathParam : 'myPath'
823
+ } ,
824
+ pathOverride : '{myPath}.xml' ,
825
+ auth : { authorizationType : 'NONE' } ,
826
+ requestParameters : {
827
+ 'integration.request.path.myPath' : 'method.request.path.myPath'
828
+ }
829
+ }
830
+ }
831
+ ]
832
+ }
833
+ serverlessApigatewayServiceProxy . apiGatewayRestApiLogicalId = 'ApiGatewayRestApi'
834
+ serverlessApigatewayServiceProxy . apiGatewayResources = {
835
+ '/{myPath+}' : {
836
+ name : 'greedyPath' ,
837
+ resourceLogicalId : 'ApiGatewayPathOverrideS3'
838
+ }
839
+ }
840
+
841
+ serverlessApigatewayServiceProxy . compileMethodsToS3 ( )
842
+ expect ( serverless . service . provider . compiledCloudFormationTemplate . Resources ) . to . deep . equal ( {
843
+ ApiGatewayMethodgreedyPathGet : {
844
+ Type : 'AWS::ApiGateway::Method' ,
845
+ Properties : {
846
+ HttpMethod : 'GET' ,
847
+ RequestParameters : {
848
+ 'method.request.path.myPath' : true
849
+ } ,
850
+ AuthorizationType : 'NONE' ,
851
+ AuthorizationScopes : undefined ,
852
+ AuthorizerId : undefined ,
853
+ ApiKeyRequired : false ,
854
+ ResourceId : { Ref : 'ApiGatewayPathOverrideS3' } ,
855
+ RestApiId : { Ref : 'ApiGatewayRestApi' } ,
856
+ Integration : {
857
+ Type : 'AWS' ,
858
+ IntegrationHttpMethod : 'GET' ,
859
+ Credentials : { 'Fn::GetAtt' : [ 'ApigatewayToS3Role' , 'Arn' ] } ,
860
+ Uri : {
861
+ 'Fn::Sub' : [ 'arn:aws:apigateway:${AWS::Region}:s3:path/{bucket}/{myPath}.xml' , { } ]
862
+ } ,
863
+ PassthroughBehavior : 'WHEN_NO_MATCH' ,
864
+ RequestParameters : {
865
+ 'integration.request.path.bucket' : {
866
+ 'Fn::Sub' : [
867
+ "'${bucket}'" ,
868
+ {
869
+ bucket : {
870
+ Ref : 'MyBucket'
871
+ }
872
+ }
873
+ ]
874
+ } ,
875
+ 'integration.request.path.object' : 'method.request.path.myPath' ,
876
+ 'integration.request.path.myPath' : 'method.request.path.myPath'
877
+ } ,
878
+ IntegrationResponses : [
879
+ {
880
+ StatusCode : 400 ,
881
+ SelectionPattern : '4\\d{2}' ,
882
+ ResponseParameters : { } ,
883
+ ResponseTemplates : { }
884
+ } ,
885
+ {
886
+ StatusCode : 500 ,
887
+ SelectionPattern : '5\\d{2}' ,
888
+ ResponseParameters : { } ,
889
+ ResponseTemplates : { }
890
+ } ,
891
+ {
892
+ StatusCode : 200 ,
893
+ SelectionPattern : '2\\d{2}' ,
894
+ ResponseParameters : {
895
+ 'method.response.header.Content-Type' : 'integration.response.header.Content-Type' ,
896
+ 'method.response.header.content-type' : 'integration.response.header.content-type'
897
+ } ,
898
+ ResponseTemplates : { }
899
+ }
900
+ ]
901
+ } ,
902
+ MethodResponses : [
903
+ {
904
+ ResponseParameters : {
905
+ 'method.response.header.Content-Type' : true ,
906
+ 'method.response.header.content-type' : true
907
+ } ,
908
+ ResponseModels : { } ,
909
+ StatusCode : 200
910
+ } ,
911
+ {
912
+ ResponseParameters : { } ,
913
+ ResponseModels : { } ,
914
+ StatusCode : 400
915
+ } ,
916
+ {
917
+ ResponseParameters : { } ,
918
+ ResponseModels : { } ,
919
+ StatusCode : 500
920
+ }
921
+ ]
922
+ }
923
+ }
924
+ } )
925
+ } )
684
926
} )
0 commit comments