]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
apt_key now really works with userinfo for http(s)
authorSimon Effenberg <simon.effenberg@olx.com>
Tue, 13 Sep 2016 13:21:15 +0000 (15:21 +0200)
committerSimon Effenberg <simon.effenberg@olx.com>
Tue, 13 Sep 2016 13:33:16 +0000 (15:33 +0200)
now http and https sources for apt_key can take a userinfo
as it should be already since #384

```
apt_key { '...':
  source => 'https://username:password@myhost.com/mypath/key.gpg'
  ..
}
```

lib/puppet/provider/apt_key/apt_key.rb
spec/acceptance/apt_key_provider_spec.rb
spec/unit/puppet/type/apt_key_spec.rb

index a6d68b1732dd4c0be547c0ce3bfe604aeae5ed04..d7e85dafaf5a1e6ab762153f137394a49cc52d47 100644 (file)
@@ -127,7 +127,9 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do
       f
     else
       begin
-        key = parsedValue.read
+        user_pass = parsedValue.userinfo.nil? ? nil : parsedValue.userinfo.split(':')
+        parsedValue.userinfo = ''
+        key = open(parsedValue, :http_basic_authentication => user_pass).read
       rescue OpenURI::HTTPError, Net::FTPPermError => e
         fail("#{e.message} for #{resource[:source]}")
       rescue SocketError
index 1661a2bfacfdf9e6648d046ce75d3961b5223a1a..7fab2a5fddf73a78336290b8d1231c296c0a3376 100644 (file)
@@ -482,6 +482,20 @@ ZTQcCD53HcBLvKX6RJ4ByYawKaQqMa27WK/YWVmFXqVDVk12iKrQW6zktDdGInnD
         shell(PUPPETLABS_KEY_CHECK_COMMAND)
       end
 
+      it 'works with userinfo' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => 'http://dummyuser:dummypassword@#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+
       it 'fails with a 404' do
         pp = <<-EOS
         apt_key { 'puppetlabs':
@@ -575,6 +589,20 @@ ZTQcCD53HcBLvKX6RJ4ByYawKaQqMa27WK/YWVmFXqVDVk12iKrQW6zktDdGInnD
         shell(PUPPETLABS_KEY_CHECK_COMMAND)
       end
 
+      it 'works with userinfo' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => 'https://dummyuser:dummypassword@#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+
       it 'fails with a 404' do
         pp = <<-EOS
         apt_key { 'puppetlabs':
index e412b5066478284b291b016871f9ba17e7e2d13c..b17c8aed0ddb8056e704eacd557780f7eb671a95 100644 (file)
@@ -136,6 +136,13 @@ describe Puppet::Type::type(:apt_key) do
       )}.to_not 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'
+      )}.to_not raise_error
+    end
+
     it 'allows the https URI scheme in source' do
       expect { Puppet::Type.type(:apt_key).new(
         :id      => '4BD6EC30',