ione 1.2.0.pre1 → 1.2.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'ione/io/connection_common'
5
+
6
+
7
+ module Ione
8
+ module Io
9
+ describe SslServerConnection do
10
+ let :handler do
11
+ described_class.new(socket, 'example.com', 4444, unblocker, ssl_context, accept_callback, ssl_socket_impl)
12
+ end
13
+
14
+ let :socket do
15
+ double(:socket, close: nil)
16
+ end
17
+
18
+ let :unblocker do
19
+ double(:unblocker)
20
+ end
21
+
22
+ let :ssl_context do
23
+ double(:ssl_context)
24
+ end
25
+
26
+ let :ssl_socket do
27
+ double(:ssl_socket)
28
+ end
29
+
30
+ let :ssl_socket_impl do
31
+ double(:ssl_socket_impl)
32
+ end
33
+
34
+ let :accept_callback do
35
+ double(:accept_callback, call: nil)
36
+ end
37
+
38
+ before do
39
+ ssl_socket_impl.stub(:new).with(socket, ssl_context).and_return(ssl_socket)
40
+ ssl_socket.stub(:to_io).and_return(socket)
41
+ end
42
+
43
+ describe '#to_io' do
44
+ it 'returns the raw socket' do
45
+ handler.to_io.should equal(socket)
46
+ end
47
+
48
+ it 'returns an SSL socket once the SSL connection has been established' do
49
+ ssl_socket.stub(:accept_nonblock)
50
+ handler.read
51
+ handler.to_io.should equal(socket)
52
+ end
53
+ end
54
+
55
+ describe '#read' do
56
+ it 'creates an SSL socket with the specified SSL context' do
57
+ ssl_socket.stub(:accept_nonblock)
58
+ handler.read
59
+ ssl_socket_impl.should have_received(:new).with(socket, ssl_context)
60
+ end
61
+
62
+ it 'accepts the SSL connection' do
63
+ ssl_socket.stub(:accept_nonblock)
64
+ handler.read
65
+ ssl_socket.should have_received(:accept_nonblock)
66
+ end
67
+
68
+ it 'calls the callback once the SSL connection has been established' do
69
+ ssl_socket.stub(:accept_nonblock)
70
+ handler.read
71
+ accept_callback.should have_received(:call).with(handler)
72
+ end
73
+
74
+ it 'reads properly once the SSL connection has been established' do
75
+ ssl_socket.stub(:accept_nonblock)
76
+ ssl_socket.stub(:read_nonblock)
77
+ handler.read
78
+ handler.read
79
+ ssl_socket.should have_received(:read_nonblock)
80
+ end
81
+
82
+ it 'continues to attempt to accept the SSL connection until it succeeds' do
83
+ ssl_socket.stub(:accept_nonblock).and_raise(OpenSSL::SSL::SSLError, 'would block')
84
+ ssl_socket.stub(:read_nonblock)
85
+ handler.read
86
+ handler.read
87
+ handler.read
88
+ ssl_socket.stub(:accept_nonblock)
89
+ handler.read
90
+ handler.read
91
+ ssl_socket.should have_received(:read_nonblock)
92
+ end
93
+
94
+ it 'closes the connection when the SSL accept fails with an SSLError' do
95
+ ssl_socket.stub(:accept_nonblock).and_raise(OpenSSL::SSL::SSLError, 'general bork')
96
+ handler.read
97
+ handler.should be_closed
98
+ end
99
+
100
+ it 'closes the connection when the SSL accept fails for another reason' do
101
+ ssl_socket.stub(:accept_nonblock).and_raise(StandardError, 'general bork')
102
+ handler.read
103
+ handler.should be_closed
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ione
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.pre1
4
+ version: 1.2.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Hultberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-21 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Reactive programming framework for Ruby, painless evented IO, futures
14
14
  and an efficient byte buffer
@@ -29,8 +29,12 @@ files:
29
29
  - lib/ione/io/connection.rb
30
30
  - lib/ione/io/io_reactor.rb
31
31
  - lib/ione/io/server_connection.rb
32
+ - lib/ione/io/ssl_acceptor.rb
33
+ - lib/ione/io/ssl_connection.rb
34
+ - lib/ione/io/ssl_server_connection.rb
32
35
  - lib/ione/version.rb
33
36
  - spec/integration/io_spec.rb
37
+ - spec/integration/ssl_spec.rb
34
38
  - spec/ione/byte_buffer_spec.rb
35
39
  - spec/ione/future_spec.rb
36
40
  - spec/ione/io/acceptor_spec.rb
@@ -38,6 +42,9 @@ files:
38
42
  - spec/ione/io/connection_spec.rb
39
43
  - spec/ione/io/io_reactor_spec.rb
40
44
  - spec/ione/io/server_connection_spec.rb
45
+ - spec/ione/io/ssl_acceptor_spec.rb
46
+ - spec/ione/io/ssl_connection_spec.rb
47
+ - spec/ione/io/ssl_server_connection_spec.rb
41
48
  - spec/spec_helper.rb
42
49
  - spec/support/await_helper.rb
43
50
  - spec/support/fake_server.rb
@@ -67,6 +74,7 @@ specification_version: 4
67
74
  summary: Reactive programming framework for Ruby
68
75
  test_files:
69
76
  - spec/integration/io_spec.rb
77
+ - spec/integration/ssl_spec.rb
70
78
  - spec/ione/byte_buffer_spec.rb
71
79
  - spec/ione/future_spec.rb
72
80
  - spec/ione/io/acceptor_spec.rb
@@ -74,6 +82,9 @@ test_files:
74
82
  - spec/ione/io/connection_spec.rb
75
83
  - spec/ione/io/io_reactor_spec.rb
76
84
  - spec/ione/io/server_connection_spec.rb
85
+ - spec/ione/io/ssl_acceptor_spec.rb
86
+ - spec/ione/io/ssl_connection_spec.rb
87
+ - spec/ione/io/ssl_server_connection_spec.rb
77
88
  - spec/spec_helper.rb
78
89
  - spec/support/await_helper.rb
79
90
  - spec/support/fake_server.rb