2016-04-13 20:08:44 +00:00
|
|
|
# options
|
2019-06-11 22:24:35 +00:00
|
|
|
inspec_bin = "BUNDLE_GEMFILE=/inspec/Gemfile bundle exec inspec"
|
|
|
|
api_url = "https://0.0.0.0"
|
|
|
|
profile = "/inspec/examples/profile"
|
2016-04-13 20:08:44 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
user = command("whoami").stdout.strip
|
|
|
|
pwd = command("pwd").stdout.strip
|
2016-08-18 16:34:09 +00:00
|
|
|
puts "Run test as #{user} in path #{pwd}"
|
|
|
|
|
2016-04-13 20:08:44 +00:00
|
|
|
# TODO: determine tokens automatically, define in kitchen yml
|
2019-06-11 22:24:35 +00:00
|
|
|
access_token = ENV["COMPLIANCE_ACCESSTOKEN"]
|
|
|
|
refresh_token = ENV["COMPLIANCE_REFRESHTOKEN"]
|
2016-04-13 20:08:44 +00:00
|
|
|
|
2017-11-21 07:49:41 +00:00
|
|
|
%w{refresh_token access_token}.each do |type| # rubocop:disable Metrics/BlockLength
|
2016-04-13 20:08:44 +00:00
|
|
|
case type
|
2019-06-11 22:24:35 +00:00
|
|
|
when "access_token"
|
2016-04-13 20:08:44 +00:00
|
|
|
token_options = "--token '#{access_token}'"
|
2019-06-11 22:24:35 +00:00
|
|
|
when "refresh_token"
|
2016-04-13 20:08:44 +00:00
|
|
|
token_options = "--refresh_token '#{refresh_token}'"
|
|
|
|
end
|
|
|
|
|
|
|
|
# verifies that the help command works
|
|
|
|
describe command("#{inspec_bin} compliance help") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "inspec compliance help [COMMAND]" }
|
|
|
|
its("stderr") { should eq "" }
|
|
|
|
its("exit_status") { should eq 0 }
|
2016-04-13 20:08:44 +00:00
|
|
|
end
|
|
|
|
|
2016-08-16 14:52:21 +00:00
|
|
|
# version command fails gracefully when server not configured
|
|
|
|
describe command("#{inspec_bin} compliance version") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "Server configuration information is missing" }
|
|
|
|
its("stderr") { should eq "" }
|
|
|
|
its("exit_status") { should eq 1 }
|
2016-08-16 14:52:21 +00:00
|
|
|
end
|
|
|
|
|
2016-08-18 00:00:26 +00:00
|
|
|
# submitting a wrong token should have an exit of 0
|
|
|
|
describe command("#{inspec_bin} compliance login #{api_url} --insecure --user 'admin' --token 'wrong-token'") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "token stored" }
|
2016-08-18 17:48:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# compliance login --help should give an accurate message for login
|
|
|
|
describe command("#{inspec_bin} compliance login --help") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "inspec compliance login SERVER --insecure --user='USER' --token='TOKEN'" }
|
|
|
|
its("exit_status") { should eq 0 }
|
2016-08-18 00:00:26 +00:00
|
|
|
end
|
|
|
|
|
2016-08-17 16:15:11 +00:00
|
|
|
# profiles command fails gracefully when token/server info is incorrect
|
|
|
|
describe command("#{inspec_bin} compliance profiles") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "401 Unauthorized. Please check your token" }
|
|
|
|
its("stderr") { should eq "" }
|
|
|
|
its("exit_status") { should eq 1 }
|
2016-08-17 16:15:11 +00:00
|
|
|
end
|
|
|
|
|
2016-04-13 20:08:44 +00:00
|
|
|
# login via access token token
|
2016-08-17 11:51:26 +00:00
|
|
|
describe command("#{inspec_bin} compliance login #{api_url} --insecure --user 'admin' #{token_options}") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "token", "stored" }
|
|
|
|
its("stdout") { should_not include "Your server supports --user and --password only" }
|
|
|
|
its("stderr") { should eq "" }
|
|
|
|
its("exit_status") { should eq 0 }
|
2016-04-13 20:08:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# see available resources
|
|
|
|
describe command("#{inspec_bin} compliance profiles") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "base/ssh" }
|
|
|
|
its("stderr") { should eq "" }
|
|
|
|
its("exit_status") { should eq 0 }
|
2016-04-13 20:08:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# upload a compliance profile
|
|
|
|
describe command("#{inspec_bin} compliance upload #{profile} --overwrite") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "Profile is valid" }
|
|
|
|
its("stdout") { should include "Successfully uploaded profile" }
|
|
|
|
its("stdout") { should_not include "error(s)" }
|
|
|
|
its("stderr") { should eq "" }
|
|
|
|
its("exit_status") { should eq 0 }
|
2016-04-13 20:08:44 +00:00
|
|
|
end
|
|
|
|
|
2016-08-16 14:52:21 +00:00
|
|
|
# returns the version of the server
|
|
|
|
describe command("#{inspec_bin} compliance version") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "Chef Compliance version:" }
|
|
|
|
its("stderr") { should eq "" }
|
|
|
|
its("exit_status") { should eq 0 }
|
2016-08-16 14:52:21 +00:00
|
|
|
end
|
|
|
|
|
2016-04-13 20:08:44 +00:00
|
|
|
# logout
|
|
|
|
describe command("#{inspec_bin} compliance logout") do
|
2019-06-11 22:24:35 +00:00
|
|
|
its("stdout") { should include "Successfully logged out" }
|
|
|
|
its("stderr") { should eq "" }
|
|
|
|
its("exit_status") { should eq 0 }
|
2016-04-13 20:08:44 +00:00
|
|
|
end
|
|
|
|
end
|