mojombo-bertrpc 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/bertrpc.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bertrpc}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Tom Preston-Werner"]
data/lib/bertrpc/fun.rb CHANGED
@@ -19,8 +19,11 @@ module BERTRPC
19
19
  sock = TCPSocket.new(@svc.host, @svc.port)
20
20
  sock.write([bert_request.length].pack("N"))
21
21
  sock.write(bert_request)
22
- len = sock.read(4).unpack('N').first
22
+ lenheader = sock.read(4)
23
+ raise ProtocolError.new("Unable to read length header from server.") unless lenheader
24
+ len = lenheader.unpack('N').first
23
25
  bert_response = sock.read(len)
26
+ raise ProtocolError.new("Unable to read data from server.") unless bert_response
24
27
  sock.close
25
28
  bert_response
26
29
  end
data/test/fun_test.rb CHANGED
@@ -77,6 +77,29 @@ class FunTest < Test::Unit::TestCase
77
77
  TCPSocket.expects(:new).returns(io)
78
78
  assert_equal "bar", @fun.sync_request("foo")
79
79
  end
80
+
81
+ should "raise a ProxyError when the length is invalid" do
82
+ io = stub()
83
+ io.expects(:write).with("\000\000\000\003")
84
+ io.expects(:write).with("foo")
85
+ io.expects(:read).with(4).returns(nil)
86
+ TCPSocket.expects(:new).returns(io)
87
+ assert_raises(BERTRPC::ProtocolError) do
88
+ @fun.sync_request("foo")
89
+ end
90
+ end
91
+
92
+ should "raise a ProxyError when the data is invalid" do
93
+ io = stub()
94
+ io.expects(:write).with("\000\000\000\003")
95
+ io.expects(:write).with("foo")
96
+ io.expects(:read).with(4).returns("\000\000\000\003")
97
+ io.expects(:read).with(3).returns(nil)
98
+ TCPSocket.expects(:new).returns(io)
99
+ assert_raises(BERTRPC::ProtocolError) do
100
+ @fun.sync_request("foo")
101
+ end
102
+ end
80
103
  end
81
104
 
82
105
  context "ruby request encoder" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojombo-bertrpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner