1

I am writing a Chef cookbook which will, among other things, add some firewall rules. But before I do that I need to write a test for it. That's where I'm stuck!

What I need is Serverspec/Rspec code that verifies that it is not possible to send data over port 1234, even if something on the server is listening to that port.

How should I write that test?

Christoffer Reijer
  • 1,925
  • 2
  • 21
  • 40
  • 1
    Something along the line `describe host("localhost") { it { should_not be_reachable.with( :port => 1234, :proto => 'tcp' ) } }` in serverspec ? – Tensibai Feb 23 '16 at 16:08
  • (Previous comment is untested code, glanced from [here](http://serverspec.org/resource_types.html#host) and with a negative syntax) – Tensibai Feb 23 '16 at 16:16

1 Answers1

0

Found the answer in comment from @Tensibai

describe host('localhost') do
  before do
    @server = TCPServer.open 1234
  end

  it { should_not be_reachable.with(port: 1234, proto: :tcp) }

  after do
    @server.close
  end
end
Christoffer Reijer
  • 1,925
  • 2
  • 21
  • 40