summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2013-05-20 16:25:48 +0100
committerSteve Kemp <steve@steve.org.uk>2013-05-20 16:25:48 +0100
commitc77b0deb8db50a9cc01a2211ebaa9c7a98de2e08 (patch)
treeafcc6df96a21489992125318696d225e6bdce651
parent563c35728746be129303ea50e5fd0e6028721ddc (diff)
The banner matching now copes with a string or a regexp.
-rw-r--r--lib/custodian/protocoltest/tcp.rb21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb
index b4a23b2..e21e5a5 100644
--- a/lib/custodian/protocoltest/tcp.rb
+++ b/lib/custodian/protocoltest/tcp.rb
@@ -158,8 +158,10 @@ module Custodian
read = socket.sysread(1024) if ( do_read )
# trim to a sane length & strip newlines.
- read = read[0,255] unless ( read.nil? )
- read.gsub!(/[\n\r]/, "") unless ( read.nil? )
+ if ( ! read.nil? )
+ read = read[0,255]
+ read.gsub!(/[\n\r]/, "")
+ end
socket.close()
@@ -168,8 +170,19 @@ module Custodian
return true
else
# test for banner
- if ( ( !read.nil? ) && ( banner.match(read) ) )
- return true
+
+ # regexp.
+ if ( banner.class == "Regexp" )
+ if ( ( !read.nil? ) && ( banner.match(read) ) )
+ return true
+ end
+ end
+
+ # string.
+ if ( banner.class == "String" )
+ if ( ( !read.nil? ) && ( read =~ /#{banner}/i ) )
+ return true
+ end
end
@error = "We expected a banner matching '#{banner}' but we got '#{read}'"