]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Allow url or domain name for key_server parameter
authorinnyso <mini.inny@gmail.com>
Thu, 29 May 2014 00:01:37 +0000 (01:01 +0100)
committeriso <inny.so@digital.cabinet-office.gov.uk>
Mon, 2 Jun 2014 17:05:20 +0000 (18:05 +0100)
As some places dont have port 11371 open, they are required to use URL as
key_server instead of domain name therefore adding the capability to use URL or
domain name as key_server parameter

manifests/key.pp
spec/defines/key_spec.rb

index 9ccbfcb6bbf6990a426f8664904a134f407fcc4f..231992b30ca5386c30c722a4fccaf28aa7044ec8 100644 (file)
@@ -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]{0,62}\.)+[a-z\d]+(:\d{2,4})?$'])
   }
 
   if $key_options {
index a85d1710b4e565b7f5bfdf33c19a7ab51791a460..c20d05d43a32a61d4aec6ed4cbd07e51917d11bb 100644 (file)
@@ -142,31 +142,100 @@ 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',
-        })
-      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,
-        })
+       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 "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
-      it 'contains the apt_key present anchor' do
-        should contain_anchor("apt_key #{title} present")
+
+      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 "malform 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 "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
+
+               end
 
     describe 'key_options =>' do
       let :params do {
@@ -229,7 +298,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