| 1 | require 'spec_helper'
|
|---|
| 2 |
|
|---|
| 3 | describe 'apt::key' do
|
|---|
| 4 | let :pre_condition do
|
|---|
| 5 | 'class { "apt": }'
|
|---|
| 6 | end
|
|---|
| 7 |
|
|---|
| 8 | let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } }
|
|---|
| 9 |
|
|---|
| 10 | GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
|
|---|
| 11 |
|
|---|
| 12 | let :title do
|
|---|
| 13 | GPG_KEY_ID
|
|---|
| 14 | end
|
|---|
| 15 |
|
|---|
| 16 | describe 'normal operation' do
|
|---|
| 17 | describe 'default options' do
|
|---|
| 18 | it 'contains the apt_key' do
|
|---|
| 19 | is_expected.to contain_apt_key(title).with({
|
|---|
| 20 | :id => title,
|
|---|
| 21 | :ensure => 'present',
|
|---|
| 22 | :source => nil,
|
|---|
| 23 | :server => 'keyserver.ubuntu.com',
|
|---|
| 24 | :content => nil,
|
|---|
| 25 | :options => nil,
|
|---|
| 26 | })
|
|---|
| 27 | end
|
|---|
| 28 | it 'contains the apt_key present anchor' do
|
|---|
| 29 | is_expected.to contain_anchor("apt_key #{title} present")
|
|---|
| 30 | end
|
|---|
| 31 | end
|
|---|
| 32 |
|
|---|
| 33 | describe 'title and key =>' do
|
|---|
| 34 | let :title do
|
|---|
| 35 | 'puppetlabs'
|
|---|
| 36 | end
|
|---|
| 37 |
|
|---|
| 38 | let :params do {
|
|---|
| 39 | :id => GPG_KEY_ID,
|
|---|
| 40 | } end
|
|---|
| 41 |
|
|---|
| 42 | it 'contains the apt_key' do
|
|---|
| 43 | is_expected.to contain_apt_key(title).with({
|
|---|
| 44 | :id => GPG_KEY_ID,
|
|---|
| 45 | :ensure => 'present',
|
|---|
| 46 | :source => nil,
|
|---|
| 47 | :server => 'keyserver.ubuntu.com',
|
|---|
| 48 | :content => nil,
|
|---|
| 49 | :options => nil,
|
|---|
| 50 | })
|
|---|
| 51 | end
|
|---|
| 52 | it 'contains the apt_key present anchor' do
|
|---|
| 53 | is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present")
|
|---|
| 54 | end
|
|---|
| 55 | end
|
|---|
| 56 |
|
|---|
| 57 | describe 'ensure => absent' do
|
|---|
| 58 | let :params do {
|
|---|
| 59 | :ensure => 'absent',
|
|---|
| 60 | } end
|
|---|
| 61 |
|
|---|
| 62 | it 'contains the apt_key' do
|
|---|
| 63 | is_expected.to contain_apt_key(title).with({
|
|---|
| 64 | :id => title,
|
|---|
| 65 | :ensure => 'absent',
|
|---|
| 66 | :source => nil,
|
|---|
| 67 | :server => 'keyserver.ubuntu.com',
|
|---|
| 68 | :content => nil,
|
|---|
| 69 | :keyserver => nil,
|
|---|
| 70 | })
|
|---|
| 71 | end
|
|---|
| 72 | it 'contains the apt_key absent anchor' do
|
|---|
| 73 | is_expected.to contain_anchor("apt_key #{title} absent")
|
|---|
| 74 | end
|
|---|
| 75 | end
|
|---|
| 76 |
|
|---|
| 77 | describe 'set a bunch of things!' do
|
|---|
| 78 | let :params do {
|
|---|
| 79 | :content => 'GPG key content',
|
|---|
| 80 | :source => 'http://apt.puppetlabs.com/pubkey.gpg',
|
|---|
| 81 | :server => 'pgp.mit.edu',
|
|---|
| 82 | :options => 'debug',
|
|---|
| 83 | } end
|
|---|
| 84 |
|
|---|
| 85 | it 'contains the apt_key' do
|
|---|
| 86 | is_expected.to contain_apt_key(title).with({
|
|---|
| 87 | :id => title,
|
|---|
| 88 | :ensure => 'present',
|
|---|
| 89 | :source => 'http://apt.puppetlabs.com/pubkey.gpg',
|
|---|
| 90 | :server => 'pgp.mit.edu',
|
|---|
| 91 | :content => params[:content],
|
|---|
| 92 | :options => 'debug',
|
|---|
| 93 | })
|
|---|
| 94 | end
|
|---|
| 95 | it 'contains the apt_key present anchor' do
|
|---|
| 96 | is_expected.to contain_anchor("apt_key #{title} present")
|
|---|
| 97 | end
|
|---|
| 98 | end
|
|---|
| 99 |
|
|---|
| 100 | context "domain with dash" do
|
|---|
| 101 | let(:params) do{
|
|---|
| 102 | :server => 'p-gp.m-it.edu',
|
|---|
| 103 | } end
|
|---|
| 104 | it 'contains the apt_key' do
|
|---|
| 105 | is_expected.to contain_apt_key(title).with({
|
|---|
| 106 | :id => title,
|
|---|
| 107 | :server => 'p-gp.m-it.edu',
|
|---|
| 108 | })
|
|---|
| 109 | end
|
|---|
| 110 | end
|
|---|
| 111 |
|
|---|
| 112 | context "url" do
|
|---|
| 113 | let :params do
|
|---|
| 114 | {
|
|---|
| 115 | :server => 'hkp://pgp.mit.edu',
|
|---|
| 116 | }
|
|---|
| 117 | end
|
|---|
| 118 | it 'contains the apt_key' do
|
|---|
| 119 | is_expected.to contain_apt_key(title).with({
|
|---|
| 120 | :id => title,
|
|---|
| 121 | :server => 'hkp://pgp.mit.edu',
|
|---|
| 122 | })
|
|---|
| 123 | end
|
|---|
| 124 | end
|
|---|
| 125 | context "url with port number" do
|
|---|
| 126 | let :params do
|
|---|
| 127 | {
|
|---|
| 128 | :server => 'hkp://pgp.mit.edu:80',
|
|---|
| 129 | }
|
|---|
| 130 | end
|
|---|
| 131 | it 'contains the apt_key' do
|
|---|
| 132 | is_expected.to contain_apt_key(title).with({
|
|---|
| 133 | :id => title,
|
|---|
| 134 | :server => 'hkp://pgp.mit.edu:80',
|
|---|
| 135 | })
|
|---|
| 136 | end
|
|---|
| 137 | end
|
|---|
| 138 | end
|
|---|
| 139 |
|
|---|
| 140 | describe 'validation' do
|
|---|
| 141 | context "domain begin with dash" do
|
|---|
| 142 | let(:params) do{
|
|---|
| 143 | :server => '-pgp.mit.edu',
|
|---|
| 144 | } end
|
|---|
| 145 | it 'fails' do
|
|---|
| 146 | expect { subject.call } .to raise_error(/does not match/)
|
|---|
| 147 | end
|
|---|
| 148 | end
|
|---|
| 149 |
|
|---|
| 150 | context "domain begin with dot" do
|
|---|
| 151 | let(:params) do{
|
|---|
| 152 | :server => '.pgp.mit.edu',
|
|---|
| 153 | } end
|
|---|
| 154 | it 'fails' do
|
|---|
| 155 | expect { subject.call } .to raise_error(/does not match/)
|
|---|
| 156 | end
|
|---|
| 157 | end
|
|---|
| 158 |
|
|---|
| 159 | context "domain end with dot" do
|
|---|
| 160 | let(:params) do{
|
|---|
| 161 | :server => "pgp.mit.edu.",
|
|---|
| 162 | } end
|
|---|
| 163 | it 'fails' do
|
|---|
| 164 | expect { subject.call } .to raise_error(/does not match/)
|
|---|
| 165 | end
|
|---|
| 166 | end
|
|---|
| 167 | context "exceed character url" do
|
|---|
| 168 | let :params do
|
|---|
| 169 | {
|
|---|
| 170 | :server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
|
|---|
| 171 | }
|
|---|
| 172 | end
|
|---|
| 173 | it 'fails' do
|
|---|
| 174 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 175 | end
|
|---|
| 176 | end
|
|---|
| 177 | context "incorrect port number url" do
|
|---|
| 178 | let :params do
|
|---|
| 179 | {
|
|---|
| 180 | :server => 'hkp://pgp.mit.edu:8008080'
|
|---|
| 181 | }
|
|---|
| 182 | end
|
|---|
| 183 | it 'fails' do
|
|---|
| 184 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 185 | end
|
|---|
| 186 | end
|
|---|
| 187 | context "incorrect protocol for url" do
|
|---|
| 188 | let :params do
|
|---|
| 189 | {
|
|---|
| 190 | :server => 'abc://pgp.mit.edu:80'
|
|---|
| 191 | }
|
|---|
| 192 | end
|
|---|
| 193 | it 'fails' do
|
|---|
| 194 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 195 | end
|
|---|
| 196 | end
|
|---|
| 197 | context "missing port number url" do
|
|---|
| 198 | let :params do
|
|---|
| 199 | {
|
|---|
| 200 | :server => 'hkp://pgp.mit.edu:'
|
|---|
| 201 | }
|
|---|
| 202 | end
|
|---|
| 203 | it 'fails' do
|
|---|
| 204 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 205 | end
|
|---|
| 206 | end
|
|---|
| 207 | context "url ending with a dot" do
|
|---|
| 208 | let :params do
|
|---|
| 209 | {
|
|---|
| 210 | :server => 'hkp://pgp.mit.edu.'
|
|---|
| 211 | }
|
|---|
| 212 | end
|
|---|
| 213 | it 'fails' do
|
|---|
| 214 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 215 | end
|
|---|
| 216 | end
|
|---|
| 217 | context "url begin with a dash" do
|
|---|
| 218 | let(:params) do{
|
|---|
| 219 | :server => "hkp://-pgp.mit.edu",
|
|---|
| 220 | } end
|
|---|
| 221 | it 'fails' do
|
|---|
| 222 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 223 | end
|
|---|
| 224 | end
|
|---|
| 225 | context 'invalid key' do
|
|---|
| 226 | let :title do
|
|---|
| 227 | 'Out of rum. Why? Why are we out of rum?'
|
|---|
| 228 | end
|
|---|
| 229 | it 'fails' do
|
|---|
| 230 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 231 | end
|
|---|
| 232 | end
|
|---|
| 233 |
|
|---|
| 234 | context 'invalid source' do
|
|---|
| 235 | let :params do {
|
|---|
| 236 | :source => 'afp://puppetlabs.com/key.gpg',
|
|---|
| 237 | } end
|
|---|
| 238 | it 'fails' do
|
|---|
| 239 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 240 | end
|
|---|
| 241 | end
|
|---|
| 242 |
|
|---|
| 243 | context 'invalid content' do
|
|---|
| 244 | let :params do {
|
|---|
| 245 | :content => [],
|
|---|
| 246 | } end
|
|---|
| 247 | it 'fails' do
|
|---|
| 248 | expect { subject.call }.to raise_error(/is not a string/)
|
|---|
| 249 | end
|
|---|
| 250 | end
|
|---|
| 251 |
|
|---|
| 252 | context 'invalid server' do
|
|---|
| 253 | let :params do {
|
|---|
| 254 | :server => 'two bottles of rum',
|
|---|
| 255 | } end
|
|---|
| 256 | it 'fails' do
|
|---|
| 257 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 258 | end
|
|---|
| 259 | end
|
|---|
| 260 |
|
|---|
| 261 | context 'invalid options' do
|
|---|
| 262 | let :params do {
|
|---|
| 263 | :options => {},
|
|---|
| 264 | } end
|
|---|
| 265 | it 'fails' do
|
|---|
| 266 | expect { subject.call }.to raise_error(/is not a string/)
|
|---|
| 267 | end
|
|---|
| 268 | end
|
|---|
| 269 |
|
|---|
| 270 | context 'invalid ensure' do
|
|---|
| 271 | let :params do
|
|---|
| 272 | {
|
|---|
| 273 | :ensure => 'foo',
|
|---|
| 274 | }
|
|---|
| 275 | end
|
|---|
| 276 | it 'fails' do
|
|---|
| 277 | expect { subject.call }.to raise_error(/does not match/)
|
|---|
| 278 | end
|
|---|
| 279 | end
|
|---|
| 280 |
|
|---|
| 281 | describe 'duplication' do
|
|---|
| 282 | context 'two apt::key resources for same key, different titles' do
|
|---|
| 283 | let :pre_condition do
|
|---|
| 284 | "class { 'apt': }
|
|---|
| 285 | apt::key { 'duplicate': id => '#{title}', }"
|
|---|
| 286 | end
|
|---|
| 287 |
|
|---|
| 288 | it 'contains two apt::key resources' do
|
|---|
| 289 | is_expected.to contain_apt__key('duplicate').with({
|
|---|
| 290 | :id => title,
|
|---|
| 291 | :ensure => 'present',
|
|---|
| 292 | })
|
|---|
| 293 | is_expected.to contain_apt__key(title).with({
|
|---|
| 294 | :id => title,
|
|---|
| 295 | :ensure => 'present',
|
|---|
| 296 | })
|
|---|
| 297 | end
|
|---|
| 298 |
|
|---|
| 299 | it 'contains only a single apt_key' do
|
|---|
| 300 | is_expected.to contain_apt_key('duplicate').with({
|
|---|
| 301 | :id => title,
|
|---|
| 302 | :ensure => 'present',
|
|---|
| 303 | :source => nil,
|
|---|
| 304 | :server => 'keyserver.ubuntu.com',
|
|---|
| 305 | :content => nil,
|
|---|
| 306 | :options => nil,
|
|---|
| 307 | })
|
|---|
| 308 | is_expected.not_to contain_apt_key(title)
|
|---|
| 309 | end
|
|---|
| 310 | end
|
|---|
| 311 |
|
|---|
| 312 | context 'two apt::key resources, different ensure' do
|
|---|
| 313 | let :pre_condition do
|
|---|
| 314 | "class { 'apt': }
|
|---|
| 315 | apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
|
|---|
| 316 | end
|
|---|
| 317 | it 'informs the user of the impossibility' do
|
|---|
| 318 | expect { subject.call }.to raise_error(/already ensured as absent/)
|
|---|
| 319 | end
|
|---|
| 320 | end
|
|---|
| 321 | end
|
|---|
| 322 | end
|
|---|
| 323 | end
|
|---|