Don't truncate to short keys in the type
authorMorgan Haskel <morgan@puppetlabs.com>
Wed, 1 Oct 2014 17:55:41 +0000 (12:55 -0500)
committerMorgan Haskel <morgan@puppetlabs.com>
Wed, 1 Oct 2014 18:40:25 +0000 (13:40 -0500)
You should be able to create/delete keys using the long key to avoid
collisions, and truncating in the type makes that not work.

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

index e5020fe27dd0647702dba262c62b2df3eaa28033..3ef94315089634cb75eb5f8cefa8886be20e09cc 100644 (file)
@@ -57,7 +57,12 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do
   def self.prefetch(resources)
     apt_keys = instances
     resources.keys.each do |name|
-      if provider = apt_keys.find{ |key| key.name == name }
+      if name.length == 16
+        shortname=name[8..-1]
+      else
+        shortname=name
+      end
+      if provider = apt_keys.find{ |key| key.name == shortname }
         resources[name].provider = provider
       end
     end
index e2cb8d9cf92695dded9d331b627dc7759abc9092..f55247314cc6f650bab39dd13735bcdda3b9dc3e 100644 (file)
@@ -36,11 +36,7 @@ Puppet::Type.newtype(:apt_key) do
       else
         id = value.upcase
       end
-      if id.length == 16
-        id[8..-1]
-      else
-        id
-      end
+      id
     end
   end
 
index 0f20174d062cde85336e4c5229f0708f56e5d672..69f7a930f6c1b80668f8d0ae6ad4341310ae3486 100644 (file)
@@ -1,14 +1,19 @@
 require 'spec_helper_acceptance'
 
-PUPPETLABS_GPG_KEY_ID   = '4BD6EC30'
-PUPPETLABS_APT_URL      = 'apt.puppetlabs.com'
-PUPPETLABS_GPG_KEY_FILE = 'pubkey.gpg'
-CENTOS_GPG_KEY_ID       = 'C105B9DE'
-CENTOS_REPO_URL         = 'ftp.cvut.cz/centos'
-CENTOS_GPG_KEY_FILE     = 'RPM-GPG-KEY-CentOS-6'
+PUPPETLABS_GPG_KEY_ID        = '4BD6EC30'
+PUPPETLABS_GPG_LONG_KEY_ID   = '1054B7A24BD6EC30'
+PUPPETLABS_APT_URL           = 'apt.puppetlabs.com'
+PUPPETLABS_GPG_KEY_FILE      = 'pubkey.gpg'
+CENTOS_GPG_KEY_ID            = 'C105B9DE'
+CENTOS_REPO_URL              = 'ftp.cvut.cz/centos'
+CENTOS_GPG_KEY_FILE          = 'RPM-GPG-KEY-CentOS-6'
 
 describe 'apt_key' do
   before(:each) do
+    # Delete twice to make sure everything is cleaned
+    # up after the short key collision
+    shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}",
+          :acceptable_exit_codes => [0,1,2])
     shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}",
           :acceptable_exit_codes => [0,1,2])
   end
@@ -36,7 +41,7 @@ describe 'apt_key' do
           EOS
 
           apply_manifest(pp, :catch_failures => true)
-          apply_manifest(pp, :catch_failures => true)
+          apply_manifest(pp, :catch_changes => true)
           shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
         end
       end
@@ -69,7 +74,7 @@ describe 'apt_key' do
 
         # Install the key first
         shell("apt-key adv --keyserver keyserver.ubuntu.com \
-              --recv-keys #{PUPPETLABS_GPG_KEY_ID}")
+              --recv-keys #{PUPPETLABS_GPG_LONG_KEY_ID}")
         shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
 
         # Time to remove it using Puppet