mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
add function tests for compliance
command
This commit is contained in:
parent
07c359431f
commit
3007aef248
3 changed files with 72 additions and 4 deletions
|
@ -85,6 +85,11 @@ module Compliance
|
|||
option :overwrite, type: :boolean, default: false,
|
||||
desc: 'Overwrite existing profile on Chef Compliance.'
|
||||
def upload(path) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, PerceivedComplexity
|
||||
unless File.exist?(path)
|
||||
puts "Directory #{path} does not exist."
|
||||
exit 1
|
||||
end
|
||||
|
||||
o = options.dup
|
||||
configure_logger(o)
|
||||
# check the profile, we only allow to upload valid profiles
|
||||
|
@ -164,9 +169,8 @@ module Compliance
|
|||
|
||||
desc 'logout', 'user logout from Chef Compliance'
|
||||
def logout
|
||||
if Compliance::Configuration.new.supported?(:oidc)
|
||||
config = Compliance::Configuration.new
|
||||
else
|
||||
config = Compliance::Configuration.new
|
||||
unless config.supported?(:oidc) || config['token'].nil?
|
||||
config = Compliance::Configuration.new
|
||||
url = "#{config['server']}/logout"
|
||||
Compliance::API.post(url, config['token'], config['insecure'], !config.supported?(:oidc))
|
||||
|
|
|
@ -47,7 +47,11 @@ module Compliance
|
|||
|
||||
# deletes data
|
||||
def destroy
|
||||
File.delete(@config_file)
|
||||
if File.exist?(@config_file)
|
||||
File.delete(@config_file)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# return if the (stored) api version does not support a certain feature
|
||||
|
|
60
test/functional/inspec_compliance_test.rb
Normal file
60
test/functional/inspec_compliance_test.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
# encoding: utf-8
|
||||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
require 'functional/helper'
|
||||
|
||||
# basic testing without availability of any server
|
||||
describe 'inspec compliance' do
|
||||
include FunctionalHelper
|
||||
|
||||
it 'help' do
|
||||
out = inspec('compliance help')
|
||||
out.exit_status.must_equal 0
|
||||
out.stdout.must_include 'inspec compliance exec PROFILE'
|
||||
end
|
||||
|
||||
# ensure we are logged out
|
||||
it 'logout' do
|
||||
out = inspec('compliance logout')
|
||||
out.exit_status.must_equal 0
|
||||
out.stdout.must_include ''
|
||||
end
|
||||
|
||||
it 'login server url missing' do
|
||||
out = inspec('compliance login')
|
||||
#TODO: we need to convince thor that this is an error
|
||||
out.exit_status.must_equal 0
|
||||
out.stderr.must_include 'ERROR: "inspec login" was called with no arguments'
|
||||
end
|
||||
|
||||
it 'login server with missing parameters' do
|
||||
out = inspec('compliance login http://example.com')
|
||||
out.exit_status.must_equal 1
|
||||
#TODO: inspec should really use stderr for errors
|
||||
out.stdout.must_include 'Please run `inspec compliance login` with options'
|
||||
end
|
||||
|
||||
it 'inspec compliance profiles without authentication' do
|
||||
out = inspec('compliance profile')
|
||||
out.exit_status.must_equal 1
|
||||
end
|
||||
|
||||
it 'try to upload a profile without directory' do
|
||||
out = inspec('compliance upload')
|
||||
out.stderr.must_include 'ERROR: "inspec upload" was called with no arguments'
|
||||
out.exit_status.must_equal 0
|
||||
end
|
||||
|
||||
it 'try to upload a profile a non-existing path' do
|
||||
out = inspec('compliance upload /path/to/dir')
|
||||
out.stdout.must_include 'Directory /path/to/dir does not exist.'
|
||||
out.exit_status.must_equal 1
|
||||
end
|
||||
|
||||
it 'logout' do
|
||||
out = inspec('compliance logout')
|
||||
out.exit_status.must_equal 0
|
||||
out.stdout.must_include ''
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue