inspec / kitchen-inspec

Test-Kitchen Plugin for InSpec
Other
109 stars 58 forks source link

inspec array input treated as hash w/ keys #271

Open rjhornsby opened 3 years ago

rjhornsby commented 3 years ago

Version:

2.2.2

Environment:

Host system - macOS 10.15, guest OS CentOS 7

Scenario:

Make kitchen pass inputs to inspec, specifically an array of values that inspec will later iterate over. It seems like the array type is crucial here.

Steps to Reproduce:

My kitchen.yml, under the suite, contains this inspec config:

    verifier:
      inspec_tests:
      ...
      inputs:
      - name: domains
        type: array
        value: ['foo.com', 'bar.com']

now run kitchen verify against this setup.

Expected Result:

The domains array should be iterable in an inspec test

Actual Result:

The execution never makes it to inspec proper. It looks like kitchen-inspec is (always?) expecting to get a hash. When it gets an array instead, and then tries to access its hash keys, it errors out:

Message: Failed to complete #verify action: [undefined method 'keys' for #<Array:memaddr>]

I believe this is where things break:

if config[:inputs]
    ...
    opts[inputs_key] = Hashie.stringify_keys config[:inputs]
end

A work around is to move the inputs config from kitchen.yml into the inspec profile's inspec.yml file.

clintoncwolfe commented 1 year ago

Here's the referenced code now, in a permelink - https://github.com/inspec/kitchen-inspec/blob/856f84a7847b4ab52e9938018b0099f36a988615/lib/kitchen/verifier/inspec.rb#L146 - we call Hashie stringify keys on it.