Skip to content

Commit

Permalink
Local transport on Windows should use WindowsFile (inspec#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ted Wang committed Aug 23, 2017
1 parent a5c5fc8 commit 1f47b59
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 13 deletions.
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ install:
- ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}"
- ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
- ps: Write-Host $env:PATH
- ps: echo hello world > "C:\train_test_file"
- ruby --version
- gem --version
- appveyor DownloadFile -Url %bundler_url% -FileName bundler.gem
Expand Down
4 changes: 4 additions & 0 deletions test/integration/tests/path_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
describe 'regular file' do
let(:file) { backend.file('/tmp/file') }

it 'is a LinuxFile' do
file.must_be_kind_of(Train::Extras::LinuxFile)
end

it 'exists' do
file.exist?.must_equal(true)
end
Expand Down
89 changes: 82 additions & 7 deletions test/windows/local_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
require 'train'

describe 'windows local command' do
let(:conn) {
let(:backend) {
# get final config
target_config = Train.target_config({})
# initialize train
backend = Train.create('local', target_config)
target_config = Train.target_config({
target: ENV['train_target'],
password: ENV['winrm_pass'],
ssl: ENV['train_ssl'],
self_signed: true,
})

# start or reuse a connection
conn = backend.connection
conn
# initialize train
Train.create('winrm', target_config)
}

let(:conn) { backend.connection }

it 'verify os' do
os = conn.os
os[:name].must_equal 'Windows Server 2012 R2 Datacenter'
Expand All @@ -39,6 +43,77 @@
cmd.stderr.must_equal ''
end

describe 'verify file' do
let(:file) { backend.file('C:\\train_test_file') }

it 'is a WindowsFile' do
file.must_be_kind_of(Train::Extras::WindowsFile)
end

it 'exists' do
file.exist?.must_equal(true)
end

it 'is a file' do
file.file?.must_equal(true)
end

it 'has type :file' do
file.type.must_equal(:file)
end

it 'has content' do
file.content.must_equal('hello world')
end

it 'has no owner name' do
file.owner.must_be_nil
end

it 'has no group name' do
file.group.must_be_nil
end

it 'has no mode' do
file.mode.must_be_nil
end

it 'has an md5sum' do
file.md5sum.wont_be_nil
end

it 'has an sha256sum' do
file.sha256sum.wont_be_nil
end

it 'has no modified time' do
file.mtime.must_be_nil
end

it 'has no size' do
# TODO: this really ought to be implemented
file.size.must_be_nil
end

it 'has no selinux label handling' do
file.selinux_label.must_be_nil
end

it 'has product_version' do
file.product_version.wont_be_nil
end

it 'has file_version' do
file.file_version.wont_be_nil
end

it 'provides a json representation' do
j = file.to_json
j.must_be_kind_of Hash
j['type'].must_equal :file
end
end

after do
# close the connection
conn.close
Expand Down
81 changes: 75 additions & 6 deletions test/windows/winrm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require 'train'

describe 'windows winrm command' do
let(:conn) {
let(:backend) {
# get final config
target_config = Train.target_config({
target: ENV['train_target'],
Expand All @@ -18,13 +18,11 @@
})

# initialize train
backend = Train.create('winrm', target_config)

# start or reuse a connection
conn = backend.connection
conn
Train.create('winrm', target_config)
}

let(:conn) { backend.connection }

it 'verify os' do
os = conn.os
os[:name].must_equal 'Windows Server 2012 R2 Datacenter'
Expand All @@ -45,6 +43,77 @@
cmd.stderr.must_equal ''
end

describe 'verify file' do
let(:file) { backend.file('C:\\train_test_file') }

it 'is an instance of WindowsFile' do
file.must_be_kind_of(Train::Extras::WindowsFile)
end

it 'exists' do
file.exist?.must_equal(true)
end

it 'is a file' do
file.file?.must_equal(true)
end

it 'has type :file' do
file.type.must_equal(:file)
end

it 'has content' do
file.content.must_equal('hello world')
end

it 'has no owner name' do
file.owner.must_be_nil
end

it 'has no group name' do
file.group.must_be_nil
end

it 'has no mode' do
file.mode.must_be_nil
end

it 'has an md5sum' do
file.md5sum.wont_be_nil
end

it 'has an sha256sum' do
file.sha256sum.wont_be_nil
end

it 'has no modified time' do
file.mtime.must_be_nil
end

it 'has no size' do
# TODO: this really ought to be implemented
file.size.must_be_nil
end

it 'has no selinux label handling' do
file.selinux_label.must_be_nil
end

it 'has product_version' do
file.product_version.wont_be_nil
end

it 'has file_version' do
file.file_version.wont_be_nil
end

it 'provides a json representation' do
j = file.to_json
j.must_be_kind_of Hash
j['type'].must_equal :file
end
end

after do
# close the connection
conn.close
Expand Down

0 comments on commit 1f47b59

Please sign in to comment.