winrm-fs 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4af545258de812839e8ff58480b26128f23b9335207bf62eafed48ef9220d0a
4
- data.tar.gz: b77310f1de5e0d6a8eb1cd2df45948ac4b848684c4646d25e75045cd8967a235
3
+ metadata.gz: d05124d9707360698af8a481ceed52404d37be0e94d61c0dd4213e8897c7dad1
4
+ data.tar.gz: 534fa08e728ca9ae6cfb1d050491bee12a5a3277bdfaa430aa6af5b700c6a9e5
5
5
  SHA512:
6
- metadata.gz: 2ba78d2418a7cab543ac316dced1053c935a07c56b052053f84dfaf8d676dd4600dffe51e5c040204e2ba6f83131fd90180513725135849e8eacda72e23e49bb
7
- data.tar.gz: fbb8b91d4283677593d68391d1be8e5d168230a1d82cfecbf3cf06c9a7dfa55adf4bac02d53e39c78c9a83a7a408abb0d0235d8c71b223f99581280bb0451e8e
6
+ metadata.gz: 8b661c26354acdbcc1f0b9a1dcfd650a2d267e5d16b118393a7e149d17b9054ff49f9c0f85294954b0202bbbbd6cf2fae7be3c93ee06a83dfeb76f1428aece7b
7
+ data.tar.gz: 69a2d826fc4cb883939cc63d172f76975b9a1598c0923941a59ca266f0f2031f10ac712b214feb83d483d2d2d5b1adbc445ae2792764c6b098a5b5c58a2223e2
@@ -179,12 +179,12 @@ module WinRM
179
179
  zip_sha1 = sha1sum(zip_io.path)
180
180
 
181
181
  hash[zip_sha1] = {
182
- 'src' => dir,
182
+ 'src' => dir,
183
183
  'src_zip' => zip_io.path.to_s,
184
- 'zip_io' => zip_io,
185
- 'tmpzip' => "#{TEMP_UPLOAD_DIRECTORY}\\tmpzip-#{zip_sha1}.zip",
186
- 'dst' => "#{remote}\\#{File.basename(dir)}",
187
- 'size' => File.size(zip_io.path)
184
+ 'zip_io' => zip_io,
185
+ 'tmpzip' => "#{TEMP_UPLOAD_DIRECTORY}\\tmpzip-#{zip_sha1}.zip",
186
+ 'dst' => "#{remote}\\#{File.basename(dir)}",
187
+ 'size' => File.size(zip_io.path)
188
188
  }
189
189
  end
190
190
 
@@ -197,9 +197,9 @@ module WinRM
197
197
  def add_file_hash!(hash, local, remote)
198
198
  logger.debug "creating hash for file #{remote}"
199
199
  hash[sha1sum(local)] = {
200
- 'src' => local,
201
- 'dst' => remote,
202
- 'size' => local.is_a?(StringIO) ? local.size : File.size(local)
200
+ 'src' => local,
201
+ 'dst' => remote,
202
+ 'size' => local.is_a?(StringIO) ? local.size : File.size(local)
203
203
  }
204
204
  end
205
205
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winrm-fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Neal
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-14 00:00:00.000000000 Z
12
+ date: 2018-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis
@@ -91,16 +91,22 @@ dependencies:
91
91
  name: rake
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '10.3'
97
+ - - "<"
98
+ - !ruby/object:Gem::Version
99
+ version: '13'
97
100
  type: :development
98
101
  prerelease: false
99
102
  version_requirements: !ruby/object:Gem::Requirement
100
103
  requirements:
101
- - - "~>"
104
+ - - ">="
102
105
  - !ruby/object:Gem::Version
103
106
  version: '10.3'
107
+ - - "<"
108
+ - !ruby/object:Gem::Version
109
+ version: '13'
104
110
  - !ruby/object:Gem::Dependency
105
111
  name: rspec
106
112
  requirement: !ruby/object:Gem::Requirement
@@ -140,20 +146,9 @@ extra_rdoc_files:
140
146
  - README.md
141
147
  - LICENSE
142
148
  files:
143
- - ".gitignore"
144
- - ".rspec"
145
- - ".rubocop.yml"
146
- - ".rubocop_todo.yml"
147
- - ".travis.yml"
148
- - Gemfile
149
149
  - LICENSE
150
150
  - README.md
151
- - Rakefile
152
- - VERSION
153
- - Vagrantfile
154
- - appveyor.yml
155
151
  - bin/rwinrmcp
156
- - changelog.md
157
152
  - lib/winrm-fs.rb
158
153
  - lib/winrm-fs/core/file_transporter.rb
159
154
  - lib/winrm-fs/core/tmp_zip.rb
@@ -167,15 +162,9 @@ files:
167
162
  - lib/winrm-fs/scripts/exists.ps1.erb
168
163
  - lib/winrm-fs/scripts/extract_files.ps1.erb
169
164
  - lib/winrm-fs/scripts/scripts.rb
170
- - spec/config-example.yml
171
- - spec/integration/file_manager_spec.rb
172
- - spec/integration/tmp_zip_spec.rb
173
- - spec/matchers.rb
174
- - spec/spec_helper.rb
175
- - spec/unit/tmp_zip_spec.rb
176
- - winrm-fs.gemspec
177
165
  homepage: http://github.com/WinRb/winrm-fs
178
- licenses: []
166
+ licenses:
167
+ - Apache-2.0
179
168
  metadata: {}
180
169
  post_install_message:
181
170
  rdoc_options:
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- *.swp
2
- *.gem
3
- pkg/*
4
- .rvmrc
5
- .idea
6
- .bundle
7
- spec/spec/creds*.json
8
- spec/config.yml
9
- traces/
10
- Gemfile.lock
11
- .vagrant
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
@@ -1,17 +0,0 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
- Naming/FileName:
4
- Exclude:
5
- - 'lib/winrm-fs.rb'
6
-
7
- Style/Encoding:
8
- Enabled: true
9
-
10
- Layout/EndOfLine:
11
- Enabled: false
12
-
13
- Metrics/LineLength:
14
- Max: 120
15
-
16
- Metrics/AbcSize:
17
- Max: 25
@@ -1,65 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2017-12-12 22:48:53 +0100 using RuboCop version 0.52.0.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 1
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: EnforcedStyle.
12
- # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
13
- Layout/IndentHeredoc:
14
- Exclude:
15
- - 'spec/matchers.rb'
16
-
17
- # Offense count: 6
18
- # Configuration parameters: CountComments, ExcludedMethods.
19
- Metrics/BlockLength:
20
- Max: 185
21
-
22
- # Offense count: 3
23
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
24
- # URISchemes: http, https
25
- Metrics/LineLength:
26
- Max: 106
27
-
28
- # Offense count: 4
29
- # Configuration parameters: Blacklist.
30
- # Blacklist: END, (?-mix:EO[A-Z]{1})
31
- Naming/HeredocDelimiterNaming:
32
- Exclude:
33
- - 'lib/winrm-fs/core/file_transporter.rb'
34
- - 'spec/matchers.rb'
35
- - 'winrm-fs.gemspec'
36
-
37
- # Offense count: 1
38
- # Configuration parameters: .
39
- # SupportedStyles: annotated, template, unannotated
40
- Style/FormatStringToken:
41
- EnforcedStyle: unannotated
42
-
43
- # Offense count: 4
44
- # Cop supports --auto-correct.
45
- # Configuration parameters: AutoCorrect, EnforcedStyle.
46
- # SupportedStyles: predicate, comparison
47
- Style/NumericPredicate:
48
- Exclude:
49
- - 'spec/**/*'
50
- - 'lib/winrm-fs/core/file_transporter.rb'
51
- - 'lib/winrm-fs/file_manager.rb'
52
-
53
- # Offense count: 1
54
- # Cop supports --auto-correct.
55
- # Configuration parameters: EnforcedStyle, AllowInnerSlashes.
56
- # SupportedStyles: slashes, percent_r, mixed
57
- Style/RegexpLiteral:
58
- Exclude:
59
- - 'lib/winrm-fs/core/tmp_zip.rb'
60
-
61
- # Offense count: 3
62
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
63
- # URISchemes: http, https
64
- Metrics/LineLength:
65
- Max: 106
@@ -1,10 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.0
4
- - 2.3.4
5
- - 2.4.1
6
-
7
- # This prevents testing branches that are created just for PRs
8
- branches:
9
- only:
10
- - master
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'rb-readline'
data/Rakefile DELETED
@@ -1,27 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'rspec/core/rake_task'
4
- require 'rubocop/rake_task'
5
-
6
- # Change to the directory of this file.
7
- Dir.chdir(File.expand_path(__dir__))
8
-
9
- # For gem creation and bundling
10
- require 'bundler/gem_tasks'
11
-
12
- RSpec::Core::RakeTask.new(:spec) do |task|
13
- task.pattern = 'spec/unit/*_spec.rb'
14
- task.rspec_opts = ['--color', '-f documentation']
15
- end
16
-
17
- # Run the integration test suite
18
- RSpec::Core::RakeTask.new(:integration) do |task|
19
- task.pattern = 'spec/integration/*_spec.rb'
20
- task.rspec_opts = ['--color', '-f documentation']
21
- end
22
-
23
- RuboCop::RakeTask.new
24
-
25
- task default: %i[spec rubocop]
26
-
27
- task all: %i[default integration]
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.3.1
@@ -1,8 +0,0 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- VAGRANTFILE_API_VERSION = '2'.freeze
5
-
6
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
7
- config.vm.box = 'mwrock/WindowsNano'
8
- end
@@ -1,38 +0,0 @@
1
- version: "master-{build}"
2
-
3
- os: Windows Server 2012 R2
4
- platform:
5
- - x64
6
-
7
- environment:
8
- winrm_user: test_user
9
- winrm_password: Pass@word1
10
-
11
- matrix:
12
- - ruby_version: "22"
13
- winrm_endpoint: http://localhost:5985/wsman
14
-
15
- clone_folder: c:\projects\winrm-fs
16
- clone_depth: 1
17
- branches:
18
- only:
19
- - master
20
-
21
- install:
22
- - ps: net user /add $env:winrm_user $env:winrm_password
23
- - ps: net localgroup administrators $env:winrm_user /add
24
- - ps: winrm set winrm/config/client/auth '@{Basic="true"}'
25
- - ps: winrm set winrm/config/service/auth '@{Basic="true"}'
26
- - ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
27
- - ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
28
- - ps: Write-Host $env:PATH
29
- - ps: ruby --version
30
- - ps: gem --version
31
- - ps: bundler --version
32
-
33
- build_script:
34
- - bundle install || bundle install || bundle install
35
-
36
- test_script:
37
- - SET SPEC_OPTS=--format progress
38
- - bundle exec rake integration
@@ -1,74 +0,0 @@
1
- # WinRM-fs Gem Changelog
2
- # 1.3.1
3
- - Download files in chunks
4
-
5
- # 1.3.0
6
- - Upload from StringIO object
7
- - Add missing winrm/exceptions require in file_transporter
8
- - Use correct way to relativize paths of Zip entries
9
-
10
- # 1.2.1
11
- - Correctly handle unicode filenames
12
-
13
- # 1.2.0
14
- - Add ability to download directories
15
-
16
- # 1.1.1
17
- - Remove empty items from powershell pipeline when extracting zip files
18
-
19
- # 1.1.0
20
- - Convert MD5 hashes to SHA1.
21
-
22
- # 1.0.2
23
- - Fix `Pathname.glob` expansion of shortnames.
24
-
25
- # 1.0.1
26
- - Call ClearScriptBlockCache to prevent OutOfMemoryExceptions ClearScriptBlockCache
27
-
28
- # 1.0.0
29
- - Using winrm v2. File uploads just got a whole lot faster!
30
-
31
- # 0.4.3
32
- - Fix error handling with wmf5, filtering out progress output from inspected stderr.
33
-
34
- # 0.4.2
35
- - Improved Powershell error handling in metadata checking.
36
-
37
- # 0.4.1
38
- - Fixes a regression on Windows 2008 R2/Windows 7 and below where the WinRM service corrupts the check files metadata resulting in malformed destination paths.
39
-
40
- # 0.4.0
41
- - Correct the destination path of individual files. Always assume it is the full destination path unless it is an existing directory. This may potentialy break some callers expecting the remote path to be a directory that winrm-fs will create if missing as the destination of the local file. A new directory will not be created and the local file will be uploaded directly to the remote path.
42
-
43
- # 0.3.2
44
- - Fix re-extraction of cached directories from temp folder when there is more than one "clean" directory deleted from destination
45
-
46
- # 0.3.1
47
- - Widen logging version constraints to include 2.0 (matching WinRM core gem)
48
-
49
- # 0.3.0
50
- - Jetisons `CommandExecutor` now living in the core WinRM gem and swaps in implementation currently used in the winrm-transport gem. These changes should have little visible effect on current consumers of the `FileManager` class with these exceptions:
51
- - BREAKING CHANGE: When uploading a directory and the destination directory exists on the endpoint, the source base directory will be created below the destination directory on the endpoint and the source directory contents will be unzipped to that location. Prior to this release, the contents of the source directory would be unzipped to an existing destination directory without creating the source base directory. This new behavior is more consistent with SCP and other well known shell copy commands.
52
- - `Upload` may now receive an array of source files and directories rather than just a single file or directory path.
53
-
54
- # 0.2.4
55
- - Fix issue 21, downloading files is extremely slow.
56
- - Add zip file creation debug logging.
57
-
58
- # 0.2.3
59
- - Fix yielding progress data, issue #23
60
-
61
- # 0.2.2
62
- - Fix powershell streams leaking to standard error breaking Windows 10, issue #18
63
-
64
- # 0.2.1
65
- - Fixed issue 16 creating zip file on Windows
66
-
67
- # 0.2.0
68
- - Redesigned temp zip file creation system
69
- - Fixed lots of small edge case issues especially with directory uploads
70
- - Simplified file manager upload method API to take only a single source file or directory
71
- - Expanded acceptable username and hostnames for rwinrmcp
72
-
73
- # 0.1.0
74
- - Initial alpha quality release
@@ -1,3 +0,0 @@
1
- endpoint: "http://localhost:55985/wsman"
2
- user: vagrant
3
- password: vagrant
@@ -1,303 +0,0 @@
1
- require 'pathname'
2
-
3
- # rubocop:disable BlockLength
4
- describe WinRM::FS::FileManager do
5
- let(:upload_dir) { "winrm_#{rand(2**16)}" }
6
- let(:dest_dir) { File.join(subject.temp_dir, upload_dir) }
7
- let(:temp_upload_dir) { '$env:TEMP/winrm-upload' }
8
- let(:spec_dir) { File.expand_path(File.dirname(File.dirname(__FILE__))) }
9
- let(:this_file) { Pathname.new(__FILE__) }
10
- let(:service) { winrm_connection }
11
-
12
- subject { WinRM::FS::FileManager.new(service) }
13
-
14
- before(:each) do
15
- expect(subject.delete(dest_dir)).to be true
16
- expect(subject.delete(temp_upload_dir)).to be true
17
- end
18
-
19
- context 'exists?' do
20
- it 'should exist' do
21
- expect(subject.exists?('c:/windows')).to be true
22
- expect(subject.exists?('c:/foobar')).to be false
23
- end
24
- end
25
-
26
- context 'create and delete dir' do
27
- it 'should create the directory recursively' do
28
- subdir = File.join(dest_dir, 'subdir1', 'subdir2')
29
- expect(subject.create_dir(subdir)).to be true
30
- expect(subject.exists?(subdir)).to be true
31
- expect(subject.create_dir(subdir)).to be true
32
- expect(subject.delete(subdir)).to be true
33
- expect(subject.exists?(subdir)).to be false
34
- end
35
- end
36
-
37
- context 'temp_dir' do
38
- it 'should return the remote users temp dir' do
39
- expect(subject.temp_dir).to match(%r{C:/Users/\S+/AppData/Local/Temp})
40
- end
41
- end
42
-
43
- context 'download file' do
44
- let(:download_dir) { File.join(spec_dir, 'temp') }
45
- let(:dest_file) { Pathname.new(File.join(dest_dir, File.basename(this_file))) }
46
- let(:download_file) { Pathname.new(File.join(download_dir, File.basename(this_file))) }
47
-
48
- before(:each) do
49
- expect(subject.delete(dest_dir)).to be true
50
- FileUtils.rm_rf(Dir.glob("#{download_dir}/*"))
51
- FileUtils.mkdir_p(download_dir)
52
- end
53
-
54
- it 'should download the specified file' do
55
- subject.upload(this_file, dest_file)
56
- subject.download(dest_file, download_file)
57
- expect(File.open(download_file).read).to eq(File.open(this_file).read)
58
- end
59
- end
60
-
61
- context 'download file chunked' do
62
- let(:download_dir) { File.join(spec_dir, 'temp') }
63
- let(:dest_file) { Pathname.new(File.join(dest_dir, File.basename(this_file))) }
64
- let(:download_file) { Pathname.new(File.join(download_dir, File.basename(this_file))) }
65
-
66
- before(:each) do
67
- expect(subject.delete(dest_dir)).to be true
68
- FileUtils.rm_rf(Dir.glob("#{download_dir}/*"))
69
- FileUtils.mkdir_p(download_dir)
70
- end
71
-
72
- it 'should download the specified file in 1000 byte chunks' do
73
- subject.upload(this_file, dest_file)
74
- subject.download(dest_file, download_file, 1000)
75
- expect(File.open(download_file).read).to eq(File.open(this_file).read)
76
- end
77
- end
78
-
79
- context 'download directory' do
80
- let(:download_dir) { File.join(spec_dir, 'temp') }
81
- let(:dest_file) { Pathname.new(File.join(dest_dir, File.basename(this_file))) }
82
- let(:root_dir) { File.expand_path('../../', File.dirname(__FILE__)) }
83
- let(:winrm_fs_dir) { File.join(root_dir, 'lib/winrm-fs') }
84
-
85
- before(:each) do
86
- expect(subject.delete(dest_dir)).to be true
87
- FileUtils.rm_rf(Dir.glob("#{download_dir}/*"))
88
- FileUtils.mkdir_p(download_dir)
89
- end
90
-
91
- it 'downloads the directory contents recursively' do
92
- subject.upload(winrm_fs_dir, dest_dir)
93
- subject.download(dest_dir, download_dir)
94
-
95
- Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
96
- host_file_rel = Pathname.new(host_file).relative_path_from(
97
- Pathname.new(winrm_fs_dir)
98
- ).to_s
99
- download_file = File.join(download_dir, upload_dir, host_file_rel)
100
- expect(File.open(download_file).read).to eq(File.open(host_file).read)
101
- end
102
- end
103
- end
104
-
105
- context 'upload file' do
106
- let(:dest_file) { Pathname.new(File.join(dest_dir, File.basename(this_file))) }
107
- let(:from_memory) { StringIO.new('Upload From Memory') }
108
-
109
- before(:each) do
110
- expect(subject.delete(dest_dir)).to be true
111
- end
112
-
113
- it 'should upload a single StringIO object to a remote file' do
114
- subject.upload(from_memory, dest_file)
115
- expect(subject).to have_created(dest_file).with_content(from_memory.string)
116
- end
117
-
118
- it 'should error if multiple StringIO objects passed to upload' do
119
- expect { subject.upload([from_memory, from_memory], dest_file) }
120
- .to raise_error(WinRM::FS::Core::UploadSourceError)
121
- end
122
-
123
- it 'should error if both a StringIO object and a file path passed to upload' do
124
- expect { subject.upload([from_memory, this_file], dest_file) }
125
- .to raise_error(WinRM::FS::Core::UploadSourceError)
126
- end
127
-
128
- it 'should upload the specified file' do
129
- subject.upload(this_file, dest_file)
130
- expect(subject).to have_created(dest_file).with_content(this_file)
131
- end
132
-
133
- it 'should upload to root of the c: drive' do
134
- subject.upload(this_file, 'c:/winrmtest.rb')
135
- expect(subject).to have_created('c:/winrmtest.rb').with_content(this_file)
136
- subject.delete('c:/winrmtest.rb')
137
- end
138
-
139
- it 'should upload just filename' do
140
- subject.upload(this_file, 'winrmtest.rb')
141
- expect(subject).to have_created('winrmtest.rb').with_content(this_file)
142
- subject.delete('winrmtest.rb')
143
- end
144
-
145
- it 'should upload using relative file path' do
146
- subject.upload('./spec/integration/file_manager_spec.rb', dest_file)
147
- expect(subject).to have_created(dest_file).with_content(this_file)
148
- end
149
-
150
- it 'should upload to the specified directory' do
151
- subject.create_dir(dest_dir)
152
- subject.upload(this_file, dest_dir)
153
- expect(subject).to have_created(dest_file).with_content(this_file)
154
- end
155
-
156
- it 'should treat extensionless target as file if not an existing directory' do
157
- subject.upload(this_file, dest_dir)
158
- expect(subject).to have_created(dest_dir).with_content(this_file)
159
- end
160
-
161
- it 'should create extensionless source under target dir if target dir exists' do
162
- subject.create_dir(dest_dir)
163
- src_file = File.expand_path('../../Gemfile', File.dirname(__FILE__))
164
- subject.upload(src_file, dest_dir)
165
- expect(subject).to have_created(File.join(dest_dir, 'Gemfile')).with_content(src_file)
166
- end
167
-
168
- it 'should upload to the specified directory with env var' do
169
- subject.upload(this_file, '$env:Temp')
170
- expected_dest_file = File.join(subject.temp_dir, File.basename(this_file))
171
- expect(subject).to have_created(expected_dest_file).with_content(this_file)
172
- end
173
-
174
- it 'should upload to Program Files sub dir' do
175
- subject.create_dir('$env:ProgramFiles/foo')
176
- subject.upload(this_file, '$env:ProgramFiles/foo')
177
- expect(subject).to have_created('c:/Program Files/foo/file_manager_spec.rb') \
178
- .with_content(this_file)
179
- end
180
-
181
- it 'should upload to the specified nested directory' do
182
- dest_sub_dir = File.join(dest_dir, 'subdir')
183
- subject.create_dir(dest_sub_dir)
184
- dest_sub_dir_file = File.join(dest_sub_dir, File.basename(this_file))
185
- subject.upload(this_file, dest_sub_dir)
186
- expect(subject).to have_created(dest_sub_dir_file).with_content(this_file)
187
- end
188
-
189
- it 'yields progress data' do
190
- block_called = false
191
- total_bytes_copied = 0
192
- total = subject.upload(this_file, dest_file) do |bytes_copied, total_bytes, local_path, remote_path|
193
- expect(total_bytes).to be > 0
194
- total_bytes_copied = bytes_copied
195
- expect(local_path).to eq(this_file.to_s)
196
- expect(remote_path).to eq(dest_file.to_s)
197
- block_called = true
198
- end
199
- expect(total_bytes_copied).to eq(total)
200
- expect(block_called).to be true
201
- expect(total).to be > 0
202
- end
203
-
204
- it 'should not upload when content matches' do
205
- subject.upload(this_file, dest_dir)
206
- bytes_uploaded = subject.upload(this_file, dest_dir)
207
- expect(bytes_uploaded).to eq 0
208
- end
209
-
210
- it 'should upload when content differs' do
211
- matchers_file = File.join(spec_dir, 'matchers.rb')
212
- subject.upload(matchers_file, dest_file)
213
- bytes_uploaded = subject.upload(this_file, dest_file)
214
- expect(bytes_uploaded).to be > 0
215
- end
216
-
217
- it 'raises WinRMUploadError when a bad source path is specified' do
218
- expect { subject.upload('c:/some/non-existant/path/foo', dest_file) }.to raise_error
219
- end
220
- end
221
-
222
- context 'upload empty file' do
223
- let(:empty_src_file) { Tempfile.new('empty') }
224
- let(:dest_file) { File.join(dest_dir, 'emptyfile.txt') }
225
-
226
- it 'creates a new empty file' do
227
- expect(subject.upload(empty_src_file.path, dest_file)).to be 0
228
- expect(subject).to have_created(dest_file).with_content('')
229
- end
230
-
231
- it 'overwrites an existing file' do
232
- expect(subject.upload(this_file, dest_file)).to be > 0
233
- expect(subject.upload(empty_src_file.path, dest_file)).to be 0
234
- expect(subject).to have_created(dest_file).with_content('')
235
- end
236
- end
237
-
238
- context 'upload directory' do
239
- let(:root_dir) { File.expand_path('../../', File.dirname(__FILE__)) }
240
- let(:winrm_fs_dir) { File.join(root_dir, 'lib/winrm-fs') }
241
- let(:core_dir) { File.join(root_dir, 'lib/winrm-fs/core') }
242
- let(:scripts_dir) { File.join(root_dir, 'lib/winrm-fs/scripts') }
243
-
244
- it 'copies the directory contents recursively when directory does not exist' do
245
- bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
246
- expect(bytes_uploaded).to be > 0
247
-
248
- Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
249
- host_file_rel = Pathname.new(host_file).relative_path_from(
250
- Pathname.new(winrm_fs_dir)
251
- ).to_s
252
- remote_file = File.join(dest_dir, host_file_rel)
253
- expect(subject).to have_created(remote_file).with_content(host_file)
254
- end
255
- end
256
-
257
- it 'copies the directory recursively when directory does exist' do
258
- subject.create_dir(dest_dir)
259
- bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
260
- expect(bytes_uploaded).to be > 0
261
-
262
- Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
263
- host_file_rel = Pathname.new(host_file).relative_path_from(
264
- Pathname.new(winrm_fs_dir).dirname
265
- ).to_s
266
- remote_file = File.join(dest_dir, host_file_rel)
267
- expect(subject).to have_created(remote_file).with_content(host_file)
268
- end
269
- end
270
-
271
- it 'does not copy the directory when content is the same' do
272
- subject.upload(winrm_fs_dir, dest_dir)
273
- bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
274
- expect(bytes_uploaded).to eq 0
275
- end
276
-
277
- it 'unzips the directory when cached content is the same' do
278
- subject.upload(winrm_fs_dir, dest_dir)
279
- subject.delete(dest_dir)
280
- expect(subject.exists?(dest_dir)).to be false
281
- subject.upload(winrm_fs_dir, dest_dir)
282
- expect(subject.exists?(dest_dir)).to be true
283
- end
284
-
285
- it 'unzips multiple directories when cached content is the same for all' do
286
- subject.create_dir(dest_dir)
287
- subject.upload([core_dir, scripts_dir], dest_dir)
288
- subject.delete(dest_dir)
289
- expect(subject.exists?(dest_dir)).to be false
290
- subject.create_dir(dest_dir)
291
- subject.upload([core_dir, scripts_dir], dest_dir)
292
- expect(subject.exists?(File.join(dest_dir, 'core'))).to be true
293
- expect(subject.exists?(File.join(dest_dir, 'scripts'))).to be true
294
- end
295
-
296
- it 'copies the directory when content differs' do
297
- subject.upload(winrm_fs_dir, dest_dir)
298
- bytes_uploaded = subject.upload(core_dir, dest_dir)
299
- expect(bytes_uploaded).to be > 0
300
- end
301
- end
302
- end
303
- # rubocop:enable BlockLength
@@ -1,26 +0,0 @@
1
- require_relative '../../lib/winrm-fs/core/tmp_zip'
2
-
3
- describe WinRM::FS::Core::TmpZip do
4
- let(:winrm_fs_dir) { File.expand_path('../../lib/winrm-fs', File.dirname(__FILE__)) }
5
-
6
- subject { WinRM::FS::Core::TmpZip.new(winrm_fs_dir) }
7
-
8
- context 'temp file creation' do
9
- it 'should create a temp file on disk' do
10
- path = subject.path
11
- expect(File.exist?(path)).to be true
12
- subject.unlink
13
- expect(File.exist?(path)).to be false
14
- end
15
- end
16
-
17
- context 'create zip' do
18
- it 'should add all files in directory to the zip recursively' do
19
- expect(subject).to contain_zip_entries([
20
- 'exceptions.rb',
21
- 'core/tmp_zip.rb',
22
- 'scripts/checksum.ps1.erb'
23
- ])
24
- end
25
- end
26
- end
@@ -1,57 +0,0 @@
1
- require 'rspec/expectations'
2
-
3
- RSpec::Matchers.define :have_created do |remote_file|
4
- match do |file_manager|
5
- if @expected_content
6
- downloaded_file = Tempfile.new('downloaded')
7
- downloaded_file.close
8
-
9
- subject.download(remote_file, downloaded_file.path)
10
- @actual_content = File.read(downloaded_file.path)
11
- downloaded_file.delete
12
-
13
- file_manager.exists?(remote_file) && \
14
- @actual_content == @expected_content
15
- else
16
- file_manager.exists?(remote_file)
17
- end
18
- end
19
- chain :with_content do |expected_content|
20
- expected_content = File.read(expected_content) if File.file?(expected_content)
21
- @expected_content = expected_content
22
- end
23
- failure_message do
24
- if @expected_content
25
- <<-EOH
26
- Expected file '#{remote_file}' to exist with content:
27
-
28
- #{@expected_content}
29
-
30
- but instead got content:
31
-
32
- #{@actual_content}
33
- EOH
34
- else
35
- "Expected file '#{remote_file}' to exist"
36
- end
37
- end
38
- end
39
-
40
- RSpec::Matchers.define :contain_zip_entries do |zip_entries|
41
- match do |temp_zip_file|
42
- zip_entries = [zip_entries] if zip_entries.is_a? String
43
- @zip_file = Zip::File.open(temp_zip_file.path)
44
- @missing_entries = []
45
- zip_entries.each do |entry|
46
- @missing_entries << entry unless @zip_file.find_entry(entry)
47
- end
48
- @missing_entries.empty?
49
- end
50
- failure_message do |temp_zip_file|
51
- msg = "Expected #{temp_zip_file.path} to contain zip entries: #{@missing_entries}\n Got: "
52
- @zip_file.each do |entry|
53
- msg << entry.name << ', '
54
- end
55
- msg
56
- end
57
- end
@@ -1,66 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'winrm-fs'
4
- require 'json'
5
- require_relative 'matchers'
6
-
7
- # Creates a WinRM connection for integration tests
8
- module ConnectionHelper
9
- def winrm_connection
10
- WinRM::Connection.new(config)
11
- end
12
-
13
- def config
14
- @config ||= begin
15
- cfg = symbolize_keys(YAML.safe_load(File.read(winrm_config_path)))
16
- cfg[:basic_auth_only] = true unless cfg[:transport].eql? :kerberos
17
- merge_environment!(cfg)
18
- cfg
19
- end
20
- end
21
-
22
- def merge_environment!(config)
23
- merge_config_option_from_environment(config, 'user')
24
- merge_config_option_from_environment(config, 'password')
25
- merge_config_option_from_environment(config, 'no_ssl_peer_verification')
26
- config[:options][:ssl_peer_fingerprint] = ENV['winrm_cert'] if ENV['use_ssl_peer_fingerprint']
27
- config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
28
- config[:transport] = ENV['winrm_transport'] if ENV['winrm_transport']
29
- end
30
-
31
- def merge_config_option_from_environment(config, key)
32
- env_key = 'winrm_' + key
33
- config[key.to_sym] = ENV[env_key] if ENV[env_key]
34
- end
35
-
36
- def winrm_config_path
37
- # Copy config-example.yml to config.yml and edit for your local configuration
38
- path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
39
- unless File.exist?(path)
40
- # user hasn't done this, so use sane defaults for unit tests
41
- path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
42
- end
43
- path
44
- end
45
-
46
- # rubocop:disable Metrics/MethodLength
47
- def symbolize_keys(hash)
48
- hash.each_with_object({}) do |(key, value), result|
49
- new_key = case key
50
- when String then key.to_sym
51
- else key
52
- end
53
- new_value = case value
54
- when Hash then symbolize_keys(value)
55
- else value
56
- end
57
- result[new_key] = new_value
58
- result
59
- end
60
- end
61
- # rubocop:enable Metrics/MethodLength
62
- end
63
-
64
- RSpec.configure do |config|
65
- config.include(ConnectionHelper)
66
- end
@@ -1,78 +0,0 @@
1
- #
2
- # Author:: Fletcher (<fnichol@nichol.ca>)
3
- #
4
- # Copyright (C) 2015, Fletcher Nichol
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the 'License');
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an 'AS IS' BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- require 'winrm-fs/core/tmp_zip'
19
-
20
- describe WinRM::FS::Core::TmpZip do
21
- let(:src_dir) do
22
- tmpdir = Pathname.new(Dir.mktmpdir)
23
- @tmpdirs << tmpdir
24
- src_dir = tmpdir.join('src')
25
- sub_dir = src_dir.join('veggies')
26
-
27
- src_dir.mkpath
28
- create_local_file(src_dir.join('apple.txt'), 'appleapple')
29
- create_local_file(src_dir.join('banana.txt'), 'bananabanana')
30
- create_local_file(src_dir.join('cherry.txt'), 'cherrycherry')
31
- sub_dir.mkpath
32
- create_local_file(sub_dir.join('carrot.txt'), 'carrotcarrot')
33
- src_dir
34
- end
35
-
36
- let(:tmp_zip) { WinRM::FS::Core::TmpZip.new(src_dir) }
37
-
38
- before { @tmpdirs = [] }
39
-
40
- after do
41
- @tmpdirs.each(&:rmtree)
42
- tmp_zip.unlink if tmp_zip.path
43
- end
44
-
45
- it '#path returns path to created zip file' do
46
- expect(tmp_zip.path.file?).to eq true
47
- end
48
-
49
- it '#unlink removes the file' do
50
- path = tmp_zip.path
51
- expect(path.file?).to eq true
52
-
53
- tmp_zip.unlink
54
-
55
- expect(path.file?).to eq false
56
- expect(tmp_zip.path).to eq nil
57
- end
58
-
59
- describe 'for a zip file containing the base directory' do
60
- let(:tmp_zip) { WinRM::FS::Core::TmpZip.new(src_dir) }
61
-
62
- it 'contains the input entries' do
63
- zip = Zip::File.new(tmp_zip.path)
64
-
65
- expect(zip.map(&:name).sort).to eq(
66
- ['apple.txt', 'banana.txt', 'cherry.txt', 'veggies/carrot.txt']
67
- )
68
- expect(zip.read('apple.txt')).to eq 'appleapple'
69
- expect(zip.read('banana.txt')).to eq 'bananabanana'
70
- expect(zip.read('cherry.txt')).to eq 'cherrycherry'
71
- expect(zip.read('veggies/carrot.txt')).to eq 'carrotcarrot'
72
- end
73
- end
74
-
75
- def create_local_file(path, content)
76
- path.open('wb') { |file| file.write(content) }
77
- end
78
- end
@@ -1,36 +0,0 @@
1
- require 'date'
2
-
3
- version = File.read(File.expand_path('VERSION', __dir__)).strip
4
-
5
- Gem::Specification.new do |s|
6
- s.platform = Gem::Platform::RUBY
7
- s.name = 'winrm-fs'
8
- s.version = version
9
- s.date = Date.today.to_s
10
-
11
- s.author = ['Shawn Neal', 'Matt Wrock']
12
- s.email = ['sneal@sneal.net', 'matt@mattwrock.com']
13
- s.homepage = 'http://github.com/WinRb/winrm-fs'
14
-
15
- s.summary = 'WinRM File System'
16
- s.description = <<-EOF
17
- Ruby library for file system operations via Windows Remote Management
18
- EOF
19
-
20
- s.files = `git ls-files`.split(/\n/)
21
- s.require_path = 'lib'
22
- s.rdoc_options = %w[-x test/ -x examples/]
23
- s.extra_rdoc_files = %w[README.md LICENSE]
24
-
25
- s.bindir = 'bin'
26
- s.executables = ['rwinrmcp']
27
- s.required_ruby_version = '>= 2.2.0'
28
- s.add_runtime_dependency 'erubis', '~> 2.7'
29
- s.add_runtime_dependency 'logging', ['>= 1.6.1', '< 3.0']
30
- s.add_runtime_dependency 'rubyzip', '~> 1.1'
31
- s.add_runtime_dependency 'winrm', '~> 2.0'
32
- s.add_development_dependency 'pry'
33
- s.add_development_dependency 'rake', '~> 10.3'
34
- s.add_development_dependency 'rspec', '~> 3.0'
35
- s.add_development_dependency 'rubocop', '~> 0.51'
36
- end