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

port() could convert string parameter to integer #867

Closed
nvtkaszpir opened this issue Aug 3, 2016 · 2 comments
Closed

port() could convert string parameter to integer #867

nvtkaszpir opened this issue Aug 3, 2016 · 2 comments
Labels
Type: Enhancement Improves an existing feature

Comments

@nvtkaszpir
Copy link
Contributor

nvtkaszpir commented Aug 3, 2016

Description

port() should accept string and try to convert it to integer, so:

port(123)
and
port('123')
would be equal

InSpec and Platform Version

0.28.0

Distributor ID: Ubuntu
Description: Ubuntu 15.10
Release: 15.10
Codename: wily

Replication Case


control 'port-param-by-number' do
  impact 1.0
  title 'ssh should listen on port 22, if parameter provided is as number'
  describe port(22) do
    it { should be_listening }
    its('processes') {should include 'sshd'}
  end
end

control 'port-param-by-string' do
  impact 1.0
  title 'ssh should listen on port 22, if parameter provided is as string'
  describe port('22') do
    it { should be_listening }
    its('processes') {should include 'sshd'}
  end
end

Possible Solutions

convert string to integer, sanitize it is a valid port number

Stacktrace

used port('3389'), and thus weird response:

  ✖  xrdp: xrdp should be listening on 3389 (2 failed)
     fail: expected `Port 3389.listening?` to return true, got false
     fail: expected [] to include "xrdp"

changed to port(3389) and it worked as expected.

@chris-rock chris-rock added the Type: Enhancement Improves an existing feature label Aug 4, 2016
@chris-rock
Copy link
Contributor

@nvtkaszpir This is a great idea. Are you going to add a PR?

@nvtkaszpir
Copy link
Contributor Author

nvtkaszpir commented Aug 4, 2016

I'm sorry I'm not a ruby dev and I'm unfortunately not having enough time to learn thoroughly ruby to commit patches. It's on my todo list but you know, I'm having already enough ops problems ;)

stevendanna added a commit that referenced this issue Aug 5, 2016
This allows the user to write:

   describe port(22) do
     it { should be_listening }
   end

as well as

   describe port('22') do
     it { should be_listening }
   end

without hitting an error.

Fixes #867

Signed-off-by: Steven Danna <steve@chef.io>
chris-rock pushed a commit that referenced this issue Aug 5, 2016
This allows the user to write:

   describe port(22) do
     it { should be_listening }
   end

as well as

   describe port('22') do
     it { should be_listening }
   end

without hitting an error.

Fixes #867

Signed-off-by: Steven Danna <steve@chef.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants