winrm-fs 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.rspec +3 -3
- data/.rubocop.yml +9 -9
- data/.travis.yml +4 -4
- data/Gemfile +3 -3
- data/LICENSE +202 -202
- data/README.md +86 -86
- data/Rakefile +28 -28
- data/VERSION +1 -1
- data/Vagrantfile +9 -9
- data/appveyor.yml +39 -39
- data/bin/rwinrmcp +86 -86
- data/changelog.md +34 -31
- data/lib/winrm-fs.rb +28 -28
- data/lib/winrm-fs/core/file_transporter.rb +507 -506
- data/lib/winrm-fs/core/tmp_zip.rb +166 -166
- data/lib/winrm-fs/exceptions.rb +28 -28
- data/lib/winrm-fs/file_manager.rb +117 -117
- data/lib/winrm-fs/scripts/check_files.ps1.erb +48 -48
- data/lib/winrm-fs/scripts/checksum.ps1.erb +13 -13
- data/lib/winrm-fs/scripts/create_dir.ps1.erb +6 -6
- data/lib/winrm-fs/scripts/decode_files.ps1.erb +58 -59
- data/lib/winrm-fs/scripts/delete.ps1.erb +6 -6
- data/lib/winrm-fs/scripts/download.ps1.erb +8 -8
- data/lib/winrm-fs/scripts/exists.ps1.erb +8 -8
- data/lib/winrm-fs/scripts/scripts.rb +31 -31
- data/spec/config-example.yml +4 -4
- data/spec/integration/file_manager_spec.rb +203 -191
- data/spec/integration/tmp_zip_spec.rb +26 -26
- data/spec/matchers.rb +58 -58
- data/spec/spec_helper.rb +72 -72
- data/spec/unit/file_transporter_spec.rb +819 -819
- data/spec/unit/tmp_zip_spec.rb +79 -79
- data/winrm-fs.gemspec +37 -37
- metadata +2 -2
@@ -1,48 +1,48 @@
|
|
1
|
-
$hash_file = "<%= hash_file %>"
|
2
|
-
|
3
|
-
Function Cleanup($o) { if (($o -ne $null) -and ($o.GetType().GetMethod("Dispose") -ne $null)) { $o.Dispose() } }
|
4
|
-
|
5
|
-
Function Decode-Base64File($src, $dst) {
|
6
|
-
Try {
|
7
|
-
$in = (Get-Item $src).OpenRead()
|
8
|
-
$b64 = New-Object -TypeName System.Security.Cryptography.FromBase64Transform
|
9
|
-
$m = [System.Security.Cryptography.CryptoStreamMode]::Read
|
10
|
-
$d = New-Object -TypeName System.Security.Cryptography.CryptoStream $in,$b64,$m
|
11
|
-
Copy-Stream $d ($out = [System.IO.File]::OpenWrite($dst))
|
12
|
-
} Finally { Cleanup $in; Cleanup $out; Cleanup $d }
|
13
|
-
}
|
14
|
-
|
15
|
-
Function Copy-Stream($src, $dst) { $b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
|
16
|
-
|
17
|
-
Function Check-Files($h) {
|
18
|
-
return $h.GetEnumerator() | ForEach-Object {
|
19
|
-
$dst = Unresolve-Path $_.Key
|
20
|
-
New-Object psobject -Property @{
|
21
|
-
chk_exists = ($exists = Test-Path $dst -PathType Leaf)
|
22
|
-
src_md5 = ($sMd5 = $_.Value)
|
23
|
-
dst_md5 = ($dMd5 = if ($exists) { Get-MD5Sum $dst } else { $null })
|
24
|
-
chk_dirty = ($dirty = if ($sMd5 -ne $dMd5) { $true } else { $false })
|
25
|
-
verifies = if ($dirty -eq $false) { $true } else { $false }
|
26
|
-
}
|
27
|
-
} | Select-Object -Property chk_exists,src_md5,dst_md5,chk_dirty,verifies
|
28
|
-
}
|
29
|
-
|
30
|
-
Function Get-MD5Sum($src) {
|
31
|
-
Try {
|
32
|
-
$c = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
|
33
|
-
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead()))
|
34
|
-
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower()
|
35
|
-
} Finally { Cleanup $c; Cleanup $in }
|
36
|
-
}
|
37
|
-
|
38
|
-
Function Invoke-Input($in) {
|
39
|
-
$in = Unresolve-Path $in
|
40
|
-
Decode-Base64File $in ($decoded = "$($in).ps1")
|
41
|
-
$expr = Get-Content $decoded | Out-String
|
42
|
-
Remove-Item $in,$decoded -Force
|
43
|
-
return Invoke-Expression "$expr"
|
44
|
-
}
|
45
|
-
|
46
|
-
Function Unresolve-Path($p) { if ($p -eq $null) { return $null } else { return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p) } }
|
47
|
-
|
48
|
-
Check-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation
|
1
|
+
$hash_file = "<%= hash_file %>"
|
2
|
+
|
3
|
+
Function Cleanup($o) { if (($o -ne $null) -and ($o.GetType().GetMethod("Dispose") -ne $null)) { $o.Dispose() } }
|
4
|
+
|
5
|
+
Function Decode-Base64File($src, $dst) {
|
6
|
+
Try {
|
7
|
+
$in = (Get-Item $src).OpenRead()
|
8
|
+
$b64 = New-Object -TypeName System.Security.Cryptography.FromBase64Transform
|
9
|
+
$m = [System.Security.Cryptography.CryptoStreamMode]::Read
|
10
|
+
$d = New-Object -TypeName System.Security.Cryptography.CryptoStream $in,$b64,$m
|
11
|
+
Copy-Stream $d ($out = [System.IO.File]::OpenWrite($dst))
|
12
|
+
} Finally { Cleanup $in; Cleanup $out; Cleanup $d }
|
13
|
+
}
|
14
|
+
|
15
|
+
Function Copy-Stream($src, $dst) { $b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
|
16
|
+
|
17
|
+
Function Check-Files($h) {
|
18
|
+
return $h.GetEnumerator() | ForEach-Object {
|
19
|
+
$dst = Unresolve-Path $_.Key
|
20
|
+
New-Object psobject -Property @{
|
21
|
+
chk_exists = ($exists = Test-Path $dst -PathType Leaf)
|
22
|
+
src_md5 = ($sMd5 = $_.Value)
|
23
|
+
dst_md5 = ($dMd5 = if ($exists) { Get-MD5Sum $dst } else { $null })
|
24
|
+
chk_dirty = ($dirty = if ($sMd5 -ne $dMd5) { $true } else { $false })
|
25
|
+
verifies = if ($dirty -eq $false) { $true } else { $false }
|
26
|
+
}
|
27
|
+
} | Select-Object -Property chk_exists,src_md5,dst_md5,chk_dirty,verifies
|
28
|
+
}
|
29
|
+
|
30
|
+
Function Get-MD5Sum($src) {
|
31
|
+
Try {
|
32
|
+
$c = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
|
33
|
+
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead()))
|
34
|
+
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower()
|
35
|
+
} Finally { Cleanup $c; Cleanup $in }
|
36
|
+
}
|
37
|
+
|
38
|
+
Function Invoke-Input($in) {
|
39
|
+
$in = Unresolve-Path $in
|
40
|
+
Decode-Base64File $in ($decoded = "$($in).ps1")
|
41
|
+
$expr = Get-Content $decoded | Out-String
|
42
|
+
Remove-Item $in,$decoded -Force
|
43
|
+
return Invoke-Expression "$expr"
|
44
|
+
}
|
45
|
+
|
46
|
+
Function Unresolve-Path($p) { if ($p -eq $null) { return $null } else { return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p) } }
|
47
|
+
|
48
|
+
Check-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation
|
@@ -1,13 +1,13 @@
|
|
1
|
-
$p = $ExecutionContext.SessionState.Path
|
2
|
-
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
-
|
4
|
-
if (Test-Path $path -PathType Leaf) {
|
5
|
-
$cryptoProv = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
|
6
|
-
$file = [System.IO.File]::Open($path,
|
7
|
-
[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
|
8
|
-
$md5 = ([System.BitConverter]::ToString($cryptoProv.ComputeHash($file)))
|
9
|
-
$md5 = $md5.Replace("-","").ToLower()
|
10
|
-
$file.Close()
|
11
|
-
|
12
|
-
Write-Output $md5
|
13
|
-
}
|
1
|
+
$p = $ExecutionContext.SessionState.Path
|
2
|
+
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
+
|
4
|
+
if (Test-Path $path -PathType Leaf) {
|
5
|
+
$cryptoProv = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
|
6
|
+
$file = [System.IO.File]::Open($path,
|
7
|
+
[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
|
8
|
+
$md5 = ([System.BitConverter]::ToString($cryptoProv.ComputeHash($file)))
|
9
|
+
$md5 = $md5.Replace("-","").ToLower()
|
10
|
+
$file.Close()
|
11
|
+
|
12
|
+
Write-Output $md5
|
13
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
$p = $ExecutionContext.SessionState.Path
|
2
|
-
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
-
if (!(Test-Path $path)) {
|
4
|
-
New-Item -ItemType Directory -Force -Path $path | Out-Null
|
5
|
-
}
|
6
|
-
exit 0
|
1
|
+
$p = $ExecutionContext.SessionState.Path
|
2
|
+
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
+
if (!(Test-Path $path)) {
|
4
|
+
New-Item -ItemType Directory -Force -Path $path | Out-Null
|
5
|
+
}
|
6
|
+
exit 0
|
@@ -1,59 +1,58 @@
|
|
1
|
-
trap {$e = $_.Exception; $e.InvocationInfo.ScriptName; do {$e.Message; $e = $e.InnerException} while ($e); break;}
|
2
|
-
$
|
3
|
-
function
|
4
|
-
function
|
5
|
-
function
|
6
|
-
function
|
7
|
-
function Test-
|
8
|
-
function
|
9
|
-
function
|
10
|
-
function
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
$
|
17
|
-
|
18
|
-
|
19
|
-
$
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
$
|
24
|
-
|
25
|
-
}
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
$
|
40
|
-
$
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
$
|
49
|
-
$dst_parent
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
$hash_file
|
59
|
-
Decode-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation
|
1
|
+
trap {$e = $_.Exception; $e.InvocationInfo.ScriptName; do {$e.Message; $e = $e.InnerException} while ($e); break;}
|
2
|
+
function Decode-Base64File($src, $dst) {folder (split-path $dst);sc -force -Encoding Byte -Path $dst -Value ([Convert]::FromBase64String([IO.File]::ReadAllLines($src)))}
|
3
|
+
function Copy-Stream($src, $dst) {$b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
|
4
|
+
function Resolve-ProviderPath{ $input | % {if ($_){(Resolve-Path $_).ProviderPath} else{$null}} }
|
5
|
+
function Get-FrameworkVersion { "Full", "Client" | % {([version](gp "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\$_").Version)} | select -first 1}
|
6
|
+
function Test-NETStack($Version){ Get-FrameworkVersion -ge $Version }
|
7
|
+
function Test-IOCompression {($PSVersionTable.PSVersion.Major -ge 3) -and (Test-NETStack '4.5')}
|
8
|
+
function folder($path){ $path | ? {-not (test-path $_)} | % {$null = mkdir $_}}
|
9
|
+
function disposable($o){($o -is [IDisposable]) -and (($o | gm | %{$_.name}) -contains 'Dispose')}
|
10
|
+
function use($obj, [scriptblock]$sb){try {& $sb} catch [exception]{throw $_} finally {if (disposable $obj) {$obj.Dispose()}} }
|
11
|
+
set-alias RPP -Value Resolve-ProviderPath
|
12
|
+
|
13
|
+
Function Decode-Files($hash) {
|
14
|
+
foreach ($key in $hash.keys) {
|
15
|
+
$value = $hash[$key]
|
16
|
+
$tmp, $tzip, $dst = $Key, $Value["tmpzip"], $Value["dst"]
|
17
|
+
if(!$tmp.StartsWith("clean")) {
|
18
|
+
$sMd5 = (gi $tmp).BaseName.Replace("b64-", "")
|
19
|
+
$decoded = if ($tzip -ne $null) { $tzip } else { $dst }
|
20
|
+
Decode-Base64File $tmp $decoded
|
21
|
+
rm $tmp -Force
|
22
|
+
$dMd5 = Get-MD5Sum $decoded
|
23
|
+
$verifies = $sMd5 -like $dMd5
|
24
|
+
}
|
25
|
+
if ($tzip) {Unzip-File $tzip $dst}
|
26
|
+
New-Object psobject -Property @{dst=$dst;verifies=$verifies;src_md5=$sMd5;dst_md5=$dMd5;tmpfile=$tmp;tmpzip=$tzip}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
Function Get-MD5Sum($src) {
|
31
|
+
if ($src -and (test-path $src)) {
|
32
|
+
use ($c = New-Object -TypeName Security.Cryptography.MD5CryptoServiceProvider) {
|
33
|
+
use ($in = (gi $src).OpenRead()) {([BitConverter]::ToString($c.ComputeHash($in))).Replace("-", "").ToLower()}}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
Function Invoke-Input($in) {
|
38
|
+
$in = $in | rpp
|
39
|
+
$d = "$($in).ps1"
|
40
|
+
Decode-Base64File $in $d
|
41
|
+
$expr = gc $d | Out-String
|
42
|
+
rm $in,$d -Force
|
43
|
+
iex "$expr"
|
44
|
+
}
|
45
|
+
|
46
|
+
Function Unzip-File($src, $dst) {
|
47
|
+
$unpack = $src -replace '\.zip'
|
48
|
+
$dst_parent = Split-Path -Path $dst -Parent
|
49
|
+
if(!(Test-Path $dst_parent)) { $dst = $dst_parent }
|
50
|
+
folder $unpack, $dst
|
51
|
+
if (Test-IOCompression) {Add-Type -AN System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::ExtractToDirectory($src, $unpack)}
|
52
|
+
else {Try {$s = New-Object -ComObject Shell.Application; ($s.NameSpace($unpack)).CopyHere(($s.NameSpace($src)).Items(), 0x610)} Finally {[void][Runtime.Interopservices.Marshal]::ReleaseComObject($s)}}
|
53
|
+
dir $unpack | cp -dest "$dst/" -force -recurse
|
54
|
+
rm $unpack -recurse -force
|
55
|
+
}
|
56
|
+
|
57
|
+
$hash_file = "<%= hash_file %>"
|
58
|
+
Decode-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation
|
@@ -1,6 +1,6 @@
|
|
1
|
-
$p = $ExecutionContext.SessionState.Path
|
2
|
-
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
-
if (Test-Path $path) {
|
4
|
-
Remove-Item $path -Force -Recurse
|
5
|
-
}
|
6
|
-
exit 0
|
1
|
+
$p = $ExecutionContext.SessionState.Path
|
2
|
+
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
+
if (Test-Path $path) {
|
4
|
+
Remove-Item $path -Force -Recurse
|
5
|
+
}
|
6
|
+
exit 0
|
@@ -1,8 +1,8 @@
|
|
1
|
-
$p = $ExecutionContext.SessionState.Path
|
2
|
-
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
-
if (Test-Path $path -PathType Leaf) {
|
4
|
-
$bytes = [System.convert]::ToBase64String([System.IO.File]::ReadAllBytes($path))
|
5
|
-
Write-Host $bytes
|
6
|
-
exit 0
|
7
|
-
}
|
8
|
-
exit 1
|
1
|
+
$p = $ExecutionContext.SessionState.Path
|
2
|
+
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
+
if (Test-Path $path -PathType Leaf) {
|
4
|
+
$bytes = [System.convert]::ToBase64String([System.IO.File]::ReadAllBytes($path))
|
5
|
+
Write-Host $bytes
|
6
|
+
exit 0
|
7
|
+
}
|
8
|
+
exit 1
|
@@ -1,8 +1,8 @@
|
|
1
|
-
$p = $ExecutionContext.SessionState.Path
|
2
|
-
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
-
if (Test-Path $path) {
|
4
|
-
exit 0
|
5
|
-
}
|
6
|
-
else {
|
7
|
-
exit 1
|
8
|
-
}
|
1
|
+
$p = $ExecutionContext.SessionState.Path
|
2
|
+
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
+
if (Test-Path $path) {
|
4
|
+
exit 0
|
5
|
+
}
|
6
|
+
else {
|
7
|
+
exit 1
|
8
|
+
}
|
@@ -1,31 +1,31 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Copyright 2015 Shawn Neal <sneal@sneal.net>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require 'erubis'
|
18
|
-
|
19
|
-
module WinRM
|
20
|
-
module FS
|
21
|
-
# PS1 scripts
|
22
|
-
module Scripts
|
23
|
-
def self.render(template, context)
|
24
|
-
template_path = File.expand_path(
|
25
|
-
"#{File.dirname(__FILE__)}/#{template}.ps1.erb")
|
26
|
-
template = File.read(template_path)
|
27
|
-
Erubis::Eruby.new(template).result(context)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2015 Shawn Neal <sneal@sneal.net>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'erubis'
|
18
|
+
|
19
|
+
module WinRM
|
20
|
+
module FS
|
21
|
+
# PS1 scripts
|
22
|
+
module Scripts
|
23
|
+
def self.render(template, context)
|
24
|
+
template_path = File.expand_path(
|
25
|
+
"#{File.dirname(__FILE__)}/#{template}.ps1.erb")
|
26
|
+
template = File.read(template_path)
|
27
|
+
Erubis::Eruby.new(template).result(context)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/config-example.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
auth_type: plaintext
|
2
|
-
endpoint: "http://192.168.137.20:5985/wsman"
|
3
|
-
options:
|
4
|
-
user: vagrant
|
1
|
+
auth_type: plaintext
|
2
|
+
endpoint: "http://192.168.137.20:5985/wsman"
|
3
|
+
options:
|
4
|
+
user: vagrant
|
5
5
|
pass: vagrant
|
@@ -1,191 +1,203 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'pathname'
|
3
|
-
|
4
|
-
describe WinRM::FS::FileManager do
|
5
|
-
let(:dest_dir) { File.join(subject.temp_dir, "winrm_#{rand(2**16)}") }
|
6
|
-
let(:temp_upload_dir) { '$env:TEMP/winrm-upload' }
|
7
|
-
let(:spec_dir) { File.expand_path(File.dirname(File.dirname(__FILE__))) }
|
8
|
-
let(:this_file) { __FILE__ }
|
9
|
-
let(:service) { winrm_connection }
|
10
|
-
|
11
|
-
subject { WinRM::FS::FileManager.new(service) }
|
12
|
-
|
13
|
-
before(:each) do
|
14
|
-
expect(subject.delete(dest_dir)).to be true
|
15
|
-
expect(subject.delete(temp_upload_dir)).to be true
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'exists?' do
|
19
|
-
it 'should exist' do
|
20
|
-
expect(subject.exists?('c:/windows')).to be true
|
21
|
-
expect(subject.exists?('c:/foobar')).to be false
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'create and delete dir' do
|
26
|
-
it 'should create the directory recursively' do
|
27
|
-
subdir = File.join(dest_dir, 'subdir1', 'subdir2')
|
28
|
-
expect(subject.create_dir(subdir)).to be true
|
29
|
-
expect(subject.exists?(subdir)).to be true
|
30
|
-
expect(subject.create_dir(subdir)).to be true
|
31
|
-
expect(subject.delete(subdir)).to be true
|
32
|
-
expect(subject.exists?(subdir)).to be false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'temp_dir' do
|
37
|
-
it 'should return the remote users temp dir' do
|
38
|
-
expect(subject.temp_dir).to match(%r{C:/Users/\S+/AppData/Local/Temp})
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'upload file' do
|
43
|
-
let(:dest_file) { File.join(dest_dir, File.basename(this_file)) }
|
44
|
-
|
45
|
-
before(:each) do
|
46
|
-
expect(subject.delete(dest_dir)).to be true
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should upload the specified file' do
|
50
|
-
subject.upload(this_file, dest_file)
|
51
|
-
expect(subject).to have_created(dest_file).with_content(this_file)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should upload to root of the c: drive' do
|
55
|
-
subject.upload(this_file, 'c:/winrmtest.rb')
|
56
|
-
expect(subject).to have_created('c:/winrmtest.rb').with_content(this_file)
|
57
|
-
subject.delete('c:/winrmtest.rb')
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should upload using relative file path' do
|
61
|
-
subject.upload('./spec/integration/file_manager_spec.rb', dest_file)
|
62
|
-
expect(subject).to have_created(dest_file).with_content(this_file)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should upload to the specified directory' do
|
66
|
-
subject.upload(this_file, dest_dir)
|
67
|
-
expect(subject).to have_created(dest_file).with_content(this_file)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should upload to the specified directory with env var' do
|
71
|
-
subject.upload(this_file, '$env:Temp')
|
72
|
-
expected_dest_file = File.join(subject.temp_dir, File.basename(this_file))
|
73
|
-
expect(subject).to have_created(expected_dest_file).with_content(this_file)
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'should upload to Program Files sub dir' do
|
77
|
-
subject.upload(this_file, '$env:ProgramFiles/foo')
|
78
|
-
expect(subject).to have_created('c:/Program Files/foo/file_manager_spec.rb') \
|
79
|
-
.with_content(this_file)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should upload to the specified nested directory' do
|
83
|
-
dest_sub_dir = File.join(dest_dir, 'subdir')
|
84
|
-
dest_sub_dir_file = File.join(dest_sub_dir, File.basename(this_file))
|
85
|
-
subject.upload(this_file, dest_sub_dir)
|
86
|
-
expect(subject).to have_created(dest_sub_dir_file).with_content(this_file)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'yields progress data' do
|
90
|
-
block_called = false
|
91
|
-
total_bytes_copied = 0
|
92
|
-
total = subject.upload(this_file, dest_file) do \
|
93
|
-
|bytes_copied, total_bytes, local_path, remote_path|
|
94
|
-
expect(total_bytes).to be > 0
|
95
|
-
total_bytes_copied = bytes_copied
|
96
|
-
expect(local_path).to eq(this_file)
|
97
|
-
expect(remote_path).to eq(dest_file)
|
98
|
-
block_called = true
|
99
|
-
end
|
100
|
-
expect(total_bytes_copied).to eq(total)
|
101
|
-
expect(block_called).to be true
|
102
|
-
expect(total).to be > 0
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should not upload when content matches' do
|
106
|
-
subject.upload(this_file, dest_dir)
|
107
|
-
bytes_uploaded = subject.upload(this_file, dest_dir)
|
108
|
-
expect(bytes_uploaded).to eq 0
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'should upload when content differs' do
|
112
|
-
matchers_file = File.join(spec_dir, 'matchers.rb')
|
113
|
-
subject.upload(matchers_file, dest_file)
|
114
|
-
bytes_uploaded = subject.upload(this_file, dest_file)
|
115
|
-
expect(bytes_uploaded).to be > 0
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'raises WinRMUploadError when a bad source path is specified' do
|
119
|
-
expect { subject.upload('c:/some/non-existant/path/foo', dest_file) }.to raise_error
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'upload empty file' do
|
124
|
-
let(:empty_src_file) { Tempfile.new('empty') }
|
125
|
-
let(:dest_file) { File.join(dest_dir, 'emptyfile.txt') }
|
126
|
-
|
127
|
-
it 'creates a new empty file' do
|
128
|
-
expect(subject.upload(empty_src_file.path, dest_file)).to be 0
|
129
|
-
expect(subject).to have_created(dest_file).with_content('')
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'overwrites an existing file' do
|
133
|
-
expect(subject.upload(this_file, dest_file)).to be > 0
|
134
|
-
expect(subject.upload(empty_src_file.path, dest_file)).to be 0
|
135
|
-
expect(subject).to have_created(dest_file).with_content('')
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'upload directory' do
|
140
|
-
let(:root_dir) { File.expand_path('../../', File.dirname(__FILE__)) }
|
141
|
-
let(:winrm_fs_dir) { File.join(root_dir, 'lib/winrm-fs') }
|
142
|
-
let(:core_dir) { File.join(root_dir, 'lib/winrm-fs/core') }
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
subject.
|
180
|
-
|
181
|
-
subject.
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
describe WinRM::FS::FileManager do
|
5
|
+
let(:dest_dir) { File.join(subject.temp_dir, "winrm_#{rand(2**16)}") }
|
6
|
+
let(:temp_upload_dir) { '$env:TEMP/winrm-upload' }
|
7
|
+
let(:spec_dir) { File.expand_path(File.dirname(File.dirname(__FILE__))) }
|
8
|
+
let(:this_file) { __FILE__ }
|
9
|
+
let(:service) { winrm_connection }
|
10
|
+
|
11
|
+
subject { WinRM::FS::FileManager.new(service) }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
expect(subject.delete(dest_dir)).to be true
|
15
|
+
expect(subject.delete(temp_upload_dir)).to be true
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'exists?' do
|
19
|
+
it 'should exist' do
|
20
|
+
expect(subject.exists?('c:/windows')).to be true
|
21
|
+
expect(subject.exists?('c:/foobar')).to be false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'create and delete dir' do
|
26
|
+
it 'should create the directory recursively' do
|
27
|
+
subdir = File.join(dest_dir, 'subdir1', 'subdir2')
|
28
|
+
expect(subject.create_dir(subdir)).to be true
|
29
|
+
expect(subject.exists?(subdir)).to be true
|
30
|
+
expect(subject.create_dir(subdir)).to be true
|
31
|
+
expect(subject.delete(subdir)).to be true
|
32
|
+
expect(subject.exists?(subdir)).to be false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'temp_dir' do
|
37
|
+
it 'should return the remote users temp dir' do
|
38
|
+
expect(subject.temp_dir).to match(%r{C:/Users/\S+/AppData/Local/Temp})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'upload file' do
|
43
|
+
let(:dest_file) { File.join(dest_dir, File.basename(this_file)) }
|
44
|
+
|
45
|
+
before(:each) do
|
46
|
+
expect(subject.delete(dest_dir)).to be true
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should upload the specified file' do
|
50
|
+
subject.upload(this_file, dest_file)
|
51
|
+
expect(subject).to have_created(dest_file).with_content(this_file)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should upload to root of the c: drive' do
|
55
|
+
subject.upload(this_file, 'c:/winrmtest.rb')
|
56
|
+
expect(subject).to have_created('c:/winrmtest.rb').with_content(this_file)
|
57
|
+
subject.delete('c:/winrmtest.rb')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should upload using relative file path' do
|
61
|
+
subject.upload('./spec/integration/file_manager_spec.rb', dest_file)
|
62
|
+
expect(subject).to have_created(dest_file).with_content(this_file)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should upload to the specified directory' do
|
66
|
+
subject.upload(this_file, dest_dir)
|
67
|
+
expect(subject).to have_created(dest_file).with_content(this_file)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should upload to the specified directory with env var' do
|
71
|
+
subject.upload(this_file, '$env:Temp')
|
72
|
+
expected_dest_file = File.join(subject.temp_dir, File.basename(this_file))
|
73
|
+
expect(subject).to have_created(expected_dest_file).with_content(this_file)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should upload to Program Files sub dir' do
|
77
|
+
subject.upload(this_file, '$env:ProgramFiles/foo')
|
78
|
+
expect(subject).to have_created('c:/Program Files/foo/file_manager_spec.rb') \
|
79
|
+
.with_content(this_file)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should upload to the specified nested directory' do
|
83
|
+
dest_sub_dir = File.join(dest_dir, 'subdir')
|
84
|
+
dest_sub_dir_file = File.join(dest_sub_dir, File.basename(this_file))
|
85
|
+
subject.upload(this_file, dest_sub_dir)
|
86
|
+
expect(subject).to have_created(dest_sub_dir_file).with_content(this_file)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'yields progress data' do
|
90
|
+
block_called = false
|
91
|
+
total_bytes_copied = 0
|
92
|
+
total = subject.upload(this_file, dest_file) do \
|
93
|
+
|bytes_copied, total_bytes, local_path, remote_path|
|
94
|
+
expect(total_bytes).to be > 0
|
95
|
+
total_bytes_copied = bytes_copied
|
96
|
+
expect(local_path).to eq(this_file)
|
97
|
+
expect(remote_path).to eq(dest_file)
|
98
|
+
block_called = true
|
99
|
+
end
|
100
|
+
expect(total_bytes_copied).to eq(total)
|
101
|
+
expect(block_called).to be true
|
102
|
+
expect(total).to be > 0
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should not upload when content matches' do
|
106
|
+
subject.upload(this_file, dest_dir)
|
107
|
+
bytes_uploaded = subject.upload(this_file, dest_dir)
|
108
|
+
expect(bytes_uploaded).to eq 0
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should upload when content differs' do
|
112
|
+
matchers_file = File.join(spec_dir, 'matchers.rb')
|
113
|
+
subject.upload(matchers_file, dest_file)
|
114
|
+
bytes_uploaded = subject.upload(this_file, dest_file)
|
115
|
+
expect(bytes_uploaded).to be > 0
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'raises WinRMUploadError when a bad source path is specified' do
|
119
|
+
expect { subject.upload('c:/some/non-existant/path/foo', dest_file) }.to raise_error
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'upload empty file' do
|
124
|
+
let(:empty_src_file) { Tempfile.new('empty') }
|
125
|
+
let(:dest_file) { File.join(dest_dir, 'emptyfile.txt') }
|
126
|
+
|
127
|
+
it 'creates a new empty file' do
|
128
|
+
expect(subject.upload(empty_src_file.path, dest_file)).to be 0
|
129
|
+
expect(subject).to have_created(dest_file).with_content('')
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'overwrites an existing file' do
|
133
|
+
expect(subject.upload(this_file, dest_file)).to be > 0
|
134
|
+
expect(subject.upload(empty_src_file.path, dest_file)).to be 0
|
135
|
+
expect(subject).to have_created(dest_file).with_content('')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'upload directory' do
|
140
|
+
let(:root_dir) { File.expand_path('../../', File.dirname(__FILE__)) }
|
141
|
+
let(:winrm_fs_dir) { File.join(root_dir, 'lib/winrm-fs') }
|
142
|
+
let(:core_dir) { File.join(root_dir, 'lib/winrm-fs/core') }
|
143
|
+
let(:scripts_dir) { File.join(root_dir, 'lib/winrm-fs/scripts') }
|
144
|
+
|
145
|
+
it 'copies the directory contents recursively when directory does not exist' do
|
146
|
+
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
147
|
+
expect(bytes_uploaded).to be > 0
|
148
|
+
|
149
|
+
Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
|
150
|
+
host_file_rel = Pathname.new(host_file).relative_path_from(
|
151
|
+
Pathname.new(winrm_fs_dir)
|
152
|
+
).to_s
|
153
|
+
remote_file = File.join(dest_dir, host_file_rel)
|
154
|
+
expect(subject).to have_created(remote_file).with_content(host_file)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'copies the directory recursively when directory does exist' do
|
159
|
+
subject.create_dir(dest_dir)
|
160
|
+
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
161
|
+
expect(bytes_uploaded).to be > 0
|
162
|
+
|
163
|
+
Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
|
164
|
+
host_file_rel = Pathname.new(host_file).relative_path_from(
|
165
|
+
Pathname.new(winrm_fs_dir).dirname
|
166
|
+
).to_s
|
167
|
+
remote_file = File.join(dest_dir, host_file_rel)
|
168
|
+
expect(subject).to have_created(remote_file).with_content(host_file)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'does not copy the directory when content is the same' do
|
173
|
+
subject.upload(winrm_fs_dir, dest_dir)
|
174
|
+
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
175
|
+
expect(bytes_uploaded).to eq 0
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'unzips the directory when cached content is the same' do
|
179
|
+
subject.upload(winrm_fs_dir, dest_dir)
|
180
|
+
subject.delete(dest_dir)
|
181
|
+
expect(subject.exists?(dest_dir)).to be false
|
182
|
+
subject.upload(winrm_fs_dir, dest_dir)
|
183
|
+
expect(subject.exists?(dest_dir)).to be true
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'unzips multiple directories when cached content is the same for all' do
|
187
|
+
subject.create_dir(dest_dir)
|
188
|
+
subject.upload([core_dir, scripts_dir], dest_dir)
|
189
|
+
subject.delete(dest_dir)
|
190
|
+
expect(subject.exists?(dest_dir)).to be false
|
191
|
+
subject.create_dir(dest_dir)
|
192
|
+
subject.upload([core_dir, scripts_dir], dest_dir)
|
193
|
+
expect(subject.exists?(File.join(dest_dir, 'core'))).to be true
|
194
|
+
expect(subject.exists?(File.join(dest_dir, 'scripts'))).to be true
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'copies the directory when content differs' do
|
198
|
+
subject.upload(winrm_fs_dir, dest_dir)
|
199
|
+
bytes_uploaded = subject.upload(core_dir, dest_dir)
|
200
|
+
expect(bytes_uploaded).to be > 0
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|