8000 Validate existing test apigw by cloutierMat · Pull Request #10653 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Validate existing test apigw #10653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion localstack/testing/pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,15 @@ def create_rest_apigw(aws_client_factory):

def _create_apigateway_function(**kwargs):
region_name = kwargs.pop("region_name", None)
apigateway_client = aws_client_factory(region_name=region_name).apigateway
client_config = None
if is_aws_cloud():
client_config = botocore.config.Config(
# Api gateway can throttle requests pretty heavily. Leading to potentially undeleted apis
retries={"max_attempts": 10, "mode": "adaptive"}
)
apigateway_client = aws_client_factory(
region_name=region_name, config=client_config
).apigateway
Comment on lines +1943 to +1951
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is a great way to fix it. We also have some other fixtures which just try deleting forever or almost if getting a 429, the throttling of DeleteRestApi is really insane to me, you'd need to add 15+ seconds sleep in between calls 😭 neat 👌

kwargs.setdefault("name", f"api-{short_uid()}")

response = apigateway_client.create_rest_api(**kwargs)
Expand Down
20 changes: 15 additions & 5 deletions tests/aws/services/acm/test_acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,24 @@ def _certificate_present():

snapshot.match("describe-certificate-response", describe_res)

@markers.aws.unknown
def test_domain_validation(self, acm_request_certificate, aws_client):
@markers.snapshot.skip_snapshot_verify(
paths=[
"$..ResourceRecord", # Added by LS but not in aws response
"$..ValidationEmails", # Not in LS response
]
)
@markers.aws.validated
def test_domain_validation(self, acm_request_certificate, aws_client, snapshot):
snapshot.add_transformer(snapshot.transform.key_value("CertificateArn"))
snapshot.add_transformer(snapshot.transform.key_value("DomainName"))
snapshot.add_transformer(snapshot.transform.key_value("ValidationMethod"))
snapshot.add_transformer(snapshot.transform.key_value("SignatureAlgorithm"))

certificate_arn = acm_request_certificate()["CertificateArn"]
result = aws_client.acm.describe_certificate(CertificateArn=certificate_arn)
options = result["Certificate"]["DomainValidationOptions"]
assert len(options) == 1
snapshot.match("describe-certificate", result)

@markers.aws.unknown
@markers.aws.needs_fixing
def test_boto_wait_for_certificate_validation(
self, acm_request_certificate, aws_client, monkeypatch
):
Expand Down
41 changes: 41 additions & 0 deletions tests/aws/services/acm/test_acm.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,46 @@
}
}
}
},
"tests/aws/services/acm/test_acm.py::TestACM::test_domain_validation": {
"recorded-date": "12-04-2024, 15:36:37",
"recorded-content": {
"describe-certificate": {
"Certificate": {
"CertificateArn": "<certificate-arn:1>",
"CreatedAt": "datetime",
"DomainName": "<domain-name:1>",
"DomainValidationOptions": [
{
"DomainName": "<domain-name:1>",
"ValidationDomain": "<domain-name:1>",
"ValidationEmails": [],
"ValidationMethod": "<validation-method:1>",
"ValidationStatus": "PENDING_VALIDATION"
}
],
"ExtendedKeyUsages": [],
"InUseBy": [],
"Issuer": "Amazon",
"KeyAlgorithm": "RSA-2048",
"KeyUsages": [],
"Options": {
"CertificateTransparencyLoggingPreference": "ENABLED"
},
"RenewalEligibility": "INELIGIBLE",
"SignatureAlgorithm": "<signature-algorithm:1>",
"Status": "PENDING_VALIDATION",
"Subject": "CN=<domain-name:1>",
"SubjectAlternativeNames": [
"<domain-name:1>"
],
"Type": "AMAZON_ISSUED"
},
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
}
}
}
}
3 changes: 3 additions & 0 deletions tests/aws/services/acm/test_acm.validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"tests/aws/services/acm/test_acm.py::TestACM::test_create_certificate_for_multiple_alternative_domains": {
"last_validated_date": "2024-01-09T14:58:14+00:00"
},
"tests/aws/services/acm/test_acm.py::TestACM::test_domain_validation": {
"last_validated_date": "2024-04-12T15:36:37+00:00"
},
"tests/aws/services/acm/test_acm.py::TestACM::test_import_certificate": {
"last_validated_date": "2024-02-22T17:41:15+00:00"
}
Expand Down
49 changes: 36 additions & 13 deletions tests/aws/services/apigateway/test_apigateway_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def test_delete_rest_api_with_invalid_id(self, aws_client):
assert "foobar" in e.value.response["Error"]["Message"]

@pytest.mark.parametrize("url_function", [path_based_url, host_based_url])
@markers.aws.unknown
@markers.aws.only_localstack
# This is not a possible feature on aws.
def test_create_rest_api_with_custom_id(self, create_rest_apigw, url_function, aws_client):
apigw_name = f"gw-{short_uid()}"
test_id = "testId123"
Expand All @@ -177,8 +178,10 @@ def test_create_rest_api_with_custom_id(self, create_rest_apigw, url_function, a
assert response.ok
assert response._content == b'{"echo": "foobar", "response": "mocked"}'

@markers.aws.unknown
def test_update_rest_api_deployment(self, create_rest_apigw, aws_client):
@markers.aws.validated
def test_update_rest_api_deployment(self, create_rest_apigw, aws_client, snapshot):
snapshot.add_transformer(snapshot.transform.key_value("id"))

api_id, _, root = create_rest_apigw(name="test_gateway5")

create_rest_resource_method(
Expand Down Expand Up @@ -218,7 +221,7 @@ def test_update_rest_api_deployment(self, create_rest_apigw, aws_client):
deploymentId=deployment_id,
patchOperations=patch_operations,
)
assert deployment["description"] == "new-description"
snapshot.match("after-update", deployment)

@markers.aws.validated
def test_api_gateway_lambda_integration_aws_type(
Expand Down Expand Up @@ -355,7 +358,9 @@ def test_invoke_endpoint_cors_headers(
assert response.status_code == 200
assert "http://test.com" in response.headers["Access-Control-Allow-Origin"]

@markers.aws.unknown
# This test fails as it tries to create a lambda locally?
# It then leaves some resources behind, apigateway and policies
@markers.aws.needs_fixing
@pytest.mark.parametrize(
"api_path", [API_PATH_LAMBDA_PROXY_BACKEND, API_PATH_LAMBDA_PROXY_BACKEND_WITH_PATH_PARAM]
)
Expand All @@ -376,7 +381,9 @@ def test_api_gateway_lambda_proxy_integration(
aws_client.apigateway,
)

@markers.aws.unknown
# This test fails as it tries to create a lambda locally?
# It then leaves some resources behind, apigateway and policies
@markers.aws.needs_fixing
def test_api_gateway_lambda_proxy_integration_with_is_base_64_encoded(
self, integration_lambda, aws_client, create_iam_role_with_policy
):
Expand Down Expand Up @@ -532,13 +539,17 @@ def _test_api_gateway_lambda_proxy_integration(
assert "/yCqIBE=" == result_content["body"]
assert ["isBase64Encoded"]

@markers.aws.unknown
# This test fails as it tries to create a lambda locally?
# It then leaves some resources behind, apigateway and policies
@markers.aws.needs_fixing
def test_api_gateway_lambda_proxy_integration_any_method(self, integration_lambda):
self._test_api_gateway_lambda_proxy_integration_any_method(
integration_lambda, API_PATH_LAMBDA_PROXY_BACKEND_ANY_METHOD
)

@markers.aws.unknown
# This test fails as it tries to create a lambda locally?
# It then leaves some resources behind, apigateway and policies
@markers.aws.needs_fixing
def test_api_gateway_lambda_proxy_integration_any_method_with_path_param(
self, integration_lambda
):
Expand Down Expand Up @@ -660,7 +671,9 @@ def test_malformed_response_apigw_invocation(
assert result.headers.get("Content-Type") == "application/json"
assert json.loads(result.content)["message"] == "Internal server error"

@markers.aws.unknown
# Missing certificate creation to create a domain
# this might end up being a bigger issue to fix until we have a validated certificate we can use
@markers.aws.needs_fixing
def test_api_gateway_handle_domain_name(self, aws_client):
domain_name = f"{short_uid()}.example.com"
apigw_client = aws_client.apigateway
Expand Down Expand Up @@ -699,15 +712,25 @@ def _test_api_gateway_lambda_proxy_integration_any_method(self, fn_name, path):
else:
assert 204 == result.status_code

@markers.aws.unknown
@markers.snapshot.skip_snapshot_verify(
paths=[
"$..authType", # Not added by LS
"$..authorizerResultTtlInSeconds", # Exists in LS but not in AWS
]
)
@markers.aws.validated
def test_apigateway_with_custom_authorization_method(
self, create_rest_apigw, aws_client, account_id, region_name, integration_lambda
self, create_rest_apigw, aws_client, account_id, region_name, integration_lambda, snapshot
):
snapshot.add_transformer(snapshot.transform.key_value("api_id"))
snapshot.add_transformer(snapshot.transform.key_value("authorizerUri"))
snapshot.add_transformer(snapshot.transform.key_value("id"))
# create Lambda function
lambda_uri = arns.lambda_function_arn(integration_lambda, account_id, region_name)

# create REST API
api_id, _, _ = create_rest_apigw(name="test-api")
snapshot.match("api-id", {"api_id": api_id})
root_res_id = aws_client.apigateway.get_resources(restApiId=api_id)["items"][0]["id"]

# create authorizer at root resource
Expand All @@ -719,6 +742,7 @@ def test_apigateway_with_custom_authorization_method(
2015-03-31/functions/{}/invocations".format(lambda_uri),
identitySource="method.request.header.Auth",
)
snapshot.match("authorizer", authorizer)

# create method with custom authorizer
is_api_key_required = True
Expand All @@ -730,8 +754,7 @@ def test_apigateway_with_custom_authorization_method(
authorizerId=authorizer["id"],
apiKeyRequired=is_api_key_required,
)

assert authorizer["id"] == method_response["authorizerId"]
snapshot.match("put-method-response", method_response)

@markers.aws.unknown
def test_base_path_mapping(self, create_rest_apigw, aws_client):
Expand Down
44 changes: 44 additions & 0 deletions tests/aws/services/apigateway/test_apigateway_basic.snapshot.json 17AE
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,49 @@
}
}
}
},
"tests/aws/services/apigateway/test_apigateway_basic.py::TestAPIGateway::test_update_rest_api_deployment": {
"recorded-date": "12-04-2024, 21:24:49",
"recorded-content": {
"after-update": {
"createdDate": "datetime",
"description": "new-description",
"id": "<id:1>",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
}
}
},
"tests/aws/services/apigateway/test_apigateway_basic.py::TestAPIGateway::test_apigateway_with_custom_authorization_method": {
"recorded-date": "12-04-2024, 22:31:50",
"recorded-content": {
"api-id": {
"api_id": "<api_id:1>"
},
"authorizer": {
"authType": "custom",
"authorizerUri": "<authorizer-uri:1>",
"id": "<id:1>",
"identitySource": "method.request.header.Auth",
"name": "lambda_authorizer",
"type": "TOKEN",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 201
}
},
"put-method-response": {
"apiKeyRequired": true,
"authorizationType": "CUSTOM",
"authorizerId": "<id:1>",
"httpMethod": "GET",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 201
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"tests/aws/services/apigateway/test_apigateway_basic.py::TestAPIGateway::test_apigateway_with_custom_authorization_method": {
"last_validated_date": "2024-04-12T22:31:50+00:00"
},
"tests/aws/services/apigateway/test_apigateway_basic.py::TestAPIGateway::test_apigateway_with_step_function_integration[DeleteStateMachine]": {
"last_validated_date": "2023-09-07T20:40:38+00:00"
},
Expand All @@ -7,5 +10,8 @@
},
"tests/aws/services/apigateway/test_apigateway_basic.py::TestAPIGateway::test_apigw_test_invoke_method_api": {
"last_validated_date": "2024-02-04T18:48:24+00:00"
},
"tests/aws/services/apigateway/test_apigateway_basic.py::TestAPIGateway::test_update_rest_api_deployment": {
"last_validated_date": "2024-04-12T21:24:49+00:00"
}
}
}
0