]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Adding dash to key_server validate regex
authorinnyso <mini.inny@gmail.com>
Mon, 9 Jun 2014 23:09:28 +0000 (00:09 +0100)
committerinnyso <mini.inny@gmail.com>
Tue, 10 Jun 2014 00:07:04 +0000 (01:07 +0100)
Dashes should be allow when defining domain or url for key_server. Rspec
test cases are included to make sure no malform domain name or url are
used.

lib/puppet/type/apt_key.rb
manifests/key.pp
spec/acceptance/apt_key_provider_spec.rb
spec/defines/key_spec.rb

index fa7b0c676c77e2c4c1d48eeaa37a1cd677a27076..e2cb8d9cf92695dded9d331b627dc7759abc9092 100644 (file)
@@ -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
index 231992b30ca5386c30c722a4fccaf28aa7044ec8..8d3bcf045c58f59df310046853e646b0c538191a 100644 (file)
@@ -69,7 +69,7 @@ define apt::key (
   }
 
   if $key_server {
-    validate_re($key_server,['\A((hkp|http|https):\/\/)?([a-z\d]{0,62}\.)+[a-z\d]+(:\d{2,4})?$'])
+    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 {
index 9becd2568419af3ac59f9c5e82ce78ba0dc2ae6f..573452e28b97a44f194a0d3aa0230930fbaf9cb1 100644 (file)
@@ -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
index c20d05d43a32a61d4aec6ed4cbd07e51917d11bb..005c95e4698ab6c426186e4d23b39e8fc4a92cc3 100644 (file)
@@ -169,6 +169,46 @@ describe 'apt::key', :type => :define do
        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
+
+      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
+
+      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
+
+      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',
@@ -218,7 +258,7 @@ describe 'apt::key', :type => :define do
           expect { subject }.to raise_error(/does not match/)
         end
       end
-      context "malform url" do
+      context "url ending with a dot" do
         let (:params) do{
           :key_server => 'hkp://pgp.mit.edu.'
         } end
@@ -226,6 +266,26 @@ describe 'apt::key', :type => :define 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'
@@ -234,7 +294,6 @@ describe 'apt::key', :type => :define do
           expect { subject }.to raise_error(/does not match/)
         end
       end
-
                end
 
     describe 'key_options =>' do