Skip to content

Commit

Permalink
Merge pull request #5 from chef/fnichol/winrm-support
Browse files Browse the repository at this point in the history
Add WinRM support to Verifier (pending full support in Train).
  • Loading branch information
chris-rock committed Oct 26, 2015
2 parents a95de00 + d174482 commit 6e60be9
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
26 changes: 26 additions & 0 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
require "kitchen/verifier/inspec_version"
require "kitchen/verifier/base"

require "uri"

module Kitchen

module Verifier
Expand All @@ -40,6 +42,8 @@ def call(state)
runner_options = case (name = instance.transport.name.downcase)
when "ssh"
runner_options_for_ssh(transport_data)
when "winrm"
runner_options_for_winrm(transport_data)
else
raise Kitchen::UserError, "Verifier #{name}",
" does not support the #{name} Transport"
Expand Down Expand Up @@ -112,6 +116,28 @@ def runner_options_for_ssh(config_data)

opts
end

# Returns a configuration Hash that can be passed to a `Inspec::Runner`.
#
# @return [Hash] a configuration hash of string-based keys
# @api private
def runner_options_for_winrm(config_data)
kitchen = instance.transport.send(:connection_options, config_data).dup

opts = {
"backend" => "winrm",
"logger" => logger,
"host" => URI(kitchen[:endpoint]).hostname,
"port" => URI(kitchen[:endpoint]).port,
"user" => kitchen[:user],
"password" => kitchen[:pass],
"connection_retries" => kitchen[:connection_retries],
"connection_retry_sleep" => kitchen[:connection_retry_sleep],
"max_wait_until_ready" => kitchen[:max_wait_until_ready]
}

opts
end
end
end
end
45 changes: 44 additions & 1 deletion spec/kitchen/verifier/inspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

require "kitchen/verifier/inspec"
require "kitchen/transport/ssh"
require "kitchen/transport/winrm"

describe Kitchen::Verifier::Inspec do

Expand Down Expand Up @@ -64,6 +65,8 @@
end

before do
allow(transport).to receive(:instance).and_return(instance)

@root = Dir.mktmpdir
config[:test_base_path] = @root
end
Expand Down Expand Up @@ -167,7 +170,47 @@
end

context "with an winrm transport" do
# coming soon

let(:transport_config) do
{
:username => "dance",
:password => "party",
:connection_retries => "thousand",
:connection_retry_sleep => "sleepy",
:max_wait_until_ready => 42
}
end

let(:transport) do
Kitchen::Transport::Winrm.new(transport_config)
end

let(:runner) do
instance_double("Inspec::Runner")
end

before do
allow(runner).to receive(:add_tests)
allow(runner).to receive(:run)
end

it "constructs a Inspec::Runner using transport config data and state" do
expect(Inspec::Runner).to receive(:new).
with(hash_including(
"backend" => "winrm",
"logger" => logger,
"host" => "win.dows",
"port" => 123,
"user" => "dance",
"password" => "party",
"connection_retries" => "thousand",
"connection_retry_sleep" => "sleepy",
"max_wait_until_ready" => 42
)).
and_return(runner)

verifier.call(:hostname => "win.dows", :port => 123)
end
end

context "with an unsupported transport" do
Expand Down

0 comments on commit 6e60be9

Please sign in to comment.