Merge pull request #304 from innyso/allow_url_for_key_server
Allow url for key server
This commit is contained in:
commit
345aef1d01
4 changed files with 188 additions and 29 deletions
|
@ -60,10 +60,10 @@ Puppet::Type.newtype(:apt_key) do
|
|||
end
|
||||
|
||||
newparam(:server) do
|
||||
desc 'The key server to fetch the key from based on the ID.'
|
||||
desc 'The key server to fetch the key from based on the ID. It can either be a domain name or url.'
|
||||
defaultto :'keyserver.ubuntu.com'
|
||||
# Need to validate this, preferably through stdlib is_fqdn
|
||||
# but still working on getting to that.
|
||||
|
||||
newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,4})?$/)
|
||||
end
|
||||
|
||||
newparam(:keyserver_options) do
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
# [*key_server*]
|
||||
# _default_: +undef+
|
||||
#
|
||||
# The keyserver from where to fetch our GPG key. It defaults to
|
||||
# The keyserver from where to fetch our GPG key. It can either be a domain
|
||||
# name or url. It defaults to
|
||||
# undef which results in apt_key's default keyserver being used,
|
||||
# currently +keyserver.ubuntu.com+.
|
||||
#
|
||||
|
@ -68,9 +69,7 @@ define apt::key (
|
|||
}
|
||||
|
||||
if $key_server {
|
||||
if !is_domain_name($key_server) {
|
||||
fail('$key_server must be a valid domain name')
|
||||
}
|
||||
validate_re($key_server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,4})?$'])
|
||||
}
|
||||
|
||||
if $key_options {
|
||||
|
|
|
@ -192,6 +192,22 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
|
|||
end
|
||||
end
|
||||
|
||||
context 'hkp://pgp.mit.edu:80' do
|
||||
it 'works' do
|
||||
pp = <<-EOS
|
||||
apt_key { 'puppetlabs':
|
||||
id => '#{PUPPETLABS_GPG_KEY_ID}',
|
||||
ensure => 'present',
|
||||
server => 'hkp://pgp.mit.edu:80',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
|
||||
end
|
||||
end
|
||||
|
||||
context 'nonexistant.key.server' do
|
||||
it 'fails' do
|
||||
pp = <<-EOS
|
||||
|
@ -207,6 +223,22 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'key server start with dot' do
|
||||
it 'fails' do
|
||||
pp = <<-EOS
|
||||
apt_key { 'puppetlabs':
|
||||
id => '#{PUPPETLABS_GPG_KEY_ID}',
|
||||
ensure => 'present',
|
||||
server => '.pgp.key.server',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true) do |r|
|
||||
expect(r.stderr).to match(/Invalid value \".pgp.key.server\"/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'source =>' do
|
||||
|
|
|
@ -142,31 +142,159 @@ describe 'apt::key', :type => :define do
|
|||
end
|
||||
|
||||
describe 'key_server =>' do
|
||||
let :params do {
|
||||
:key_server => 'pgp.mit.edu',
|
||||
} end
|
||||
context 'domain name' do
|
||||
let :params do {
|
||||
:key_server => 'pgp.mit.edu',
|
||||
} end
|
||||
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'pgp.mit.edu',
|
||||
})
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'pgp.mit.edu',
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:ensure => 'present',
|
||||
:source => nil,
|
||||
:server => params[:key_server],
|
||||
:content => nil,
|
||||
:keyserver_options => nil,
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key present anchor' do
|
||||
should contain_anchor("apt_key #{title} present")
|
||||
end
|
||||
end
|
||||
|
||||
context "domain with dash" do
|
||||
let(:params) do{
|
||||
:key_server => 'p-gp.m-it.edu',
|
||||
} end
|
||||
it "should contain apt::key" do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'p-gp.m-it.edu',
|
||||
})
|
||||
end
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:ensure => 'present',
|
||||
:source => nil,
|
||||
:server => params[:key_server],
|
||||
:content => nil,
|
||||
:keyserver_options => nil,
|
||||
})
|
||||
|
||||
context "domain begin with dash" do
|
||||
let(:params) do{
|
||||
:key_server => '-pgp.mit.edu',
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject } .to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
it 'contains the apt_key present anchor' do
|
||||
should contain_anchor("apt_key #{title} present")
|
||||
|
||||
context "domain begin with dot" do
|
||||
let(:params) do{
|
||||
:key_server => '.pgp.mit.edu',
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject } .to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "domain end with dot" do
|
||||
let(:params) do{
|
||||
:key_server => "pgp.mit.edu.",
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject } .to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
|
||||
context "url" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgp.mit.edu',
|
||||
} end
|
||||
it "should contain apt::key" do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'hkp://pgp.mit.edu',
|
||||
})
|
||||
end
|
||||
end
|
||||
context "url with port number" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgp.mit.edu:80',
|
||||
} end
|
||||
it "should contain apt::key" do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'hkp://pgp.mit.edu:80',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context "incorrect port number url" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgp.mit.edu:8008080'
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "incorrect protocol for url" do
|
||||
let (:params) do{
|
||||
:key_server => 'abc://pgp.mit.edu:80'
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "missing port number url" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgp.mit.edu:'
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "url ending with a dot" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgp.mit.edu.'
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "url begin with a dash" do
|
||||
let(:params) do{
|
||||
:key_server => "hkp://-pgp.mit.edu",
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "url with dash" do
|
||||
let(:params) do{
|
||||
:key_server => 'hkp://p-gp.m-it.edu',
|
||||
} end
|
||||
it "should contain apt::key" do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'hkp://p-gp.m-it.edu',
|
||||
})
|
||||
end
|
||||
end
|
||||
context "exceed characher url" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'key_options =>' do
|
||||
let :params do {
|
||||
|
@ -229,7 +357,7 @@ describe 'apt::key', :type => :define do
|
|||
:key_server => 'two bottles of rum',
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/must be a valid domain name/)
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue