From f65e6081dc8492e141b5c38ea9d25fa2f718b5a1 Mon Sep 17 00:00:00 2001 From: Salim Alam Date: Wed, 29 Jul 2015 10:12:58 -0700 Subject: [PATCH 1/2] Allow spaces in windows package sources --- libraries/windows_helper.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libraries/windows_helper.rb b/libraries/windows_helper.rb index 2dfe6903..890acdf9 100644 --- a/libraries/windows_helper.rb +++ b/libraries/windows_helper.rb @@ -63,13 +63,23 @@ def win_version @win_version ||= Windows::Version.new end + # Helper function to properly parse a URI + def as_uri(source) + begin + URI.parse(source) + rescue URI::InvalidURIError + Chef::Log.warn("#{source} was an invalid URI. Trying to escape invalid characters") + URI.parse(URI.escape(source)) + end + end + # if a file is local it returns a windows friendly path version # if a file is remote it caches it locally def cached_file(source, checksum=nil, windows_path=true) @installer_file_path ||= begin - if source =~ ::URI::ABS_URI && %w[ftp http https].include?(URI.parse(source).scheme) - uri = ::URI.parse(source) + if source =~ /^(file|ftp|http|https):\/\// + uri = as_uri(source) cache_file_path = "#{Chef::Config[:file_cache_path]}/#{::File.basename(::URI.unescape(uri.path))}" Chef::Log.debug("Caching a copy of file #{source} at #{cache_file_path}") r = Chef::Resource::RemoteFile.new(cache_file_path, run_context) From 8dcec6ab014064354d1736326e16209b3256725a Mon Sep 17 00:00:00 2001 From: Salim Alam Date: Wed, 29 Jul 2015 10:17:15 -0700 Subject: [PATCH 2/2] Add test for windows package --- .kitchen.yml | 6 +++++- test/cookbooks/minimal/recipes/package.rb | 10 ++++++++++ .../package/pester/minimal.package.Tests.ps1 | 11 +++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/cookbooks/minimal/recipes/package.rb create mode 100644 test/integration/package/pester/minimal.package.Tests.ps1 diff --git a/.kitchen.yml b/.kitchen.yml index 32b5f76a..f13f9937 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -45,4 +45,8 @@ suites: - name: certificate run_list: - recipe[windows::default] - - recipe[minimal::certificate] \ No newline at end of file + - recipe[minimal::certificate] + - name: package + run_list: + - recipe[windows::default] + - recipe[minimal::package] \ No newline at end of file diff --git a/test/cookbooks/minimal/recipes/package.rb b/test/cookbooks/minimal/recipes/package.rb new file mode 100644 index 00000000..176ab05e --- /dev/null +++ b/test/cookbooks/minimal/recipes/package.rb @@ -0,0 +1,10 @@ +remote_file 'C:\\Firefox Setup 5.0.exe' do + source 'http://archive.mozilla.org/pub/mozilla.org/mozilla.org/firefox/releases/5.0/win32/en-US/Firefox%20Setup%205.0.exe' +end + +windows_package 'Mozilla Firefox 5.0 (x86 en-US)' do + source 'file:///C:/Firefox Setup 5.0.exe' + options '-ms' + installer_type :custom + action :install +end diff --git a/test/integration/package/pester/minimal.package.Tests.ps1 b/test/integration/package/pester/minimal.package.Tests.ps1 new file mode 100644 index 00000000..0d94a2fa --- /dev/null +++ b/test/integration/package/pester/minimal.package.Tests.ps1 @@ -0,0 +1,11 @@ +$global:progressPreference = 'SilentlyContinue' + +describe 'minimal::package' { + context 'minimal_package' { + + it "task 'task_for_system' was created" { + Test-Path "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" | Should Be True + } + } +} +