Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bb7a72a
chore: don't install integration tests (#1964)
yan12125 Mar 17, 2021
b35be10
Remove unnecessary use of comprehension (#1805)
HarshCasper Mar 17, 2021
f6914fa
fix: Grammatical error in README.md (#1965)
Pranav016 Mar 18, 2021
fa2e1f5
fix: Added SAR Support Check (#1972)
CoshUS Mar 29, 2021
006c184
update pyyaml version to get the security update (#1974)
moelasmar Mar 30, 2021
ffd3b11
fix the request parameter parsing, the value can contain dots (#1975)
moelasmar Apr 7, 2021
193c7b7
Documentation: fix incorrect header (#1979)
bfreiberg Apr 12, 2021
6f83117
fix: mutable default values in method definitions (#1997)
mndeveci Apr 22, 2021
2925701
fix: remove explicit logging level set in single module (#1998)
mndeveci Apr 22, 2021
ff86ef6
fix: Fail when Intrinsics are in SourceVPC list instead of Intrinsics…
jfuss May 10, 2021
4f272ae
feat: Adding support for metric publishing. (#2062)
c2tarun Jun 23, 2021
36b7a3d
Update AppConfig boto3 client config to shorten timeout (#2070)
hawflau Jun 24, 2021
bb101ef
feat: Add ValidateBody/ValidateParameters attribute to API models (#2…
Rondineli Jun 30, 2021
4d432d7
fix: fail with invalid resource, when RetentionPolicy has unresolved …
mndeveci Jun 30, 2021
c4de6a0
test: Migration of combination integration tests (#1970)
mingkun2020 Jul 9, 2021
7ee8c60
fix: Compare integration tests results using hash of file content ins…
mingkun2020 Jul 10, 2021
d1590f8
Remove logging of SAR service call response (#2064)
hawflau Jul 15, 2021
5a85aea
Test CloudWatchEvent Properties With Intrinsic Functions (#2090)
mildaniel Jul 16, 2021
018c3a5
test: Added intrinsic tests for Function SNS Event (#2101)
mgrandis Jul 23, 2021
b3a9aba
fix: Validate Trigger field and test Cognito properties with intrinsi…
mildaniel Jul 23, 2021
5a4a81b
feat(Intrinsic Tests): Added Tests for Kinesis Event Source with Intr…
CoshUS Jul 23, 2021
938414a
fix: Don't attempt to refetch a swagger method object by its name as …
elbayaaa Jul 26, 2021
c01321d
test: Adding intrinsic tests for Function S3 Event (#2100)
mgrandis Jul 26, 2021
e3057b3
fix(bug): Check if Identity.ReauthorizeEvery equals zero (#2105)
jfuss Jul 27, 2021
b26769d
chore: Update PR Checklist to include writing intrinsic tests (#2106)
jfuss Jul 27, 2021
23ecdf4
Delete .travis.yml (#2102)
shogo82148 Jul 27, 2021
274cb7d
fix: Correct grammar in the waiting for changeset message (#2027)
skyzyx Jul 28, 2021
7a99052
chore: bump version to 1.39.0 (#2128)
jfuss Aug 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

*Checklist:*

- [ ] Write/update tests
- [ ] Add/update tests using:
- [ ] Correct values
- [ ] Bad/wrong values (None, empty, wrong type, length, etc.)
- [ ] [Intrinsic Functions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html)
- [ ] `make pr` passes
- [ ] Update documentation
- [ ] Verify transformed template deploys and application functions as expected
Expand Down
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ init:
test:
pytest --cov samtranslator --cov-report term-missing --cov-fail-under 95 tests/*

test-cov-report:
pytest --cov samtranslator --cov-report term-missing --cov-report html --cov-fail-under 95 tests/*

integ-test:
pytest --no-cov integration/*

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ environment that lets you locally build, test, debug, and deploy applications de

## What is this Github repository? 💻

This GitHub repository contains the SAM Specification, the Python code that translates SAM templates into AWS CloudFormation stacks and lots of examples applications.
This GitHub repository contains the SAM Specification, the Python code that translates SAM templates into AWS CloudFormation stacks and lots of example applications.
In the words of SAM developers:

> SAM Translator is the Python code that deploys SAM templates via AWS CloudFormation. Source code is high quality (95% unit test coverage),
Expand Down
2 changes: 1 addition & 1 deletion docs/internals/generated_resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ AWS::Lambda::Permission MyFunction\ **ThumbnailApi**\ Permission\ **P
NOTE: ``ServerlessRestApi*`` resources are generated one per stack.

HTTP API
^^^
^^^^
This is called an "Implicit HTTP API". There can be many functions in the template that define these APIs. Behind the
scenes, SAM will collect all implicit HTTP APIs from all Functions in the template, generate an OpenApi doc, and create an
implicit ``AWS::Serverless::HttpApi`` using this OpenApi. This API defaults to a StageName called "$default" that cannot be
Expand Down
Empty file.
181 changes: 181 additions & 0 deletions integration/combination/test_api_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import hashlib

try:
from pathlib import Path
except ImportError:
from pathlib2 import Path

import requests
from parameterized import parameterized

from integration.helpers.base_test import BaseTest


class TestApiSettings(BaseTest):
def test_method_settings(self):
self.create_and_verify_stack("combination/api_with_method_settings")

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client
response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod")

wildcard_path = "*/*"

method_settings = response["methodSettings"]
self.assertTrue(wildcard_path in method_settings, "MethodSettings for the wildcard path must be present")

wildcard_path_setting = method_settings[wildcard_path]

self.assertTrue(wildcard_path_setting["metricsEnabled"], "Metrics must be enabled")
self.assertTrue(wildcard_path_setting["dataTraceEnabled"], "DataTrace must be enabled")
self.assertEqual(wildcard_path_setting["loggingLevel"], "INFO", "LoggingLevel must be INFO")

@parameterized.expand(
[
"combination/api_with_binary_media_types",
"combination/api_with_binary_media_types_with_definition_body",
]
)
def test_binary_media_types(self, file_name):
self.create_and_verify_stack(file_name, self.get_default_test_template_parameters())

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_rest_api(restApiId=rest_api_id)
self.assertEqual(set(response["binaryMediaTypes"]), {"image/jpg", "image/png", "image/gif"})

@parameterized.expand(
[
"combination/api_with_request_models",
"combination/api_with_request_models_openapi",
]
)
def test_request_models(self, file_name):
self.create_and_verify_stack(file_name)

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_models(restApiId=rest_api_id)
request_models = response["items"]

self.assertEqual(request_models[0]["name"], "user")
self.assertEqual(
request_models[0]["schema"],
'{\n "type" : "object",\n'
+ ' "properties" : {\n "username" : {\n "type" : "string"\n }\n'
+ " }\n}",
)

def test_request_parameters_open_api(self):
self.create_and_verify_stack("combination/api_with_request_parameters_openapi")

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

# Test if the request parameters got set on the method
resources_response = apigw_client.get_resources(restApiId=rest_api_id)
resources = resources_response["items"]

resource = get_resource_by_path(resources, "/one")
method = apigw_client.get_method(restApiId=rest_api_id, resourceId=resource["id"], httpMethod="GET")
expected = {"method.request.querystring.type": True}
self.assertEqual(expected, method["requestParameters"])

# Test that the method settings got applied on the method
stage_response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod")
method_settings = stage_response["methodSettings"]

path = "one/GET"
self.assertTrue(path in method_settings, "MethodSettings for the path must be present")

path_settings = method_settings[path]
self.assertEqual(path_settings["cacheTtlInSeconds"], 15)
self.assertTrue(path_settings["cachingEnabled"], "Caching must be enabled")

def test_binary_media_types_with_definition_body_openapi(self):
parameters = self.get_default_test_template_parameters()
binary_media = {
"ParameterKey": "BinaryMediaCodeKey",
"ParameterValue": "binary-media.zip",
"UsePreviousValue": False,
"ResolvedValue": "string",
}
parameters.append(binary_media)

self.create_and_verify_stack("combination/api_with_binary_media_types_with_definition_body_openapi", parameters)

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_rest_api(restApiId=rest_api_id)
self.assertEqual(
set(response["binaryMediaTypes"]), {"image/jpg", "image/png", "image/gif", "application/octet-stream"}
)
base_url = self.get_stack_output("ApiUrl")["OutputValue"]
self.verify_binary_media_request(base_url + "none", 200)

@parameterized.expand(
[
"combination/api_with_endpoint_configuration",
"combination/api_with_endpoint_configuration_dict",
]
)
def test_end_point_configuration(self, file_name):
self.create_and_verify_stack(file_name, self.get_default_test_template_parameters())

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_rest_api(restApiId=rest_api_id)
endpoint_config = response["endpointConfiguration"]
self.assertEqual(endpoint_config["types"], ["REGIONAL"])

def test_implicit_api_settings(self):
self.create_and_verify_stack("combination/implicit_api_with_settings")

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod")

wildcard_path = "*/*"

method_settings = response["methodSettings"]
self.assertTrue(wildcard_path in method_settings, "MethodSettings for the wildcard path must be present")

wildcard_path_setting = method_settings[wildcard_path]

self.assertTrue(wildcard_path_setting["metricsEnabled"], "Metrics must be enabled")
self.assertTrue(wildcard_path_setting["dataTraceEnabled"], "DataTrace must be enabled")
self.assertEqual(wildcard_path_setting["loggingLevel"], "INFO", "LoggingLevel must be INFO")

response = apigw_client.get_rest_api(restApiId=rest_api_id)
endpoint_config = response["endpointConfiguration"]
self.assertEqual(endpoint_config["types"], ["REGIONAL"])
self.assertEqual(set(response["binaryMediaTypes"]), {"image/jpg", "image/png"})

def verify_binary_media_request(self, url, expected_status_code):
headers = {"accept": "image/png"}
response = requests.get(url, headers=headers)

status = response.status_code
expected_file_path = str(Path(self.code_dir, "AWS_logo_RGB.png"))

with open(expected_file_path, mode="rb") as file:
expected_file_content = file.read()
expected_hash = hashlib.sha1(expected_file_content).hexdigest()

if 200 <= status <= 299:
actual_hash = hashlib.sha1(response.content).hexdigest()
self.assertEqual(expected_hash, actual_hash)

self.assertEqual(status, expected_status_code, " must return HTTP " + str(expected_status_code))


def get_resource_by_path(resources, path):
for resource in resources:
if resource["path"] == path:
return resource
return None
Loading