Class: Serverspec::Type::Bitlbee
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::Bitlbee
- Defined in:
- lib/serverspec_extended_types/bitlbee.rb
Instance Method Summary collapse
-
#communicate ⇒ nil
private
Login to IRC and get version, over @socket.
-
#connect ⇒ nil
private
connection to the IRC server (without SSL).
-
#connect_ssl ⇒ nil
private
Open SSL connection to the IRC server.
-
#connectable? ⇒ Boolean
Check whether we can successfully connect.
-
#initialize(port, nick, password, use_ssl = false) ⇒ Bitlbee
constructor
Bitlbee constructor.
-
#start ⇒ nil
private
Begin timeout-wrapped connection.
-
#timed_out? ⇒ Boolean
Check whether the connection timed out.
-
#version ⇒ String
Return the version string from Bitlbee.
Constructor Details
#initialize(port, nick, password, use_ssl = false) ⇒ Bitlbee
Bitlbee constructor
Connects to Bitlbee on the host specified by ENV
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/serverspec_extended_types/bitlbee.rb', line 43 def initialize(port, nick, password, use_ssl=false) @port = port @host = ENV['TARGET_HOST'] @nick = nick @use_ssl = use_ssl @password = password @connected_status = false @version_str = "" @timed_out_status = false @started = false end |
Instance Method Details
#communicate ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Login to IRC and get version, over @socket
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/serverspec_extended_types/bitlbee.rb', line 107 def communicate password = @password nick = @nick @socket.puts("PASS #{password}\n") @socket.puts("NICK #{nick}\n") @socket.puts("USER #{nick} #{nick} servername :TestUser\n") while buf = (@socket.readpartial(1024) rescue nil ) @connected_status = true (data||="") << buf if data =~ /Welcome to the/ @socket.puts("MODE #{nick} +i\n") data = "" elsif data =~ /If you've never/ @socket.puts("PRIVMSG &bitlbee :identify #{password}\n") data = "" elsif data =~ /PING (\S+)/ @socket.puts(":#{$1} PONG #{$1} :#{$1}\n") data = "" elsif data =~ /MODE #{nick} :\+i/ break end end @socket.puts("PRIVMSG root :\001VERSION\001\n") while buf = (@socket.readpartial(1024) rescue nil ) (data||="") << buf if data =~ /VERSION (.+)/ @version_str = $1 break end end end |
#connect ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
connection to the IRC server (without SSL)
79 80 81 82 83 84 |
# File 'lib/serverspec_extended_types/bitlbee.rb', line 79 def connect @socket = TCPSocket.open(@host, @port) communicate @socket.puts("QUIT :\"outta here\"\n") @socket.close end |
#connect_ssl ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Open SSL connection to the IRC server
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/serverspec_extended_types/bitlbee.rb', line 90 def connect_ssl sock = TCPSocket.open(@host, @port) ctx = OpenSSL::SSL::SSLContext.new ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_NONE) @socket = OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |socket| socket.sync_close = true socket.connect end communicate @socket.puts("QUIT :\"outta here\"\n") @socket.close end |
#connectable? ⇒ Boolean
Check whether we can successfully connect
162 163 164 165 |
# File 'lib/serverspec_extended_types/bitlbee.rb', line 162 def connectable? start if not @started @connected_status end |
#start ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Begin timeout-wrapped connection
This just calls #connect within a 10-second Timeout::timeout wrapper, and handles both timeout and Errno::ECONNREFUSED.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/serverspec_extended_types/bitlbee.rb', line 62 def start @started = true begin Timeout::timeout(10) do @use_ssl ? ( connect_ssl ) : ( connect ) end rescue Timeout::Error @timed_out_status = true rescue Errno::ECONNREFUSED @connected_status = false end end |
#timed_out? ⇒ Boolean
Check whether the connection timed out
148 149 150 151 |
# File 'lib/serverspec_extended_types/bitlbee.rb', line 148 def timed_out? start if not @started @timed_out_status end |
#version ⇒ String
Return the version string from Bitlbee
176 177 178 179 |
# File 'lib/serverspec_extended_types/bitlbee.rb', line 176 def version start if not @started @version_str end |