Skip to content

Add test_apigateway_rest_api_waf_acl_attached.py to validate WAF ACL logic#304

Open
prajwal-choudhari-comprinno wants to merge 4 commits intocomprinnotech:testcases_devfrom
prajwal-choudhari-comprinno:test_apigateway_rest_api_waf_acl_attached
Open

Add test_apigateway_rest_api_waf_acl_attached.py to validate WAF ACL logic#304
prajwal-choudhari-comprinno wants to merge 4 commits intocomprinnotech:testcases_devfrom
prajwal-choudhari-comprinno:test_apigateway_rest_api_waf_acl_attached

Conversation

@prajwal-choudhari-comprinno

Context

This change introduces unit tests for the apigateway_rest_api_waf_acl_attached check. The purpose is to validate the logic that determines whether API Gateway REST APIs have WAF ACLs attached. This ensures the check's accuracy under various conditions and increases confidence during refactoring or enhancement.

Description

This PR includes a comprehensive test suite for the check apigateway_rest_api_waf_acl_attached, covering the following scenarios:

No REST APIs exist: The check should return PASSED with no resources.
WAF ACL is attached to REST API: The test simulates a REST API with the expected WAF tag. (Note: currently returns FAILED with empty results due to current implementation, as documented.)
WAF ACL not attached to REST API: Simulates APIs without the tag, expecting a FAILED result.
ClientError from AWS API: Simulates an AWS permission issue or internal error. The check should return UNKNOWN.

All tests mock the boto3 API calls using unittest.mock, avoiding live AWS interaction. No additional dependencies or infrastructure are required.

Checklist

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.


assert report.status == CheckStatus.UNKNOWN
assert report.resource_ids_status[0].status == CheckStatus.UNKNOWN
assert "API Gateway listing error occurred." in report.resource_ids_status[0].summary
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. No partial WAF coverage test Add test with one stage with webAclArn, one without
  2. No multiple API coverage Add test with two APIs (one passes, one fails)
  3. Exception field untested Assert presence of exception in the result for exceptions
  4. All APIs missing WAF Add test for multiple APIs, all stages missing WAF

Choose a reason for hiding this comment

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

Partial WAF coverage (some stages with WAF, some without)
Multiple APIs with mixed WAF coverage
Exception field coverage for get_stages and get_rest_apis
All APIs missing WAF scenario

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants