From 367f91ea31f82cf0db8618fa362424006bbf88f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Magnus=20Rakv=C3=A5g?= Date: Thu, 31 May 2018 19:36:15 +0200 Subject: [PATCH] handle nil properties in iis_site (#3040) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * return nil instead of trying to index into nil * fix typo * add spec for deleted site Signed-off-by: Tor Magnus Rakvåg --- lib/resources/iis_site.rb | 8 ++++---- test/integration/default/controls/iis_site_spec.rb | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/resources/iis_site.rb b/lib/resources/iis_site.rb index 438ec78f1..f90f29cb5 100644 --- a/lib/resources/iis_site.rb +++ b/lib/resources/iis_site.rb @@ -40,19 +40,19 @@ module Inspec::Resources end def app_pool - iis_site[:app_pool] + iis_site.nil? ? nil : iis_site[:app_pool] end def bindings - iis_site[:bindings] + iis_site.nil? ? nil : iis_site[:bindings] end def state - iis_site[:state] + iis_site.nil? ? nil : iis_site[:state] end def path - iis_site[:path] + iis_site.nil? ? nil : iis_site[:path] end def exists? diff --git a/test/integration/default/controls/iis_site_spec.rb b/test/integration/default/controls/iis_site_spec.rb index 8b25ce815..7fb9980bb 100644 --- a/test/integration/default/controls/iis_site_spec.rb +++ b/test/integration/default/controls/iis_site_spec.rb @@ -33,10 +33,19 @@ describe iis_website('Default Web Site') do end describe iis_app('/TestApp', 'Default Web Site') do - it { sould exist } + it { should exist } it { should have_application_pool('DefaultAppPool') } it { should have_protocols('http') } it { should have_site_name('Default Web Site') } it { should have_physical_path('C:\\inetpub\\wwwroot\\Test') } it { should have_path('\\TestApp') } end + +# test testing a non existing website +describe iis_site('DeletedSite') do + it { should_not exist } + its('app_pool') { should eq nil } + its('bindings') { should eq nil } + its('state') { should eq nil } + its('path') { should eq nil } +end