Modify DirProvider to allow special characters (#2174)

This modifies `Inspec::DirProvider` to allow special characters in the
file glob by escaping those characters via `Shellwords.shellescape`.

This fixes #2111 (`inspec check` on path with special characters)

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
This commit is contained in:
Jerry Aldrich III 2017-09-23 02:16:25 -05:00 committed by Dominik Richter
parent 9f06ba0b0b
commit 125e0915b2
5 changed files with 37 additions and 6 deletions

View file

@ -72,7 +72,7 @@ module Inspec
@files = if File.file?(path) @files = if File.file?(path)
[path] [path]
else else
Dir[File.join(path, '**', '*')] Dir[File.join(Shellwords.shellescape(path), '**', '*')]
end end
@path = path @path = path
end end

View file

@ -5,12 +5,21 @@
require 'functional/helper' require 'functional/helper'
require 'jsonschema' require 'jsonschema'
describe 'inspec check with json formatter' do describe 'inspec check' do
include FunctionalHelper include FunctionalHelper
it 'can execute a simple file and validate the json schema' do describe 'inspec check with json formatter' do
out = inspec('check ' + integration_test_path + ' --format json') it 'can check a profile and produce valid JSON' do
out.exit_status.must_equal 0 out = inspec('check ' + integration_test_path + ' --format json')
data = JSON.parse(out.stdout) out.exit_status.must_equal 0
JSON.parse(out.stdout)
end
end
describe 'inspec check with special characters in path' do
it 'can check a profile with special characters in its path' do
out = inspec('check ' + File.join(profile_path, '{{special-path}}'))
out.exit_status.must_equal 0
end
end end
end end

View file

@ -0,0 +1,4 @@
# Profile with Special Characters in Path
This is used to test `inspec check` on a path containing special characters. See: https://github.com/chef/inspec/issues/2111

View file

@ -0,0 +1,10 @@
title 'special-path'
control 'normal-profile-1.0' do
impact 0.7
title 'Test Paths with Special Chars'
desc 'Not a real test, check with `inspec check`'
describe 'foo' do
it { should eq 'foo' }
end
end

View file

@ -0,0 +1,8 @@
name: normal-profile
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0