aws-cloudformation / aws-cloudformation/cloudformation-cli-java-plugin

WriteOnlyProperty removed before calling a Delete handler - Contract tests failure due to language specific plugin

未關閉
#318 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
Java
星號
30
分支
48
PR 合併指標
30 天內沒有已合併 PR

描述

Hi,

[My resource](https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-cloudformation/tree/master/aws-cloudformation-resourceversion) has a property "SchemaHandlerPackage", which is both a **required** property and a **writeOnlyProperty**. I am running contract_create_delete on my resource. The create handler is invoked and returns success after creating the resource. I return all required properties and the primary ID in the resourceModel after creating the resource.

My create handler returns IN_PROGRESS two times because it takes sometime to create the resource. For these two calls, I see the "SchemaHandlerPackage" in the response(because I return it in the intermediate response as well), something like this(in rpdk.log):

```
[2020-10-19T19:46:46Z] DEBUG - Received response
{
'status': 'IN_PROGRESS',
'callbackContext': {removed the values here},
'callbackDelaySeconds': 5,
'resourceModel': {
'Arn': 'arn:aws:cloudformation:us-west-2:336098619110:type/resource/Organization-Service-Resource17/00000033',
'SchemaHandlerPackage': 's3: //cloudformationsampleresourcetype/organization-service-resource17.zip',
'TypeName': 'Organization::Service::Resource17'
}
}
```
But when the handler returns success, the "SchemaHandlerPackage" is disappeared from the response, even though I set it in the code:

```
[2020-10-19T19:47:32Z] DEBUG - Received response{
'status': 'SUCCESS',
'callbackDelaySeconds': 0,
'resourceModel': {
'Arn': 'arn:aws:cloudformation:us-west-2:336098619110:type/resource/Organization-Service-Resource17/00000033',
'Description': 'Anexampleresourceschemademonstratingsomebasicconstructsandvalidationrules.',
'IsDefaultVersion': False,
'LastUpdated': '2020-10-19T19: 46: 50.047Z',
'ProvisioningType': 'FULLY_MUTABLE',
'Schema': {},
'SourceUrl': 'https: //github.com/aws-cloudformation/aws-cloudformation-rpdk.git',
'TimeCreated': '2020-10-19T19: 46: 50.047Z',
'TypeName': 'Organization::Service::Resource17',
'VersionId': '00000033',
'Visibility': 'PRIVATE'
}
}
```

I later found out that the writeOnlyProperties are removed before framing the request to the delete handler. By doing this, the writeOnlyProperty, which is also a required property is getting removed, hence the delete handler fails due to a validation error, which results in that contract test failure.

```
[2020-10-19T19:48:07Z] DEBUG - Received response
{'status': 'FAILED', 'errorCode': 'InvalidRequest', 'message': 'Model validation failed (#: required key [SchemaHandlerPackage] not found)', 'callbackDelaySeconds': 0}
[2020-10-19T19:48:08Z] DEBUG - Caught exit recommendation
```

Solution: Is the "required property validation" necessary for a delete handler? Checking for a Primary Id should be enough for a delete handler as per https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-delete Or you can remove a writeOnlyProperty only if it's not a required property.

Thanks,
Uma

貢獻指南

開啟貢獻指南

研究方向

Start by reading the contract test flow described in the issue and the CloudFormation resource type contract documentation linked there, especially the delete requirements. Then trace where writeOnlyProperties are stripped and where the delete request is validated in this Java plugin. Done means the delete handler receives the required write-only property, or required-property validation is appropriately avoided, and the contract_create_delete test passes.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
aws, java
領域
backend, testing
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
42/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。