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

command resource check doesn't fail when it should #1318

Closed
walterdolce opened this issue Nov 23, 2016 · 3 comments
Closed

command resource check doesn't fail when it should #1318

walterdolce opened this issue Nov 23, 2016 · 3 comments

Comments

@walterdolce
Copy link

Description

Provided from the terminal I get:

$ which telnet
/usr/bin/telnet

Given the following control:

# encoding: utf-8
# copyright: 2015, Walter Dolce <walterdolce@gmail.com>
# license: Apache License 2.0
title 'telnet'

control 'telnet-executable-in-path' do
  impact 0.7
  title 'Verifies whether there is a telnet executable available in $PATH'
  desc title
  describe command('which telnet') do
    it { should_not exist }
  end
end

When I run InSpec it doesn't fail.
I would expect it to fail given the test says "make sure there's no executable named telnet callable from within the $PATH".

InSpec and Platform Version

InSpec version is 1.0.0
Platform info:

Name:      mac_os_x
Family:    darwin
Release:   10.10.5
Arch:      x86_64

Replication Case

You should be able to run the control above as is.

Possible Solutions

Not sure yet. Will have to have a look at InSpec's code.

Stacktrace

None available.

@walterdolce
Copy link
Author

walterdolce commented Nov 24, 2016

I am investigating this issue while someone comes in and replies.

This line of code is being executed and it's returning:
bash: line 0: type: which telnet: not found

But if I do:

fish-shell$ bash
bash-shell$ which telnet
/usr/bin/telnet

Or:

fish-shell$ bash -c "which telnet"
/usr/bin/telnet

Why are commands being run this way?

bash -c 'type "{{command}}"'

@walterdolce
Copy link
Author

Hm. I guess I should change:

describe command('which telnet') do
    it { should_not exist }
end

To just:

describe command('telnet') do
    it { should_not exist }
  end

Or change the expectation:

describe command('which telnet') do
    its('exit_status') { should_not eq 0 }
end

@walterdolce
Copy link
Author

I think I answered my own question. Will use:

describe command('telnet') do
   it { should_not exist }
end

Which I find more readable and does strip the dependency on which out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant