2 describe 'apt::key', :type => :define do
11 :key_server => "keyserver.ubuntu.com",
25 :key_source => 'ftp://ftp.example.org/key',
28 :key_content => 'deadbeef',
33 param_hash = default_params.merge(param_set)
34 param_hash[:key].upcase! if param_hash[:key]
44 str << param_hash[:key].to_s << '/'
45 str << param_hash[:key_content].to_s << '/'
46 str << param_hash[:key_source].to_s << '/'
47 str << param_hash[:key_server].to_s << '/'
48 Digest::SHA1.hexdigest(str)
51 describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
54 if [:present, 'present', :absent, 'absent'].include? param_hash[:ensure]
55 should contain_apt__params
60 if [:present, 'present'].include? param_hash[:ensure]
61 should_not contain_exec("apt::key #{param_hash[:key]} absent")
62 should contain_anchor("apt::key #{param_hash[:key]} present")
63 should contain_exec(digest).with({
64 "path" => "/bin:/usr/bin",
65 "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
67 elsif [:absent, 'absent'].include? param_hash[:ensure]
68 should_not contain_anchor("apt::key #{param_hash[:key]} present")
69 should contain_exec("apt::key #{param_hash[:key]} absent").with({
70 "path" => "/bin:/usr/bin",
71 "onlyif" => "apt-key list | grep '#{param_hash[:key]}'",
72 "command" => "apt-key del '#{param_hash[:key]}'"
75 expect { should raise_error(Puppet::Error) }
80 if [:present, 'present'].include? param_hash[:ensure]
81 if param_hash[:key_content]
82 should contain_exec(digest).with({
83 "command" => "echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -"
85 elsif param_hash[:key_source]
86 should contain_exec(digest).with({
87 "command" => "wget -q '#{param_hash[:key_source]}' -O- | apt-key add -"
89 elsif param_hash[:key_server]
90 should contain_exec(digest).with({
91 "command" => "apt-key adv --keyserver '#{param_hash[:key_server]}' --recv-keys '#{param_hash[:key]}'"
100 [{ :ensure => 'present' }, { :ensure => 'absent' }].each do |param_set|
101 describe "should correctly handle duplicate definitions" do
103 let :pre_condition do
104 "apt::key { 'duplicate': key => '#{title}'; }"
107 let(:params) { param_set }
110 if param_set[:ensure] == 'present'
111 should contain_anchor("apt::key #{title} present")
112 should contain_apt__key(title)
113 should contain_apt__key("duplicate")
114 elsif param_set[:ensure] == 'absent'
115 expect { should raise_error(Puppet::Error) }