mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
Update apache_conf regular expression to exclude whitespace. (#2416)
* Update apache_conf test to check for ServerAlias values. Signed-off-by: Miah Johnson <miah@chia-pet.org> * Add ServerAlias key and values to mock apache conf which includes trailing whitespace. Signed-off-by: Miah Johnson <miah@chia-pet.org> * Updated test to reflect all ServerAlias values being put into a single array item. This is expected as we do not override the key_values default setting of '1' when passing the raw configuration to SimpleConfig. Signed-off-by: Miah Johnson <miah@chia-pet.org> * Update the regular expression to include a conditional with positive lookahead that checks if the line ends with one or more spaces. If the lookahead succeeds we non-greedily capture, and when it fails we greedily capture. Signed-off-by: Miah Johnson <miah@chia-pet.org>
This commit is contained in:
parent
d86ebee7bd
commit
685ba1bc1e
3 changed files with 11 additions and 2 deletions
|
@ -78,10 +78,17 @@ module Inspec::Resources
|
|||
raw_conf = read_file(to_read[0])
|
||||
@content += raw_conf
|
||||
|
||||
# parse include file parameters
|
||||
# An explaination of the below regular expression.
|
||||
# Creates two capture groups.
|
||||
# The first group captures the first group of non-whitespace character
|
||||
# surrounded whitespace characters.
|
||||
# The second group contains a conditional with a positive lookahead
|
||||
# (does the line end with one or more spaces?). If the lookahead succeeds
|
||||
# a non-greedy capture takes place, if it fails then a greedy capture takes place.
|
||||
# The regex is terminated by an expression that matches zero or more spaces.
|
||||
params = SimpleConfig.new(
|
||||
raw_conf,
|
||||
assignment_regex: /^\s*(\S+)\s+(.*)\s*$/,
|
||||
assignment_regex: /^\s*(\S+)\s+((?=.*\s+$).*?|.*)\s*$/,
|
||||
multiple_values: true,
|
||||
).params
|
||||
@params.merge!(params)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# This is the main Apache server configuration file. It contains comments.
|
||||
ServerRoot "/etc/apache2"
|
||||
ServerAlias inspec.test www.inspec.test io.inspec.test
|
||||
|
||||
User ${APACHE_RUN_USER}
|
||||
Include ports.conf
|
||||
|
|
|
@ -12,6 +12,7 @@ describe 'Inspec::Resources::ApacheConf' do
|
|||
_(resource.params).must_be_kind_of Hash
|
||||
_(resource.content).must_be_kind_of String
|
||||
_(resource.params('ServerRoot')).must_equal ['"/etc/apache2"']
|
||||
_(resource.params('ServerAlias')).must_equal ['inspec.test www.inspec.test io.inspec.test']
|
||||
_(resource.params('Listen').sort).must_equal ['443', '80']
|
||||
# sourced using a linked file in conf-enabled/
|
||||
_(resource.params('ServerSignature')).must_equal ['Off']
|
||||
|
|
Loading…
Add table
Reference in a new issue