2016-11-09 14:41:48 +00:00
# encoding: utf-8
# author: Christoph Hartmann
require 'functional/helper'
describe 'example inheritance profile' do
include FunctionalHelper
2016-11-09 17:12:22 +00:00
let ( :inheritance_path ) { File . join ( examples_path , 'inheritance' ) }
let ( :meta_path ) { File . join ( examples_path , 'meta-profile' ) }
2016-11-09 14:41:48 +00:00
it 'can vendor profile dependencies' do
2016-11-09 17:12:22 +00:00
out = inspec ( 'vendor ' + inheritance_path + ' --overwrite' )
out . stdout . force_encoding ( Encoding :: UTF_8 ) . must_include " Vendor dependencies of #{ inheritance_path } into #{ inheritance_path } /vendor "
2016-11-09 14:41:48 +00:00
out . stderr . must_equal ''
out . exit_status . must_equal 0
2016-11-09 17:12:22 +00:00
vendor_dir = File . join ( inheritance_path , 'vendor' )
2016-11-09 14:41:48 +00:00
File . exist? ( vendor_dir ) . must_equal true
2016-11-09 17:12:22 +00:00
lockfile = File . join ( inheritance_path , 'inspec.lock' )
2016-11-09 14:41:48 +00:00
File . exist? ( lockfile ) . must_equal true
end
it 'can vendor profile dependencies from the profile path' do
2016-11-29 12:39:29 +00:00
# clean existing vendor directory
2016-11-29 23:12:47 +00:00
begin
FileUtils . rm_r ( " #{ inheritance_path } /vendor " )
rescue Errno :: ENOENT = > e
end
2016-11-29 12:39:29 +00:00
# vendor all dependencies
2016-11-09 17:12:22 +00:00
out = inspec ( 'vendor --overwrite' , " cd #{ inheritance_path } && " )
out . stdout . force_encoding ( Encoding :: UTF_8 ) . must_include " Vendor dependencies of #{ inheritance_path } into #{ inheritance_path } /vendor "
2016-11-09 14:41:48 +00:00
out . stderr . must_equal ''
out . exit_status . must_equal 0
2016-11-09 17:12:22 +00:00
vendor_dir = File . join ( inheritance_path , 'vendor' )
2016-11-09 14:41:48 +00:00
File . exist? ( vendor_dir ) . must_equal true
2016-11-09 17:12:22 +00:00
lockfile = File . join ( inheritance_path , 'inspec.lock' )
2016-11-09 14:41:48 +00:00
File . exist? ( lockfile ) . must_equal true
end
2016-11-09 17:12:22 +00:00
it 'ensure nothing is loaded from external source if vendored profile is used' do
2016-11-29 12:39:29 +00:00
# clean existing vendor directory
2016-11-29 23:12:47 +00:00
begin
FileUtils . rm_r ( " #{ meta_path } /vendor " )
rescue Errno :: ENOENT = > e
end
2016-11-29 12:39:29 +00:00
# vendor all dependencies
2016-11-09 17:12:22 +00:00
out = inspec ( 'vendor ' + meta_path + ' --overwrite' )
out . exit_status . must_equal 0
vendor_dir = File . join ( meta_path , 'vendor' )
File . exist? ( vendor_dir ) . must_equal true
lockfile = File . join ( meta_path , 'inspec.lock' )
File . exist? ( lockfile ) . must_equal true
out = inspec ( 'exec ' + meta_path + ' -l debug --no-create-lockfile' )
2016-11-29 22:40:42 +00:00
out . stdout . force_encoding ( Encoding :: UTF_8 ) . must_include 'Using cached dependency for {:url=>"https://github.com/dev-sec/tests-ssh-hardening/archive/master.tar.gz"'
out . stdout . force_encoding ( Encoding :: UTF_8 ) . must_include 'Using cached dependency for {:url=>"https://github.com/dev-sec/ssl-benchmark/archive/master.tar.gz"'
out . stdout . force_encoding ( Encoding :: UTF_8 ) . must_include 'Using cached dependency for {:url=>"https://github.com/chris-rock/windows-patch-benchmark/archive/master.tar.gz"'
2016-11-09 17:12:22 +00:00
out . stdout . force_encoding ( Encoding :: UTF_8 ) . index ( 'Fetching URL:' ) . must_be_nil
out . stdout . force_encoding ( Encoding :: UTF_8 ) . index ( 'Fetched archive moved to:' ) . must_be_nil
out . stderr . must_equal ''
end
2016-11-30 09:19:26 +00:00
it 'ensure json/check command do not fetch remote profiles if vendored' do
2016-11-29 12:39:29 +00:00
# clean cache directory
2016-11-29 23:12:47 +00:00
begin
FileUtils . rm_rf " #{ Dir . home } /.inspec/cache "
rescue Errno :: ENOENT = > e
end
2016-11-29 12:39:29 +00:00
2016-11-30 09:19:26 +00:00
# ensure the profile is vendored
out = inspec ( 'vendor ' + meta_path + ' --overwrite' )
2016-11-29 12:39:29 +00:00
# execute json command
2016-12-02 18:52:34 +00:00
# we need to activate the logger with `-l debug`, but that needs to redirect its output to STDERR
out = inspec ( 'json ' + meta_path + ' --output ' + dst . path )
2016-11-29 12:39:29 +00:00
out . exit_status . must_equal 0
2016-11-30 09:19:26 +00:00
hm = JSON . load ( File . read ( dst . path ) )
hm [ 'name' ] . must_equal 'meta-profile'
2017-01-02 11:19:22 +00:00
hm [ 'controls' ] . length . must_equal 78
2016-11-29 22:40:42 +00:00
2016-12-02 18:52:34 +00:00
# copies = out.stdout.scan(/Copy .* to cache directory/).length
# copies.must_equal 3
#
# length = out.stdout.scan(/Dependency does not exist in the cache/).length
# length.must_equal 1
#
# length = out.stdout.scan(/Fetching URL:/).length
# length.must_equal 0
2016-11-29 12:39:29 +00:00
# execute check command
out = inspec ( 'check ' + meta_path + ' -l debug' )
out . exit_status . must_equal 0
2016-11-29 22:40:42 +00:00
2016-12-02 18:52:34 +00:00
# copies = out.stdout.scan(/Copy .* to cache directory/).length
# copies.must_equal 3
#
# length = out.stdout.scan(/Dependency does not exist in the cache/).length
# length.must_equal 1
#
# length = out.stdout.scan(/Fetching URL:/).length
# length.must_equal 0
2016-11-09 17:12:22 +00:00
end
2016-11-29 12:39:29 +00:00
it 'can vendor profile dependencies from the profile path' do
out = inspec ( 'vendor --overwrite' , " cd #{ inheritance_path } && " )
out . stdout . force_encoding ( Encoding :: UTF_8 ) . must_include " Vendor dependencies of #{ inheritance_path } into #{ inheritance_path } /vendor "
out . stderr . must_equal ''
out . exit_status . must_equal 0
vendor_dir = File . join ( inheritance_path , 'vendor' )
File . exist? ( vendor_dir ) . must_equal true
lockfile = File . join ( inheritance_path , 'inspec.lock' )
File . exist? ( lockfile ) . must_equal true
end
2016-11-29 23:12:47 +00:00
it 'use lockfile in tarball' do
# ensure the profile is vendored and packaged as tar
out = inspec ( 'vendor ' + meta_path + ' --overwrite' )
out . exit_status . must_equal 0
out = inspec ( 'archive ' + meta_path + ' --overwrite' )
out . exit_status . must_equal 0
# execute json command
2016-12-14 16:07:09 +00:00
out = inspec ( ' meta-profile-1.0.0.tar.gz -l debug' )
2016-11-29 23:12:47 +00:00
out . exit_status . must_equal 0
length = out . stdout . scan ( / Fetching URL: / ) . length
length . must_equal 0
end
2016-11-09 14:41:48 +00:00
end