From c8d829fa4be914c03de7b254f03a01bbee88ddc9 Mon Sep 17 00:00:00 2001 From: Jimmy Gaussen Date: Tue, 28 May 2024 17:43:46 +0200 Subject: [PATCH 1/4] fix(integ-tests): http flattenResponse --- .../lib/assertions/http-call.ts | 1 + .../providers/lambda-handler/http.ts | 21 +- .../providers/lambda-handler/types.ts | 16 + ...efaultTestDeployAssertDC0672BB.assets.json | 10 +- ...aultTestDeployAssertDC0672BB.template.json | 195 ++++++++- .../InvokeFunctionAssertions.assets.json | 4 +- .../InvokeFunctionAssertions.template.json | 124 ++++++ .../manifest.json | 70 ++- .../tree.json | 409 ++++++++++++++++++ .../integ.http-api-call-assertions.ts | 54 +++ .../providers/lambda-handler/http.test.ts | 4 +- 11 files changed, 885 insertions(+), 23 deletions(-) diff --git a/packages/@aws-cdk/integ-tests-alpha/lib/assertions/http-call.ts b/packages/@aws-cdk/integ-tests-alpha/lib/assertions/http-call.ts index 473131ecbbe4c..9e4812d6493d1 100644 --- a/packages/@aws-cdk/integ-tests-alpha/lib/assertions/http-call.ts +++ b/packages/@aws-cdk/integ-tests-alpha/lib/assertions/http-call.ts @@ -32,6 +32,7 @@ export class HttpApiCall extends ApiCallBase { parameters: props, expected: Lazy.any({ produce: () => this.expectedResult }), stateMachineArn: Lazy.string({ produce: () => this.stateMachineArn }), + flattenResponse: Lazy.string({ produce: () => this.flattenResponse }), salt: Date.now().toString(), }, resourceType: `${HTTP_RESOURCE_TYPE}${name}`.substring(0, 60), diff --git a/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/http.ts b/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/http.ts index ec9ff7ba80e7b..9fc9555459a4f 100644 --- a/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/http.ts +++ b/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/http.ts @@ -2,11 +2,13 @@ // eslint-disable-next-line import/no-extraneous-dependencies import fetch, { Response } from 'node-fetch'; // TODO: can use builtin fetch on node18 +import { flatten } from '@aws-cdk/aws-custom-resource-sdk-adapter'; import { CustomResourceHandler } from './base'; import { HttpRequest, HttpResponseWrapper } from './types'; +import { deepParseJson } from './utils'; -export class HttpHandler extends CustomResourceHandler { - protected async processEvent(request: HttpRequest): Promise { +export class HttpHandler extends CustomResourceHandler { + protected async processEvent(request: HttpRequest): Promise { console.log('request', request); const response: Response = await fetch(request.parameters.url, request.parameters.fetchOptions); const result: any = { @@ -22,8 +24,17 @@ export class HttpHandler extends CustomResourceHandler ({\n statusCode: 200,\n body: echo,\n });" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "EchoHandlerServiceRole659EA5BA", + "Arn" + ] + }, + "Runtime": "nodejs20.x" + }, + "DependsOn": [ + "EchoHandlerServiceRole659EA5BA" + ] + }, "Stage0E8C2AF5": { "Type": "AWS::ApiGatewayV2::Stage", "Properties": { diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/manifest.json b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/manifest.json index 706291c78dadb..f5d536ca8023f 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/manifest.json +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/36e80ce5dbc492c642dac9ca0257e10d8e34c3caf3f30260ac762e52e4b238c2.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2e7fc58037a1e3ef5a30c65ac2af47e5febfe4e4d862e183203483306d542b1e.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -100,6 +100,24 @@ "data": "HttpApiGETstatus403A55D5D16" } ], + "/InvokeFunctionAssertions/HttpApi/GET--echo--{echo}/EchoIntegration/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "HttpApiGETechoechoEchoIntegration7C9B7725" + } + ], + "/InvokeFunctionAssertions/HttpApi/GET--echo--{echo}/EchoIntegration-Permission": [ + { + "type": "aws:cdk:logicalId", + "data": "HttpApiGETechoechoEchoIntegrationPermission23357605" + } + ], + "/InvokeFunctionAssertions/HttpApi/GET--echo--{echo}/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "HttpApiGETechoecho3FB8EAA5" + } + ], "/InvokeFunctionAssertions/GetHandler/ServiceRole/Resource": [ { "type": "aws:cdk:logicalId", @@ -136,6 +154,18 @@ "data": "ForbiddenHandler630D1ED1" } ], + "/InvokeFunctionAssertions/EchoHandler/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "EchoHandlerServiceRole659EA5BA" + } + ], + "/InvokeFunctionAssertions/EchoHandler/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "EchoHandlerB75BC5D4" + } + ], "/InvokeFunctionAssertions/Stage/Resource": [ { "type": "aws:cdk:logicalId", @@ -180,7 +210,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/50a9f7f8eefab0b355a2ce03bbac0a10a5daafbdf65cdc3a014650815ee0731f.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5eecc163dd1744c46ae3dd64631ce6cafc338d55d236de3af962ce0f8e5f0beb.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -245,6 +275,24 @@ "data": "AssertionResultsHttpApiCallf16d32bb38fdf952b8530f86260d5337" } ], + "/AssertionsTest/DefaultTest/DeployAssert/HttpApiCallb4a073c2cf8d627c3401d840e86f6804/Default/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "HttpApiCallb4a073c2cf8d627c3401d840e86f6804" + } + ], + "/AssertionsTest/DefaultTest/DeployAssert/HttpApiCall926492d2f4793e05bf2949d16464966f/Default/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "HttpApiCall926492d2f4793e05bf2949d16464966f" + } + ], + "/AssertionsTest/DefaultTest/DeployAssert/HttpApiCall926492d2f4793e05bf2949d16464966f/AssertionResults": [ + { + "type": "aws:cdk:logicalId", + "data": "AssertionResultsHttpApiCall926492d2f4793e05bf2949d16464966f" + } + ], "/AssertionsTest/DefaultTest/DeployAssert/HttpApiCallhttpbin.org--getcd942067e1d112f86d205b2008dcab31/Default/Default": [ { "type": "aws:cdk:logicalId", @@ -281,6 +329,24 @@ "data": "AssertionResultsHttpApiCallhttpbinorgstatus403241ddf94e19f31ae5405653ddcc7ea8b" } ], + "/AssertionsTest/DefaultTest/DeployAssert/HttpApiCallhttpbin.org--uuid578ccfacb1d0792dd6965cdddf794e02/Default/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "HttpApiCallhttpbinorguuid578ccfacb1d0792dd6965cdddf794e02" + } + ], + "/AssertionsTest/DefaultTest/DeployAssert/HttpApiCall01535207422a144ea98405a56eae8349/Default/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "HttpApiCall01535207422a144ea98405a56eae8349" + } + ], + "/AssertionsTest/DefaultTest/DeployAssert/HttpApiCall01535207422a144ea98405a56eae8349/AssertionResults": [ + { + "type": "aws:cdk:logicalId", + "data": "AssertionResultsHttpApiCall01535207422a144ea98405a56eae8349" + } + ], "/AssertionsTest/DefaultTest/DeployAssert/BootstrapVersion": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/tree.json b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/tree.json index f0d504dc80660..76c6a56907c9b 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/tree.json +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/tree.json @@ -408,6 +408,124 @@ "fqn": "aws-cdk-lib.aws_apigatewayv2.HttpRoute", "version": "0.0.0" } + }, + "GET--echo--{echo}": { + "id": "GET--echo--{echo}", + "path": "InvokeFunctionAssertions/HttpApi/GET--echo--{echo}", + "children": { + "EchoIntegration": { + "id": "EchoIntegration", + "path": "InvokeFunctionAssertions/HttpApi/GET--echo--{echo}/EchoIntegration", + "children": { + "Resource": { + "id": "Resource", + "path": "InvokeFunctionAssertions/HttpApi/GET--echo--{echo}/EchoIntegration/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::Integration", + "aws:cdk:cloudformation:props": { + "apiId": { + "Ref": "HttpApiF5A9A8A7" + }, + "integrationType": "AWS_PROXY", + "integrationUri": { + "Fn::GetAtt": [ + "EchoHandlerB75BC5D4", + "Arn" + ] + }, + "payloadFormatVersion": "2.0" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnIntegration", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigatewayv2.HttpIntegration", + "version": "0.0.0" + } + }, + "EchoIntegration-Permission": { + "id": "EchoIntegration-Permission", + "path": "InvokeFunctionAssertions/HttpApi/GET--echo--{echo}/EchoIntegration-Permission", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Permission", + "aws:cdk:cloudformation:props": { + "action": "lambda:InvokeFunction", + "functionName": { + "Fn::GetAtt": [ + "EchoHandlerB75BC5D4", + "Arn" + ] + }, + "principal": "apigateway.amazonaws.com", + "sourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "HttpApiF5A9A8A7" + }, + "/*/*/echo/{echo}" + ] + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnPermission", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "InvokeFunctionAssertions/HttpApi/GET--echo--{echo}/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::Route", + "aws:cdk:cloudformation:props": { + "apiId": { + "Ref": "HttpApiF5A9A8A7" + }, + "authorizationType": "NONE", + "routeKey": "GET /echo/{echo}", + "target": { + "Fn::Join": [ + "", + [ + "integrations/", + { + "Ref": "HttpApiGETechoechoEchoIntegration7C9B7725" + } + ] + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigatewayv2.HttpRoute", + "version": "0.0.0" + } } }, "constructInfo": { @@ -688,6 +806,97 @@ "version": "0.0.0" } }, + "EchoHandler": { + "id": "EchoHandler", + "path": "InvokeFunctionAssertions/EchoHandler", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "InvokeFunctionAssertions/EchoHandler/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "InvokeFunctionAssertions/EchoHandler/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "InvokeFunctionAssertions/EchoHandler/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "InvokeFunctionAssertions/EchoHandler/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "\n exports.handler = async ({ pathParameters: { echo } }) => ({\n statusCode: 200,\n body: echo,\n });" + }, + "handler": "index.handler", + "role": { + "Fn::GetAtt": [ + "EchoHandlerServiceRole659EA5BA", + "Arn" + ] + }, + "runtime": "nodejs20.x" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnFunction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.Function", + "version": "0.0.0" + } + }, "Stage": { "id": "Stage", "path": "InvokeFunctionAssertions/Stage", @@ -972,6 +1181,106 @@ "version": "0.0.0" } }, + "HttpApiCallb4a073c2cf8d627c3401d840e86f6804": { + "id": "HttpApiCallb4a073c2cf8d627c3401d840e86f6804", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallb4a073c2cf8d627c3401d840e86f6804", + "children": { + "HttpProvider": { + "id": "HttpProvider", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallb4a073c2cf8d627c3401d840e86f6804/HttpProvider", + "children": { + "AssertionsProvider": { + "id": "AssertionsProvider", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallb4a073c2cf8d627c3401d840e86f6804/HttpProvider/AssertionsProvider", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.AssertionsProvider", + "version": "0.0.0" + } + }, + "Default": { + "id": "Default", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallb4a073c2cf8d627c3401d840e86f6804/Default", + "children": { + "Default": { + "id": "Default", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallb4a073c2cf8d627c3401d840e86f6804/Default/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.HttpApiCall", + "version": "0.0.0" + } + }, + "HttpApiCall926492d2f4793e05bf2949d16464966f": { + "id": "HttpApiCall926492d2f4793e05bf2949d16464966f", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall926492d2f4793e05bf2949d16464966f", + "children": { + "HttpProvider": { + "id": "HttpProvider", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall926492d2f4793e05bf2949d16464966f/HttpProvider", + "children": { + "AssertionsProvider": { + "id": "AssertionsProvider", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall926492d2f4793e05bf2949d16464966f/HttpProvider/AssertionsProvider", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.AssertionsProvider", + "version": "0.0.0" + } + }, + "Default": { + "id": "Default", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall926492d2f4793e05bf2949d16464966f/Default", + "children": { + "Default": { + "id": "Default", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall926492d2f4793e05bf2949d16464966f/Default/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResource", + "version": "0.0.0" + } + }, + "AssertionResults": { + "id": "AssertionResults", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall926492d2f4793e05bf2949d16464966f/AssertionResults", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnOutput", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.HttpApiCall", + "version": "0.0.0" + } + }, "HttpApiCallhttpbin.org--getcd942067e1d112f86d205b2008dcab31": { "id": "HttpApiCallhttpbin.org--getcd942067e1d112f86d205b2008dcab31", "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallhttpbin.org--getcd942067e1d112f86d205b2008dcab31", @@ -1134,6 +1443,106 @@ "version": "0.0.0" } }, + "HttpApiCallhttpbin.org--uuid578ccfacb1d0792dd6965cdddf794e02": { + "id": "HttpApiCallhttpbin.org--uuid578ccfacb1d0792dd6965cdddf794e02", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallhttpbin.org--uuid578ccfacb1d0792dd6965cdddf794e02", + "children": { + "HttpProvider": { + "id": "HttpProvider", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallhttpbin.org--uuid578ccfacb1d0792dd6965cdddf794e02/HttpProvider", + "children": { + "AssertionsProvider": { + "id": "AssertionsProvider", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallhttpbin.org--uuid578ccfacb1d0792dd6965cdddf794e02/HttpProvider/AssertionsProvider", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.AssertionsProvider", + "version": "0.0.0" + } + }, + "Default": { + "id": "Default", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallhttpbin.org--uuid578ccfacb1d0792dd6965cdddf794e02/Default", + "children": { + "Default": { + "id": "Default", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCallhttpbin.org--uuid578ccfacb1d0792dd6965cdddf794e02/Default/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.HttpApiCall", + "version": "0.0.0" + } + }, + "HttpApiCall01535207422a144ea98405a56eae8349": { + "id": "HttpApiCall01535207422a144ea98405a56eae8349", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall01535207422a144ea98405a56eae8349", + "children": { + "HttpProvider": { + "id": "HttpProvider", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall01535207422a144ea98405a56eae8349/HttpProvider", + "children": { + "AssertionsProvider": { + "id": "AssertionsProvider", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall01535207422a144ea98405a56eae8349/HttpProvider/AssertionsProvider", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.AssertionsProvider", + "version": "0.0.0" + } + }, + "Default": { + "id": "Default", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall01535207422a144ea98405a56eae8349/Default", + "children": { + "Default": { + "id": "Default", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall01535207422a144ea98405a56eae8349/Default/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResource", + "version": "0.0.0" + } + }, + "AssertionResults": { + "id": "AssertionResults", + "path": "AssertionsTest/DefaultTest/DeployAssert/HttpApiCall01535207422a144ea98405a56eae8349/AssertionResults", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnOutput", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.HttpApiCall", + "version": "0.0.0" + } + }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "AssertionsTest/DefaultTest/DeployAssert/BootstrapVersion", diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts index e3c1bd42b2702..ddfa484134fae 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts @@ -56,6 +56,21 @@ httpApi.addRoutes({ })), }); +httpApi.addRoutes({ + path: '/echo/{echo}', + methods: [apigwv2.HttpMethod.GET], + integration: new integrations.HttpLambdaIntegration('EchoIntegration', + new lambda.Function(stack, 'EchoHandler', { + runtime: lambda.Runtime.NODEJS_20_X, + handler: 'index.handler', + code: new lambda.InlineCode(` + exports.handler = async ({ pathParameters: { echo } }) => ({ + statusCode: 200, + body: echo, + });`), + })), +}); + const stage = new apigwv2.HttpStage(stack, 'Stage', { httpApi, stageName: 'dev', @@ -96,6 +111,22 @@ integ.assertions.httpApiCall( }), ); +// FIXME expectations broken by flattenResult? +const echoCall = integ.assertions.httpApiCall( + `${stage.url}/echo/HelloWorld`, +); +const echo = echoCall.getAttString('body'); + +integ.assertions.httpApiCall( + `${stage.url}/echo/${echo}`, +).expect( + ExpectedResult.objectLike({ + status: 200, + ok: true, + body: echo, + }), +); + // We are also using httpbin.org to test the assertions with a fixed URL // See https://github.com/aws/aws-cdk/issues/29700 @@ -138,3 +169,26 @@ integ.assertions.httpApiCall( ok: false, }), ); + +// FIXME expectations broken by flattenResult? +const uuidCall = integ.assertions.httpApiCall( + 'https://httpbin.org/uuid', +)/* .expect( + ExpectedResult.objectLike({ + status: 200, + ok: true, + }), +) */; +const uuid = uuidCall.getAttString('body.uuid'); + +integ.assertions.httpApiCall( + `https://httpbin.org/anything/${uuid}`, +).expect( + ExpectedResult.objectLike({ + status: 200, + ok: true, + body: { + url: `https://httpbin.org/anything/${uuid}`, + }, + }), +); \ No newline at end of file diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/lambda-handler/http.test.ts b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/lambda-handler/http.test.ts index 0da75eb5f8699..05a3b76094c3d 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/lambda-handler/http.test.ts +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/lambda-handler/http.test.ts @@ -113,7 +113,7 @@ describe('HttpHandler', () => { const response = await processEvent({ parameters: { url: 'x' } }); // THEN - expect(response.apiCallResponse.body).toEqual({ key: 'value' }); + expect(response.apiCallResponse).toEqual({ body: { key: 'value' } }); }); test('Non-JSON is not parsed', async () => { @@ -126,7 +126,7 @@ describe('HttpHandler', () => { const response = await processEvent({ parameters: { url: 'x' } }); // THEN - expect(response.apiCallResponse.body).toEqual('this is a string'); + expect(response.apiCallResponse).toEqual({ body: 'this is a string' }); }); }); From 3b5ed12d7bb8d84d4137c691003bdaa5a3c52dd7 Mon Sep 17 00:00:00 2001 From: Jimmy Gaussen Date: Tue, 4 Jun 2024 08:32:25 +0200 Subject: [PATCH 2/4] fix: test --- .../test/assertions/providers/integ.http-api-call-assertions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts index ddfa484134fae..22a9b4316b953 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts @@ -191,4 +191,4 @@ integ.assertions.httpApiCall( url: `https://httpbin.org/anything/${uuid}`, }, }), -); \ No newline at end of file +); From a992da9777c8addc23001d8508e388bc44e7df14 Mon Sep 17 00:00:00 2001 From: Jimmy Gaussen Date: Mon, 10 Jun 2024 16:12:32 +0200 Subject: [PATCH 3/4] fix: unit test --- .../test/assertions/providers/lambda-handler/http.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/lambda-handler/http.test.ts b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/lambda-handler/http.test.ts index 05a3b76094c3d..939d78f8c9399 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/lambda-handler/http.test.ts +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/lambda-handler/http.test.ts @@ -113,7 +113,7 @@ describe('HttpHandler', () => { const response = await processEvent({ parameters: { url: 'x' } }); // THEN - expect(response.apiCallResponse).toEqual({ body: { key: 'value' } }); + expect(response.apiCallResponse).toMatchObject({ body: { key: 'value' } }); }); test('Non-JSON is not parsed', async () => { @@ -126,7 +126,7 @@ describe('HttpHandler', () => { const response = await processEvent({ parameters: { url: 'x' } }); // THEN - expect(response.apiCallResponse).toEqual({ body: 'this is a string' }); + expect(response.apiCallResponse).toMatchObject({ body: 'this is a string' }); }); }); From b49c8fcc79d77fef54e5d8399cd30537edd71e61 Mon Sep 17 00:00:00 2001 From: Jimmy Gaussen Date: Mon, 10 Jun 2024 16:18:21 +0200 Subject: [PATCH 4/4] fix: integ --- ...efaultTestDeployAssertDC0672BB.assets.json | 4 ++-- ...aultTestDeployAssertDC0672BB.template.json | 20 +++++++++---------- .../manifest.json | 2 +- .../integ.http-api-call-assertions.ts | 12 ++++++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.assets.json b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.assets.json index 8cd7160cf9a40..8351e1e8257eb 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.assets.json +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.assets.json @@ -14,7 +14,7 @@ } } }, - "5eecc163dd1744c46ae3dd64631ce6cafc338d55d236de3af962ce0f8e5f0beb": { + "503f62a00a2e258fb7167df4311707b1dbe9f4df405544db9067105f731b80ad": { "source": { "path": "AssertionsTestDefaultTestDeployAssertDC0672BB.template.json", "packaging": "file" @@ -22,7 +22,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "5eecc163dd1744c46ae3dd64631ce6cafc338d55d236de3af962ce0f8e5f0beb.json", + "objectKey": "503f62a00a2e258fb7167df4311707b1dbe9f4df405544db9067105f731b80ad.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.template.json b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.template.json index d1e5cdf4f00e3..be8ca8111f830 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.template.json +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.template.json @@ -33,7 +33,7 @@ }, "expected": "{\"$ObjectLike\":{\"status\":200,\"ok\":true,\"body\":\"Hello!\"}}", "flattenResponse": "false", - "salt": "1716910816085" + "salt": "1718029025810" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -120,7 +120,7 @@ }, "expected": "{\"$ObjectLike\":{\"status\":200,\"ok\":true,\"body\":\"Received body: {\\\"key\\\":\\\"value\\\"}\"}}", "flattenResponse": "false", - "salt": "1716910816086" + "salt": "1718029025811" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -158,7 +158,7 @@ }, "expected": "{\"$ObjectLike\":{\"status\":403,\"ok\":false}}", "flattenResponse": "false", - "salt": "1716910816086" + "salt": "1718029025811" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -195,7 +195,7 @@ } }, "flattenResponse": "true", - "salt": "1716910816087" + "salt": "1718029025812" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -253,7 +253,7 @@ ] }, "flattenResponse": "false", - "salt": "1716910816087" + "salt": "1718029025812" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -272,7 +272,7 @@ }, "expected": "{\"$ObjectLike\":{\"status\":200,\"ok\":true,\"body\":{\"url\":\"https://httpbin.org/get?key=value\",\"args\":{\"key\":\"value\"}}}}", "flattenResponse": "false", - "salt": "1716910816087" + "salt": "1718029025812" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -298,7 +298,7 @@ }, "expected": "{\"$ObjectLike\":{\"status\":200,\"ok\":true,\"body\":{\"url\":\"https://httpbin.org/post\",\"json\":{\"key\":\"value\"}}}}", "flattenResponse": "false", - "salt": "1716910816087" + "salt": "1718029025812" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -317,7 +317,7 @@ }, "expected": "{\"$ObjectLike\":{\"status\":403,\"ok\":false}}", "flattenResponse": "false", - "salt": "1716910816087" + "salt": "1718029025812" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -335,7 +335,7 @@ "url": "https://httpbin.org/uuid" }, "flattenResponse": "true", - "salt": "1716910816087" + "salt": "1718029025812" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" @@ -381,7 +381,7 @@ ] }, "flattenResponse": "false", - "salt": "1716910816088" + "salt": "1718029025812" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/manifest.json b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/manifest.json index f5d536ca8023f..237fc2580454c 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/manifest.json +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/manifest.json @@ -210,7 +210,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5eecc163dd1744c46ae3dd64631ce6cafc338d55d236de3af962ce0f8e5f0beb.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/503f62a00a2e258fb7167df4311707b1dbe9f4df405544db9067105f731b80ad.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts index 22a9b4316b953..104cbdb6417a1 100644 --- a/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts +++ b/packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.ts @@ -111,10 +111,16 @@ integ.assertions.httpApiCall( }), ); -// FIXME expectations broken by flattenResult? +// FIXME expectations broken by flattenResult, see https://github.com/aws/aws-cdk/issues/30477 const echoCall = integ.assertions.httpApiCall( `${stage.url}/echo/HelloWorld`, -); +)/* .expect( + ExpectedResult.objectLike({ + status: 200, + ok: true, + body: 'HelloWorld', + }), +) */; const echo = echoCall.getAttString('body'); integ.assertions.httpApiCall( @@ -170,7 +176,7 @@ integ.assertions.httpApiCall( }), ); -// FIXME expectations broken by flattenResult? +// FIXME expectations broken by flattenResult, see https://github.com/aws/aws-cdk/issues/30477 const uuidCall = integ.assertions.httpApiCall( 'https://httpbin.org/uuid', )/* .expect(