mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
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:
parent
9f06ba0b0b
commit
125e0915b2
5 changed files with 37 additions and 6 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
4
test/unit/mock/profiles/{{special-path}}/README.md
Normal file
4
test/unit/mock/profiles/{{special-path}}/README.md
Normal 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
|
||||||
|
|
|
@ -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
|
8
test/unit/mock/profiles/{{special-path}}/inspec.yml
Normal file
8
test/unit/mock/profiles/{{special-path}}/inspec.yml
Normal 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
|
Loading…
Reference in a new issue