|
| 1 | +require 'spec_helper' |
| 2 | +require 'password_rule_spec_helper' |
| 3 | +require 'cfn-model' |
| 4 | +require 'cfn-nag/custom_rules/EKSClusterEncryptionRule' |
| 5 | + |
| 6 | +describe EKSClusterEncryptionRule do |
| 7 | + context 'EKS Cluster with no EncryptionConfig' do |
| 8 | + it 'Returns the logical resource ID of the offending EKS Cluster resource' do |
| 9 | + cfn_model = CfnParser.new.parse read_test_template( |
| 10 | + 'yaml/eks_cluster/eks_cluster_encryptionconfig_not_set.yaml' |
| 11 | + ) |
| 12 | + |
| 13 | + actual_logical_resource_ids = |
| 14 | + EKSClusterEncryptionRule.new.audit_impl cfn_model |
| 15 | + expected_logical_resource_ids = %w[EKSCluster] |
| 16 | + |
| 17 | + expect(actual_logical_resource_ids).to eq expected_logical_resource_ids |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + context 'EKS Cluster with EncryptionConfig Provider KeyArn set' do |
| 22 | + it 'Returns empty list' do |
| 23 | + cfn_model = CfnParser.new.parse read_test_template( |
| 24 | + 'yaml/eks_cluster/eks_cluster_encryptionconfig_provider_keyarn_set.yaml' |
| 25 | + ) |
| 26 | + |
| 27 | + actual_logical_resource_ids = |
| 28 | + EKSClusterEncryptionRule.new.audit_impl cfn_model |
| 29 | + expected_logical_resource_ids = %w[] |
| 30 | + |
| 31 | + expect(actual_logical_resource_ids).to eq expected_logical_resource_ids |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + context 'EKS Cluster EncryptionConfig with Provider not set' do |
| 36 | + it 'Returns the logical resource ID of the offending EKS Cluster resource' do |
| 37 | + cfn_model = CfnParser.new.parse read_test_template( |
| 38 | + 'yaml/eks_cluster/eks_cluster_encryptionconfig_provider_not_set.yaml' |
| 39 | + ) |
| 40 | + |
| 41 | + actual_logical_resource_ids = |
| 42 | + EKSClusterEncryptionRule.new.audit_impl cfn_model |
| 43 | + expected_logical_resource_ids = %w[EKSCluster] |
| 44 | + |
| 45 | + expect(actual_logical_resource_ids).to eq expected_logical_resource_ids |
| 46 | + end |
| 47 | + end |
| 48 | +end |
0 commit comments