Skip to content

Commit fadb1dc

Browse files
committed
add unit tests and update other instance of same usage on line 534
1 parent 2a74cad commit fadb1dc

File tree

6 files changed

+629
-1
lines changed

6 files changed

+629
-1
lines changed

samtranslator/swagger/swagger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def set_path_default_authorizer(
531531
if add_default_auth_to_preflight or normalized_method_name != "options":
532532
normalized_method_name = self._normalize_method_name(method_name)
533533
# It is possible that the method could have two definitions in a Fn::If block.
534-
for method_definition in self.get_method_contents(self.get_path(path)[normalized_method_name]):
534+
for method_definition in self.get_method_contents(method):
535535

536536
# If no integration given, then we don't need to process this definition (could be AWS::NoValue)
537537
if not isinstance(method_definition, dict):
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Resources:
2+
HttpApiFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/todo_list.zip
6+
Handler: index.restapi
7+
Runtime: python3.7
8+
Events:
9+
SimpleCase:
10+
Type: HttpApi
11+
Properties:
12+
ApiId: !Ref MyApi
13+
BasePath:
14+
Type: HttpApi
15+
Properties:
16+
ApiId: !Ref MyApi
17+
Path: /
18+
Method: get
19+
20+
MyApi:
21+
Type: AWS::Serverless::Api
22+
Properties:
23+
StageName:
24+
Ref: Stage
25+
Auth:
26+
DefaultAuthorizer: "LambdaAuthorizer"
27+
Authorizers:
28+
LambdaAuthorizer:
29+
FunctionPayloadType: "REQUEST"
30+
Identity:
31+
Headers:
32+
- "Authorization"
33+
DefinitionBody:
34+
openapi: '3.0'
35+
info:
36+
title: !Sub ${AWS::StackName}-Api
37+
paths:
38+
/:
39+
any:
40+
x-amazon-apigateway-integration:
41+
httpMethod: ANY
42+
type: http_proxy
43+
uri: https://www.alphavantage.co/
44+
payloadFormatVersion: '1.0'
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{
2+
"Resources": {
3+
"MyApi": {
4+
"Type": "AWS::ApiGateway::RestApi",
5+
"Properties": {
6+
"Body": {
7+
"info": {
8+
"title": {
9+
"Fn::Sub": "${AWS::StackName}-Api"
10+
}
11+
},
12+
"paths": {
13+
"$default": {
14+
"x-amazon-apigateway-any-method": {
15+
"x-amazon-apigateway-integration": {
16+
"httpMethod": "POST",
17+
"type": "aws_proxy",
18+
"uri": {
19+
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
20+
},
21+
"payloadFormatVersion": "2.0"
22+
},
23+
"isDefaultRoute": true,
24+
"security": [
25+
{
26+
"LambdaAuthorizer": []
27+
}
28+
],
29+
"responses": {}
30+
}
31+
},
32+
"/": {
33+
"any": {
34+
"x-amazon-apigateway-integration": {
35+
"httpMethod": "ANY",
36+
"type": "http_proxy",
37+
"uri": "https://www.alphavantage.co/",
38+
"payloadFormatVersion": "1.0"
39+
},
40+
"security": [
41+
{
42+
"LambdaAuthorizer": []
43+
}
44+
]
45+
},
46+
"get": {
47+
"x-amazon-apigateway-integration": {
48+
"httpMethod": "POST",
49+
"type": "aws_proxy",
50+
"uri": {
51+
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
52+
},
53+
"payloadFormatVersion": "2.0"
54+
},
55+
"security": [
56+
{
57+
"LambdaAuthorizer": []
58+
}
59+
],
60+
"responses": {}
61+
}
62+
}
63+
},
64+
"openapi": "3.0",
65+
"components": {
66+
"securitySchemes": {
67+
"LambdaAuthorizer": {
68+
"in": "header",
69+
"type": "apiKey",
70+
"name": "Unused",
71+
"x-amazon-apigateway-authorizer": {
72+
"type": "request",
73+
"identitySource": "method.request.header.Authorization",
74+
"authorizerUri": {
75+
"Fn::Sub": [
76+
"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations",
77+
{
78+
"__FunctionArn__": null
79+
}
80+
]
81+
}
82+
},
83+
"x-amazon-apigateway-authtype": "custom"
84+
}
85+
}
86+
}
87+
}
88+
}
89+
},
90+
"HttpApiFunction": {
91+
"Type": "AWS::Lambda::Function",
92+
"Properties": {
93+
"Handler": "index.restapi",
94+
"Code": {
95+
"S3Bucket": "sam-demo-bucket",
96+
"S3Key": "todo_list.zip"
97+
},
98+
"Role": {
99+
"Fn::GetAtt": [
100+
"HttpApiFunctionRole",
101+
"Arn"
102+
]
103+
},
104+
"Runtime": "python3.7",
105+
"Tags": [
106+
{
107+
"Value": "SAM",
108+
"Key": "lambda:createdBy"
109+
}
110+
]
111+
}
112+
},
113+
"HttpApiFunctionSimpleCasePermission": {
114+
"Type": "AWS::Lambda::Permission",
115+
"Properties": {
116+
"Action": "lambda:InvokeFunction",
117+
"Principal": "apigateway.amazonaws.com",
118+
"FunctionName": {
119+
"Ref": "HttpApiFunction"
120+
},
121+
"SourceArn": {
122+
"Fn::Sub": [
123+
"arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*",
124+
{
125+
"__Stage__": "*",
126+
"__ApiId__": {
127+
"Ref": "MyApi"
128+
}
129+
}
130+
]
131+
}
132+
}
133+
},
134+
"HttpApiFunctionRole": {
135+
"Type": "AWS::IAM::Role",
136+
"Properties": {
137+
"AssumeRolePolicyDocument": {
138+
"Version": "2012-10-17",
139+
"Statement": [
140+
{
141+
"Action": [
142+
"sts:AssumeRole"
143+
],
144+
"Effect": "Allow",
145+
"Principal": {
146+
"Service": [
147+
"lambda.amazonaws.com"
148+
]
149+
}
150+
}
151+
]
152+
},
153+
"ManagedPolicyArns": [
154+
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
155+
],
156+
"Tags": [
157+
{
158+
"Value": "SAM",
159+
"Key": "lambda:createdBy"
160+
}
161+
]
162+
}
163+
},
164+
"MyApiStage": {
165+
"Type": "AWS::ApiGateway::Stage",
166+
"Properties": {
167+
"DeploymentId": {
168+
"Ref": "MyApiDeployment69a80e7382"
169+
},
170+
"RestApiId": {
171+
"Ref": "MyApi"
172+
},
173+
"StageName": {
174+
"Ref": "Stage"
175+
}
176+
}
177+
},
178+
"MyApiDeployment69a80e7382": {
179+
"Type": "AWS::ApiGateway::Deployment",
180+
"Properties": {
181+
"RestApiId": {
182+
"Ref": "MyApi"
183+
},
184+
"Description": "RestApi deployment id: 69a80e738222706cff079ab8d7f348c0d89eddab",
185+
"StageName": "Stage"
186+
}
187+
}
188+
}
189+
}

0 commit comments

Comments
 (0)