Merge pull request #282 from laurenrother/security
[puppet-modules/puppetlabs-apt.git] / spec / classes / apt_spec.rb
index 080bc81760282c70a9bf7b5a45249f06a645bd5d..0b677564d1d1cbc84193369f1e1c078e75be4b6d 100644 (file)
@@ -1,6 +1,6 @@
 require 'spec_helper'
 describe 'apt', :type => :class do
-  let(:facts) { { :lsbdistid => 'Debian' } }
+  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
   let :default_params do
     {
       :disable_keys => :undef,
@@ -19,6 +19,10 @@ describe 'apt', :type => :class do
       :purge_sources_list => true,
       :purge_sources_list_d => true,
     },
+    {
+      :purge_preferences   => true,
+      :purge_preferences_d => true,
+    },
     {
       :disable_keys => false
     }
@@ -86,6 +90,49 @@ describe 'apt', :type => :class do
           })
         end
       }
+      it {
+        if param_hash[:purge_preferences]
+          should create_file('apt-preferences').with({
+            :ensure  => 'present',
+            :path    => '/etc/apt/preferences',
+            :owner   => 'root',
+            :group   => 'root',
+            :mode    => '0644',
+            :content => /Explanation/,
+          })
+        else
+          should create_file('apt-preferences').with({
+            :ensure  => 'present',
+            :path    => '/etc/apt/preferences',
+            :owner   => 'root',
+            :group   => 'root',
+            :mode    => '0644',
+            :content => nil,
+          })
+        end
+      }
+
+      it {
+        if param_hash[:purge_preferences_d]
+          should create_file("preferences.d").with({
+            'path'    => "/etc/apt/preferences.d",
+            'ensure'  => "directory",
+            'owner'   => "root",
+            'group'   => "root",
+            'purge'   => true,
+            'recurse' => true,
+          })
+        else
+          should create_file("preferences.d").with({
+            'path'    => "/etc/apt/preferences.d",
+            'ensure'  => "directory",
+            'owner'   => "root",
+            'group'   => "root",
+            'purge'   => false,
+            'recurse' => false,
+          })
+        end
+      }
 
       it {
         should contain_exec("apt_update").with({
@@ -117,7 +164,7 @@ describe 'apt', :type => :class do
           if param_hash[:proxy_host]
             should contain_file('configure-apt-proxy').with(
               'path'    => '/etc/apt/apt.conf.d/proxy',
-              'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";",
+              'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";\n",
               'notify'  => "Exec[apt_update]"
             )
           else