Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check error - digest: no implicit conversion of nil into String (TypeError) #509

Closed
username-is-already-taken2 opened this issue Mar 1, 2016 · 4 comments · Fixed by inspec/train#75
Assignees
Labels
Type: Bug Feature not working as expected

Comments

@username-is-already-taken2
Copy link
Contributor

Hi there

I have come across an error when trying to uploaded my compliance profile to chef-compliance. I got a server response of 500. Tailing the log it would seem that my profile is failing the inspec check command.
If I run it manually, it looks

inspec check .
C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/r-train-0.10.0/lib/train/transports/mock.rb:92:in digest: no implicit conversion of nil into String (TypeError)
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/r-train-0.10.0/lib/train/transports/mock.rb:92:in hexdigest
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/r-train-0.10.0/lib/train/transports/mock.rb:92:in run_command
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/resources/command.rb:26:in result
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/resources/command.rb:30:in stdout
        from ./controls/01-config-checks.rb:6:in load
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/profile_context.rb:34:in instance_eval
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/profile_context.rb:34:in load
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/runner.rb:86:in add_content
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/runner.rb:60:in block in add_profile
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/runner.rb:57:in each
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/runner.rb:57:in add_profile
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/profile.rb:234:in load_params
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/profile.rb:49:in params
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/profile.rb:167:in rules_count
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/lib/inspec/profile.rb:136:in check
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/bin/inspec:53:in check
        from C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in run
        from C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in invoke_command
        from C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in dispatch
        from C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in start
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/gems/inspec-0.14.3/bin/inspec:166:in <top (required)>
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/bin/inspec:23:in load
        from C:/Users/xxxx/AppData/Local/chefdk/gem/ruby/2.1.0/bin/inspec:23:in <main>

It would seem that the check has a problem with line 6 in my example control

# encoding: utf-8
script = <<-EOH
$ENV:COMPUTERNAME
EOH

hostname = script(script).stdout.strip

# contents of robot.cfg 
# ROBOTNAME = WIN-2012R2

control 'app-configuration-1.01' do
  impact 1.0
  title 'APP: Validating that ROBOTNAME matches the computer hostname'
  desc 'Application wont work correctly if there is a mismatch between the ROBOTNAME and the computer name'
  options = {
    assignment_re: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
    multiple_values: false
  }
  describe parse_config_file('C:\\TEMP\\robot.cfg', options) do
    its('ROBOTNAME') {should eq hostname}
  end
end

With a bit of testing it looks like it has an issue the '.stdout' part of the line

hostname = script(script).stdout.strip

My profiles do work, I have tested them both locally and using the winrm transport, and they work great :) the trouble is I have written quite a few using this technique and I can't use them :)

mock.rb:92 is the [Digest line

    def run_command(cmd)
      @commands[cmd] ||
        @commands[Digest::SHA256.hexdigest cmd] ||
        command_not_found(cmd)
    end
@username-is-already-taken2
Copy link
Contributor Author

forgot to say I'm running inspec version 0.14.3

@arlimus arlimus self-assigned this Mar 1, 2016
@arlimus
Copy link
Contributor

arlimus commented Mar 1, 2016

Hi @username-is-already-taken2 , great catch, bug confirmed! We'll get it straightened out in train.

@username-is-already-taken2
Copy link
Contributor Author

:) that's good. I thought you where going to tell me to rewrite my controls :)

@arlimus
Copy link
Contributor

arlimus commented Mar 1, 2016

It's an oversight, and I guess not the last one considering that we are trying to read ruby during inspec check without any actual data (since there's no target backend yet ;) ). Happy to find and solve these!

@arlimus arlimus added the Type: Bug Feature not working as expected label Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants