Commit graph

30 commits

Author SHA1 Message Date
Vasundhara Jagdale
95c17d4e7f
CHEF-3849: InSpec should exit quickly and clearly if waiver file is malformed/corrupt (#6644)
* Functional test for malformed waiver file

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Raise error for malformed yaml content and exit

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Updates functional test for malformed yaml waiver file and for empty waiver file

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Raises error in case of missing required parameters in waiver file

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Update functional test for missing parameters, extra parameters or column without headers in waiver file

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Fix linting

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Fix warning and error messages

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Updates nil and false check for yaml data and adds additional empty check.

Co-authored-by: Sathish Babu <80091550+sathish-progress@users.noreply.github.com>
Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Adds more generic message as this yaml reader is now getting used by other functionalities like waiver file

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Fixed test description to reflect correct use case

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Fix validate headers was not validating the required parametes for all the data fields as it was not called inside the loop where we are iterating over the data and fetching the headers.

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Updates the test files for the use case to missing parameters and extra parameters

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Updates code to better handle errors and warnings related to missing required parameters and extra parameters in waivers file in all format i.e (yaml, json and csv).

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Updated functional test to capture the updated error and warning messages for waiver file validation

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Fix linting

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Deleted fixture file which is not required

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

* Refactor: Renamed method validate_headers to reflect whats it's doing and instead of return data in array it will now return the data in hash

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>

---------

Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com>
Co-authored-by: Sathish Babu <80091550+sathish-progress@users.noreply.github.com>
2023-09-12 10:36:40 -04:00
Vasundhara Jagdale
e861b37a59
CHEF-5200 Waived controls are not getting waived (skipped) in case of failure at resource level. (#6588)
* CHEF-5200: This fix applies waiver if exception occurs while eval the control inside control block. This ensures that waiver are got applied in case of resouce level failures too.

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* When waiver file is empty error should be raised the written is invalid for the empty waiver file.
Added different test to check only_if waiver is applied when the waived control in the waived file has expired.

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Fix lint

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Fix test failing on windows due to different exit code on the Windows.

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

---------

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
2023-08-09 09:50:49 -04:00
Nikita Mathur
ae1173c0b3
CFINSPEC-240 Extended file format support for waivers: JSON & CSV (#6369)
* Revert "Revert "CFINSPEC-240 Extended file format support for waivers (#6193)" (#6366)"

This reverts commit 30146e07fe.

* Waiver support for csv and json

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Removed the word excel from image tag

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Update waivers.md

Signed-off-by: Ian Maddaus <ian.maddaus@progress.com>

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
Signed-off-by: Ian Maddaus <ian.maddaus@progress.com>
Co-authored-by: Ian Maddaus <ian.maddaus@progress.com>
2023-01-17 07:27:47 -05:00
Nikita Mathur
30146e07fe
Revert "CFINSPEC-240 Extended file format support for waivers (#6193)" (#6366)
This reverts commit b7ddac9dcc.
2023-01-04 16:02:16 +05:30
Nikita Mathur
b7ddac9dcc
CFINSPEC-240 Extended file format support for waivers (#6193)
* Added separate waiver file reader and support for csv

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Added support for json format waivers

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Added support for xls and xlsx

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Build issues and updated description of gems

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Doc changes for waivers about supports

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Fix added to check final options presense in config

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Renamed variables from inputs to waivers

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Validation changes with other small changes

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Headers validation added for json and yaml

* Linter issues resolved

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Some refactoring and message change

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* exit code check removed from test cases since not req

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Doc change for waiver support for excel by showing example

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

Co-authored-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2022-08-01 09:19:35 -04:00
Clinton Wolfe
46541a7cae Typo in test
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2021-04-08 16:25:09 -04:00
Clinton Wolfe
c21055af62 Rename --ludicrous-speed to --filter-waived-controls and reword usage message
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2021-04-08 16:25:09 -04:00
Nick Schwaderer
bb5cfbd434 Implement retain-waiver-data to keep 100% feature-ability
Signed-off-by: Nick Schwaderer <nschwaderer@chef.io>
2021-04-08 16:20:02 -04:00
Nick Schwaderer
ac8ee33b63 Extend nuke_waivers
Signed-off-by: Nick Schwaderer <nschwaderer@chef.io>
2021-04-08 16:19:17 -04:00
Nick Schwaderer
db3e2751d6 Sets up testing and expectation for completely nuked waived controls
Signed-off-by: Nick Schwaderer <nschwaderer@chef.io>
2021-04-08 16:18:35 -04:00
David Marshall
874ee77791 add test for when run is not specified in waiver
The existing documentation explicitly claims that not specifying “run” in a waiver is equivalent to specifying “run: false.” It turns out to be the case that the claim is completely false. This commit includes a test for a new control 18_waivered_no_expiry_default_run that behaves exactly like the control 04_waivered_no_expiry_ran_fails. That is, not specifying run in a waiver is the same as specifying “run: true.”

Signed-off-by: David Marshall <dmarshall@gmail.com>
2020-12-28 16:26:19 -08:00
Nick Schwaderer
4c4bfe0426 Update tests to handle waiver expiration message
Signed-off-by: Nick Schwaderer <nschwaderer@chef.io>
2020-10-14 12:55:39 +01:00
James Stocks
350c0bfe8f Handle waiver expiration dates being YAML strings
This is technically incorrect YAML, but if you transcode YAML between several tools you may end up with a date/time value being an explicit string.
It would be helpful if InSpec supported any string value that easily translates to a Time.

Signed-off-by: James Stocks <jstocks@chef.io>
2020-05-20 15:00:43 +01:00
James Stocks
35e36ad40a Allow for waiver time as well as date
Fixes #5037

The YAML parser may parse a waiver timestamp as a Time rather than a Date. Even when the user doesn't care about time, they may be using a tool that outputs YAML with trailing zeroes for hour, minutes, seconds etc.

Signed-off-by: James Stocks <jstocks@chef.io>
2020-05-20 14:59:07 +01:00
Nick Schwaderer
a1129f9efc Allows input and control to have the same name
In https://github.com/inspec/inspec/issues/4936 the issue was reported that naming an input the same as a control caused an unexpected failure.

In that particular case, the naming was a result of a pre-waivers workaround which is no longer necessary, but ultimately a breakage of that name clash is an unexpected occurrance.

Due to how inputs are named and registered, `__apply_waivers` thinks that an object is a waiver that is not a waiver and tries to process it. On the micro level, it breaks when trying to pass a variable to a string as if it were a Hash.

It is imperative that we preserve 100% of the current featureset, pass our tests, and fix this edge case along with new test coverage for the failure.

This PR updates the code to do a slightly more elegant and small ‘waiver check’ to stop the namespace clash from breaking our code.

Signed-off-by: Nick Schwaderer <nschwaderer@chef.io>
2020-05-05 10:00:19 +01:00
Ryan Davis
d201d1fbc2 Fixed the rest of the minitest deprecations by removing FuncTestRunResult.
Folded the json & other payloads into plain ivars on the test.
Found and removed some unused code while I was there.

Fixes #4533.

Signed-off-by: Ryan Davis <zenspider@chef.io>
2019-10-22 12:15:28 -07:00
Clinton Wolfe
8f4ff8923e Add functional test to exercise waivers during profile inheritance
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-10-09 19:10:48 -07:00
Clinton Wolfe
0f5fde9729 Modify waiver input file to use 'run' subfield instead of 'skip'
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-10-08 01:03:40 -07:00
Clinton Wolfe
7516f959d1 If there is no data, alwaya return an empty hash.
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-10-08 00:31:23 -07:00
Clinton Wolfe
56c2416c57 Move waiver JSON data from per-result to per-control
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-10-08 00:25:06 -07:00
Ryan Davis
1d3c9341ec Finished up the phase 3 waiver json output tests.
Signed-off-by: Ryan Davis <zenspider@chef.io>
2019-09-16 16:39:34 -07:00
Miah Johnson
5d94b0d709 Add waiver_data to json output, update assertion to show where waiver_data lives.
Signed-off-by: Miah Johnson <miah@chia-pet.org>
2019-09-16 14:49:05 -07:00
Miah Johnson
168c77e472 Refactor tests.
Signed-off-by: Miah Johnson <miah@chia-pet.org>
2019-09-16 14:49:05 -07:00
Clinton Wolfe
5d94440823 Fix logic error for future expiring waivers
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-09-09 11:29:26 -04:00
Clinton Wolfe
43bc7e0343 Modify @__skip_rule to distinguish only_if and waiver, and force waiver to win
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-09-09 11:29:26 -04:00
Clinton Wolfe
0db0a2bfdc Don't assume waiver_ prefix in waiver files
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-09-09 11:29:26 -04:00
Clinton Wolfe
718e205cf2 Alter expiration_date behavior to match spec
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-09-09 11:29:26 -04:00
Clinton Wolfe
ff209b4bae Refactor control_id lookup in waiver test file
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-09-09 11:29:26 -04:00
Clinton Wolfe
eb1ec437d7 Linting and test number corrections
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-09-09 11:29:26 -04:00
Clinton Wolfe
5891c9aee9 A failing functional test to skip waivered controls
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2019-09-09 11:29:26 -04:00