|
49 | 49 | import software.amazon.cloudformation.proxy.hook.HookHandlerRequest;
|
50 | 50 | import software.amazon.cloudformation.proxy.hook.HookProgressEvent;
|
51 | 51 | import software.amazon.cloudformation.proxy.hook.HookStatus;
|
| 52 | +import software.amazon.cloudformation.proxy.hook.targetmodel.ChangedResource; |
| 53 | +import software.amazon.cloudformation.proxy.hook.targetmodel.StackHookTargetModel; |
52 | 54 | import software.amazon.cloudformation.resource.SchemaValidator;
|
53 | 55 | import software.amazon.cloudformation.resource.Serializer;
|
54 | 56 |
|
@@ -168,7 +170,6 @@ public void invokeHandler_CompleteSynchronously_returnsSuccess(final String requ
|
168 | 170 |
|
169 | 171 | // assert handler receives correct injections
|
170 | 172 | assertThat(wrapper.awsClientProxy).isNotNull();
|
171 |
| - assertThat(wrapper.getRequest()).isEqualTo(hookHandlerRequest); |
172 | 173 | assertThat(wrapper.invocationPoint).isEqualTo(invocationPoint);
|
173 | 174 | assertThat(wrapper.callbackContext).isNull();
|
174 | 175 | }
|
@@ -205,7 +206,6 @@ public void invokeHandler_WithResourceProperties_returnsSuccess(final String req
|
205 | 206 |
|
206 | 207 | // assert handler receives correct injections
|
207 | 208 | assertThat(wrapper.awsClientProxy).isNotNull();
|
208 |
| - assertThat(wrapper.getRequest()).isEqualTo(hookHandlerRequest); |
209 | 209 | assertThat(wrapper.invocationPoint).isEqualTo(invocationPoint);
|
210 | 210 | assertThat(wrapper.callbackContext).isNull();
|
211 | 211 | }
|
@@ -242,7 +242,6 @@ public void invokeHandler_WithResourcePropertiesAndExtraneousFields_returnsSucce
|
242 | 242 |
|
243 | 243 | // assert handler receives correct injections
|
244 | 244 | assertThat(wrapper.awsClientProxy).isNotNull();
|
245 |
| - assertThat(wrapper.getRequest()).isEqualTo(hookHandlerRequest); |
246 | 245 | assertThat(wrapper.invocationPoint).isEqualTo(invocationPoint);
|
247 | 246 | assertThat(wrapper.callbackContext).isNull();
|
248 | 247 | }
|
@@ -279,7 +278,6 @@ public void invokeHandler_StrictDeserializer_WithResourceProperties_returnsSucce
|
279 | 278 |
|
280 | 279 | // assert handler receives correct injections
|
281 | 280 | assertThat(wrapperStrictDeserialize.awsClientProxy).isNotNull();
|
282 |
| - assertThat(wrapperStrictDeserialize.getRequest()).isEqualTo(hookHandlerRequest); |
283 | 281 | assertThat(wrapperStrictDeserialize.invocationPoint).isEqualTo(invocationPoint);
|
284 | 282 | assertThat(wrapperStrictDeserialize.callbackContext).isNull();
|
285 | 283 | }
|
@@ -323,6 +321,54 @@ public void invokeHandler_StrictDeserializer_WithResourceProperties_returnsSucce
|
323 | 321 | }
|
324 | 322 | }
|
325 | 323 |
|
| 324 | + @ParameterizedTest |
| 325 | + @CsvSource({ "preCreate.request.with-stack-level-hook.json,CREATE_PRE_PROVISION" }) |
| 326 | + public void invokeHandler_WithStackLevelHook_returnsSuccess(final String requestDataPath, final String invocationPointString) |
| 327 | + throws IOException { |
| 328 | + final HookInvocationPoint invocationPoint = HookInvocationPoint.valueOf(invocationPointString); |
| 329 | + |
| 330 | + final ProgressEvent<TestModel, |
| 331 | + TestContext> pe = ProgressEvent.<TestModel, TestContext>builder().status(OperationStatus.SUCCESS).build(); |
| 332 | + wrapper.setInvokeHandlerResponse(pe); |
| 333 | + |
| 334 | + lenient().when(cipher.decryptCredentials(any())).thenReturn(new Credentials("123", "123", "123")); |
| 335 | + |
| 336 | + try (final InputStream in = loadRequestStream(requestDataPath); final OutputStream out = new ByteArrayOutputStream()) { |
| 337 | + final Context context = getLambdaContext(); |
| 338 | + |
| 339 | + wrapper.handleRequest(in, out, context); |
| 340 | + |
| 341 | + // verify initialiseRuntime was called and initialised dependencies |
| 342 | + verifyInitialiseRuntime(); |
| 343 | + |
| 344 | + // verify output response |
| 345 | + verifyHandlerResponse(out, |
| 346 | + HookProgressEvent.<TestContext>builder().clientRequestToken("123456").hookStatus(HookStatus.SUCCESS).build()); |
| 347 | + |
| 348 | + // assert handler receives correct injections |
| 349 | + assertThat(wrapper.awsClientProxy).isNotNull(); |
| 350 | + assertThat(wrapper.invocationPoint).isEqualTo(invocationPoint); |
| 351 | + assertThat(wrapper.callbackContext).isNull(); |
| 352 | + |
| 353 | + assertThat(wrapper.getRequest().getHookContext().getTargetType()).isEqualTo("STACK"); |
| 354 | + assertThat(wrapper.getRequest().getHookContext().getTargetName()).isEqualTo("STACK"); |
| 355 | + assertThat(wrapper.getRequest().getHookContext().getTargetLogicalId()).isEqualTo("myStack"); |
| 356 | + |
| 357 | + StackHookTargetModel stackHookTargetModel = wrapper.getRequest().getHookContext() |
| 358 | + .getTargetModel(StackHookTargetModel.class); |
| 359 | + assertThat(stackHookTargetModel.getTemplate()).isEqualTo("template string here"); |
| 360 | + assertThat(stackHookTargetModel.getPreviousTemplate()).isEqualTo("previous template string here"); |
| 361 | + assertThat(stackHookTargetModel.getResolvedTemplate()).isEqualTo("resolved template string here"); |
| 362 | + assertThat(stackHookTargetModel.getChangedResources().size()).isEqualTo(1); |
| 363 | + |
| 364 | + ChangedResource expectedChangedResource = ChangedResource.builder().logicalResourceId("SomeLogicalResourceId") |
| 365 | + .resourceType("AWS::S3::Bucket").lineNumber(3).action("CREATE") |
| 366 | + .resourceProperties("<Resource Properties as json string>") |
| 367 | + .previousResourceProperties("<Resource Properties as json string>").build(); |
| 368 | + assertThat(stackHookTargetModel.getChangedResources().get(0)).isEqualTo(expectedChangedResource); |
| 369 | + } |
| 370 | + } |
| 371 | + |
326 | 372 | private final String expectedStringWhenStrictDeserializingWithExtraneousFields = "Unrecognized field \"targetName\" (class software.amazon.cloudformation.proxy.hook.HookInvocationRequest), not marked as ignorable (10 known properties: \"requestContext\", \"stackId\", \"clientRequestToken\", \"hookModel\", \"hookTypeName\", \"requestData\", \"actionInvocationPoint\", \"awsAccountId\", \"changeSetId\", \"hookTypeVersion\"])\n"
|
327 | 373 | + " at [Source: (String)\"{\n" + " \"clientRequestToken\": \"123456\",\n" + " \"awsAccountId\": \"123456789012\",\n"
|
328 | 374 | + " \"stackId\": \"arn:aws:cloudformation:us-east-1:123456789012:stack/SampleStack/e722ae60-fe62-11e8-9a0e-0ae8cc519968\",\n"
|
|
0 commit comments