X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fpuppet%2Ftype%2Fapt_key_spec.rb;h=b20a09a101b4499c89b8a4f0f32b8d353710b693;hb=c5259f83ad20d120d502d8541c75f4ee6021fec8;hp=e412b5066478284b291b016871f9ba17e7e2d13c;hpb=fd71aedda76f60e87b3a996ab22e9f92af560ec2;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/unit/puppet/type/apt_key_spec.rb b/spec/unit/puppet/type/apt_key_spec.rb index e412b50..b20a09a 100644 --- a/spec/unit/puppet/type/apt_key_spec.rb +++ b/spec/unit/puppet/type/apt_key_spec.rb @@ -1,17 +1,22 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet' -describe Puppet::Type::type(:apt_key) do - context 'only namevar 32bit key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30' - )} +describe Puppet::Type.type(:apt_key) do + context 'with only namevar 32bit key id' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + ) + end + it 'id is set' do - expect(resource[:id]).to eq '4BD6EC30' + expect(resource[:id]).to eq 'EF8D349F' end it 'name is set to id' do - expect(resource[:name]).to eq '4BD6EC30' + expect(resource[:name]).to eq 'EF8D349F' end it 'keyserver is default' do @@ -25,69 +30,110 @@ describe Puppet::Type::type(:apt_key) do it 'content is not set' do expect(resource[:content]).to eq nil end + + it 'refresh is not set' do + expect(resource[:refresh]).to eq nil + end + + it 'weak_ssl is not set' do + expect(resource[:weak_ssl]).to eq nil + end end context 'with a lowercase 32bit key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '4bd6ec30' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'ef8d349f', + ) + end + it 'id is set' do - expect(resource[:id]).to eq '4BD6EC30' + expect(resource[:id]).to eq 'EF8D349F' end end context 'with a 64bit key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => 'FFFFFFFF4BD6EC30' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'FFFFFFFFEF8D349F', + ) + end + it 'id is set' do - expect(resource[:id]).to eq 'FFFFFFFF4BD6EC30' + expect(resource[:id]).to eq 'FFFFFFFFEF8D349F' end end context 'with a 0x formatted key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '0x4BD6EC30' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xEF8D349F', + ) + end + it 'id is set' do - expect(resource[:id]).to eq '4BD6EC30' + expect(resource[:id]).to eq 'EF8D349F' end end context 'with a 0x formatted lowercase key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '0x4bd6ec30' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xef8d349f', + ) + end + it 'id is set' do - expect(resource[:id]).to eq '4BD6EC30' + expect(resource[:id]).to eq 'EF8D349F' end end context 'with a 0x formatted 64bit key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '0xFFFFFFFF4BD6EC30' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xFFFFFFFFEF8D349F', + ) + end + it 'id is set' do - expect(resource[:id]).to eq 'FFFFFFFF4BD6EC30' + expect(resource[:id]).to eq 'FFFFFFFFEF8D349F' end end context 'with source' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'http://apt.puppetlabs.com/pubkey.gpg' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + ) + end it 'source is set to the URL' do expect(resource[:source]).to eq 'http://apt.puppetlabs.com/pubkey.gpg' end end + context 'with source and weak_ssl' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'https://apt.puppetlabs.com/pubkey.gpg', + weak_ssl: true, + ) + end + + it 'source is set to the URL' do + expect(resource[:source]).to eq 'https://apt.puppetlabs.com/pubkey.gpg' + end + end + context 'with content' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :content => 'http://apt.puppetlabs.com/pubkey.gpg' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + content: 'http://apt.puppetlabs.com/pubkey.gpg', + ) + end it 'content is set to the string' do expect(resource[:content]).to eq 'http://apt.puppetlabs.com/pubkey.gpg' @@ -95,87 +141,105 @@ describe Puppet::Type::type(:apt_key) do end context 'with keyserver' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :server => 'http://keyring.debian.org' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + server: 'http://keyring.debian.org', + ) + end it 'keyserver is set to Debian' do expect(resource[:server]).to eq 'http://keyring.debian.org' end end - context 'validation' do + context 'with validation' do it 'raises an error if content and source are set' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :content => 'Completely invalid as a GPG key' - )}.to raise_error(/content and source are mutually exclusive/) + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + content: 'Completely invalid as a GPG key') + }.to raise_error(%r{content and source are mutually exclusive}) + end + + it 'raises an error if refresh => true and ensure => absent' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + ensure: :absent, + refresh: :true) + }.to raise_error(%r{ensure => absent and refresh => true are mutually exclusive}) end it 'raises an error if a weird length key is used' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'F4BD6EC30', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :content => 'Completely invalid as a GPG key' - )}.to raise_error(/Valid values match/) + expect { + Puppet::Type.type(:apt_key).new(id: 'FEF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + content: 'Completely invalid as a GPG key') + }.to raise_error(%r{Valid values match}) end it 'raises an error when an invalid URI scheme is used in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'hkp://pgp.mit.edu' - )}.to raise_error(/Valid values match/) + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'hkp://pgp.mit.edu') + }.to raise_error(%r{Valid values match}) end it 'allows the http URI scheme in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'http://pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://pgp.mit.edu') + }.not_to raise_error + end + + it 'allows the http URI with username and password' do + expect { + Puppet::Type.type(:apt_key).new(id: '4BD6EC30', + source: 'http://testme:Password2@pgp.mit.edu') + }.not_to raise_error end it 'allows the https URI scheme in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'https://pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'https://pgp.mit.edu') + }.not_to raise_error end it 'allows the https URI with username and password' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'https://testme:Password2@pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'https://testme:Password2@pgp.mit.edu') + }.not_to raise_error end it 'allows the ftp URI scheme in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'ftp://pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'ftp://pgp.mit.edu') + }.not_to raise_error end it 'allows an absolute path in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => '/path/to/a/file' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: '/path/to/a/file') + }.not_to raise_error end it 'allows 5-digit ports' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'http://pgp.mit.edu:12345/key' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://pgp.mit.edu:12345/key') + }.not_to raise_error end it 'allows 5-digit ports when using key servers' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :server => 'http://pgp.mit.edu:12345' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + server: 'http://pgp.mit.edu:12345') + }.not_to raise_error end end end