From 9e1ef742f818332ae7daa673907fe10285278fbf Mon Sep 17 00:00:00 2001 From: Nikita Mathur Date: Thu, 10 Mar 2022 18:32:11 +0530 Subject: [PATCH] Test cases fixed and new test cases added Signed-off-by: Nikita Mathur --- lib/inspec/dsl.rb | 2 +- .../profiles/azure-profile/controls/azure.rb | 24 +++++++++++++++++ .../profiles/azure-profile/inspec.yml | 9 +++++++ test/functional/inspec_check_test.rb | 5 ++-- test/functional/inspec_exec_test.rb | 27 ++++++++++++++----- 5 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 test/fixtures/profiles/azure-profile/controls/azure.rb create mode 100644 test/fixtures/profiles/azure-profile/inspec.yml diff --git a/lib/inspec/dsl.rb b/lib/inspec/dsl.rb index f8030ed07..d5af0e59b 100644 --- a/lib/inspec/dsl.rb +++ b/lib/inspec/dsl.rb @@ -43,7 +43,7 @@ module Inspec::DSL include DeprecatedCloudResourcesList cloud_resource = id.start_with?("aws_") ? "aws" : "azure" - # this check raises deprecation warning for aws and azure resources that were part of InSpec before version 5. + # Deprecated AWS and Azure resources in InSpec 5. if CLOUD_RESOURCES_DEPRECATED.include? id Inspec.deprecate(:"#{cloud_resource}_resources_in_resource_pack", "Resource '#{id}'") else diff --git a/test/fixtures/profiles/azure-profile/controls/azure.rb b/test/fixtures/profiles/azure-profile/controls/azure.rb new file mode 100644 index 000000000..5ce0db6db --- /dev/null +++ b/test/fixtures/profiles/azure-profile/controls/azure.rb @@ -0,0 +1,24 @@ +control 'azure_resource_group_example' do + title 'Check if the Example Resource Group matches expectations' + impact 1.0 + + describe azure_resource_group(name: 'Inspec-Azure') do + # Check if the Resource Group is located in the correct region + its('location') { should cmp 'westeurope' } + + # Check if the Resource Group has tags + it { should have_tags } + + # Check if the number of VMs in the Resource Group is correct + its('vm_count') { should eq 3 } + + # Check if the number of public IPs is correct + its('public_ip_count') { should eq 1 } + + # Check if the number of Network Security Groups is correct + its('nsg_count') { should eq 1 } + + # Check if the number of Storage Accounts is correct + its('sa_count') { should eq 1 } + end +end diff --git a/test/fixtures/profiles/azure-profile/inspec.yml b/test/fixtures/profiles/azure-profile/inspec.yml new file mode 100644 index 000000000..c7c6b7444 --- /dev/null +++ b/test/fixtures/profiles/azure-profile/inspec.yml @@ -0,0 +1,9 @@ +name: azure +title: azure example profile +maintainer: Chef Software, Inc. +copyright: Chef Software, Inc. +copyright_email: support@chef.io +license: Apache-2.0 +summary: Testing stub +version: 1.0.0 +license: Apache-2.0 diff --git a/test/functional/inspec_check_test.rb b/test/functional/inspec_check_test.rb index f7e1c8e1f..e5ceaaa82 100644 --- a/test/functional/inspec_check_test.rb +++ b/test/functional/inspec_check_test.rb @@ -42,8 +42,7 @@ describe "inspec check" do describe "inspec check with a aws profile" do it "ignore train connection error" do out = inspec("check " + File.join(examples_path, "profile-aws")) - - assert_exit_code 0, out + assert_exit_code 3, out end end @@ -51,7 +50,7 @@ describe "inspec check" do it "ignore train connection error" do out = inspec("check " + File.join(examples_path, "profile-azure")) - assert_exit_code 0, out + assert_exit_code 3, out end end diff --git a/test/functional/inspec_exec_test.rb b/test/functional/inspec_exec_test.rb index 898f8b21b..ce88e71c9 100644 --- a/test/functional/inspec_exec_test.rb +++ b/test/functional/inspec_exec_test.rb @@ -479,15 +479,28 @@ Test Summary: 0 successful, 0 failures, 0 skipped end describe "with a profile that contains skipped resources" do - let(:out) { inspec("exec " + File.join(profile_path, "aws-profile")) } + let(:out) { inspec("exec " + File.join(examples_path, "profile-aws")) } it "exits with an error" do - skip if ENV["NO_AWS"] - _(stdout).must_include "Unsupported resource/backend combination: aws_iam_users" - _(stdout).must_include "Unsupported resource/backend combination: aws_iam_access_keys" - _(stdout).must_include "Unsupported resource/backend combination: aws_s3_bucket" - _(stdout).must_include "3 failures" + _(stdout).must_include "Skipping profile: 'profile-aws' on unsupported platform" + assert_exit_code 101, out + end + end - assert_exit_code 100, out + # Deprecation tests are called without aws:// and azure:// due to lack of creds + # aws-profile and azure-profiles does not have platforms as aws and azure for testing this scenario + describe "with a profile that contains deprecated aws resources" do + let(:out) { inspec("exec " + File.join(profile_path, "aws-profile")) } + it "exits with deprecation error" do + _(stdout).must_include "DEPRECATION: AWS resources shipped with core InSpec are deprecated" + assert_exit_code 3, out + end + end + + describe "with a profile that contains deprecated azure resources" do + let(:out) { inspec("exec " + File.join(profile_path, "azure-profile")) } + it "exits with deprecation error" do + _(stdout).must_include "DEPRECATION: Azure resources shipped with core InSpec are deprecated" + assert_exit_code 3, out end end