MODULES-2326 - Run Regexp.escape on the source URL
authorMorgan Haskel <morgan@puppetlabs.com>
Mon, 17 Aug 2015 19:14:18 +0000 (12:14 -0700)
committerMorgan Haskel <morgan@puppetlabs.com>
Mon, 17 Aug 2015 19:15:39 +0000 (12:15 -0700)
The URL can have special characters, making the regex match fail.

lib/puppet/provider/vcsrepo/git.rb
spec/acceptance/modules_2326_spec.rb [new file with mode: 0644]

index 7617b13..4623f8e 100644 (file)
@@ -111,7 +111,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
 
   def working_copy_exists?
     if @resource.value(:source) and File.exists?(File.join(@resource.value(:path), '.git', 'config'))
-      File.readlines(File.join(@resource.value(:path), '.git', 'config')).grep(/#{default_url}/).any?
+      File.readlines(File.join(@resource.value(:path), '.git', 'config')).grep(/#{Regexp.escape(default_url)}/).any?
     else
       File.directory?(File.join(@resource.value(:path), '.git'))
     end
diff --git a/spec/acceptance/modules_2326_spec.rb b/spec/acceptance/modules_2326_spec.rb
new file mode 100644 (file)
index 0000000..d62dbb0
--- /dev/null
@@ -0,0 +1,69 @@
+require 'spec_helper_acceptance'
+
+tmpdir = default.tmpdir('vcsrepo')
+
+describe 'clones with special characters' do
+
+  before(:all) do
+    my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+    shell("mkdir -p #{tmpdir}") # win test
+    scp_to(default, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
+    shell("cd #{tmpdir} && ./create_git_repo.sh")
+  end
+
+  after(:all) do
+    shell("rm -rf #{tmpdir}/testrepo.git")
+  end
+
+  context 'as a user with ssh' do
+    before(:all) do
+      # create user
+      pp = <<-EOS
+        group { 'testuser-ssh':
+          ensure => present,
+        }
+        user { 'testuser-ssh':
+          ensure     => present,
+          groups     => 'testuser-ssh',
+          managehome => true,
+        }
+      EOS
+      apply_manifest(pp, :catch_failures => true)
+
+      # create ssh keys
+      shell('mkdir -p /home/testuser-ssh/.ssh')
+      shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
+
+      # copy public key to authorized_keys
+      shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
+      shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
+      shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
+      shell("chown testuser-ssh:testuser-ssh #{tmpdir}")
+    end
+
+    it 'applies the manifest' do
+      pp = <<-EOS
+        vcsrepo { "#{tmpdir}/testrepo_user_ssh":
+          ensure   => present,
+          provider => git,
+          source   => "git+ssh://testuser-ssh@localhost#{tmpdir}/testrepo.git",
+          user     => 'testuser-ssh',
+        }
+      EOS
+
+      # Run it twice and test for idempotency
+      apply_manifest(pp, :catch_failures => true)
+      apply_manifest(pp, :catch_changes => true)
+    end
+
+    after(:all) do
+      pp = <<-EOS
+        user { 'testuser-ssh':
+          ensure     => absent,
+          managehome => true,
+        }
+      EOS
+      apply_manifest(pp, :catch_failures => true)
+    end
+  end
+end