arachni-reactor 0.1.0.beta5 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,117 +16,28 @@ shared_examples_for 'Arachni::Reactor::Connection' do
16
16
  let(:data) { 'b' * 5 * block_size }
17
17
  let(:configured) do
18
18
  connection.reactor = reactor
19
- connection.configure socket, role, server_handler
20
- connection
21
- end
22
-
23
- # This needs to be put in a file of its own.
24
- describe '::PeerInfo' do
25
- describe '#peer_address_info' do
26
- context 'when using an IP socket' do
27
- let(:connection) { echo_client_handler }
28
- let(:role) { :client }
29
- let(:socket) { client_socket }
30
-
31
- it 'returns IP address information' do
32
- s = peer_server_socket
33
- configured
34
-
35
- Thread.new do
36
- s = s.accept
37
- end
38
-
39
- IO.select( nil, [configured.socket] )
40
-
41
- info = {}
42
- info[:protocol], info[:port], info[:hostname], info[:ip_address] = s.to_io.addr
43
- configured.peer_address_info.should == info
44
-
45
- info = {}
46
- info[:protocol], info[:port], info[:hostname], info[:ip_address] = s.to_io.addr(false)
47
- configured.peer_address_info(false).should == info
48
-
49
- info = {}
50
- info[:protocol], info[:port], info[:hostname], info[:ip_address] = s.to_io.addr(true)
51
- configured.peer_address_info(true).should == info
52
- end
53
- end
54
-
55
- context 'when using UNIX-domain socket',
56
- if: Arachni::Reactor.supports_unix_sockets? do
57
-
58
- let(:connection) { echo_client_handler }
59
- let(:role) { :client }
60
- let(:socket) { unix_socket }
61
-
62
- it 'returns socket information' do
63
- configured
64
-
65
- IO.select( nil, [configured.socket] )
66
-
67
- info = {}
68
- info[:protocol], info[:path] = 'AF_UNIX', socket.path
69
- configured.peer_address_info.should == info
70
- end
71
- end
72
- end
73
-
74
- describe '#peer_hostname' do
75
- let(:connection) { echo_client_handler }
76
- let(:role) { :client }
77
- let(:socket) { client_socket }
78
-
79
- it 'returns the peer hostname' do
80
- s = peer_server_socket
81
- configured
82
-
83
- Thread.new do
84
- s = s.accept
85
- end
86
-
87
- IO.select( nil, [configured.socket] )
88
-
89
- configured.peer_hostname.should == s.to_io.addr(true)[2]
90
- end
91
- end
92
-
93
- describe '#peer_ip_address' do
94
- let(:connection) { echo_client_handler }
95
- let(:role) { :client }
96
- let(:socket) { client_socket }
97
-
98
- it 'returns the peer IP address' do
99
- s = peer_server_socket
100
- configured
101
-
102
- Thread.new do
103
- s = s.accept
19
+ connection.configure(
20
+ host: host,
21
+ port: port,
22
+ socket: socket,
23
+ role: role,
24
+ server_handler: server_handler
25
+ )
26
+
27
+ if role == :client
28
+ while !connection.connected?
29
+ begin
30
+ IO.select( [connection.socket], [connection.socket], nil, 0.1 )
31
+ rescue => e
32
+ ap e
33
+ break
104
34
  end
105
35
 
106
- IO.select( nil, [configured.socket] )
107
-
108
- configured.peer_ip_address.should == s.to_io.addr[3]
36
+ connection._connect
109
37
  end
110
38
  end
111
39
 
112
- describe '#peer_port' do
113
- let(:connection) { echo_client_handler }
114
- let(:role) { :client }
115
- let(:socket) { client_socket }
116
-
117
- it 'returns the peer IP address' do
118
- s = peer_server_socket
119
- configured
120
-
121
- Thread.new do
122
- s = s.accept
123
- end
124
-
125
- IO.select( nil, [configured.socket] )
126
-
127
- configured.peer_port.should == s.to_io.addr[1]
128
- end
129
- end
40
+ connection
130
41
  end
131
42
 
132
43
  describe '#configure' do
@@ -157,12 +68,12 @@ shared_examples_for 'Arachni::Reactor::Connection' do
157
68
  end
158
69
  end
159
70
 
160
- it 'calls #on_connect' do
161
- peer_server_socket
162
- connection.should receive(:on_connect)
163
- connection.reactor = reactor
164
- connection.configure socket, role
165
- end
71
+ # it 'calls #on_connect' do
72
+ # peer_server_socket
73
+ # connection.should receive(:on_connect)
74
+ # connection.reactor = reactor
75
+ # connection.configure socket: socket, role: role
76
+ # end
166
77
  end
167
78
 
168
79
  describe '#unix?' do
@@ -172,7 +83,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
172
83
  let(:socket) { client_socket }
173
84
 
174
85
  it 'returns false' do
175
- s = peer_server_socket
86
+ peer_server_socket
176
87
  configured
177
88
  configured.should_not be_unix
178
89
  end
@@ -186,7 +97,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
186
97
  let(:socket) { unix_socket }
187
98
 
188
99
  it 'returns true' do
189
- s = peer_server_socket
100
+ peer_server_socket
190
101
  configured
191
102
  configured.should be_unix
192
103
  end
@@ -200,7 +111,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
200
111
  let(:socket) { client_socket }
201
112
 
202
113
  it 'returns false' do
203
- s = peer_server_socket
114
+ peer_server_socket
204
115
  configured
205
116
  configured.should be_inet
206
117
  end
@@ -214,7 +125,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
214
125
  let(:socket) { unix_socket }
215
126
 
216
127
  it 'returns false' do
217
- s = peer_server_socket
128
+ peer_server_socket
218
129
  configured
219
130
  configured.should_not be_inet
220
131
  end
@@ -240,7 +151,6 @@ shared_examples_for 'Arachni::Reactor::Connection' do
240
151
  if: Arachni::Reactor.supports_unix_sockets? do
241
152
 
242
153
  let(:connection) { echo_client_handler }
243
- let(:role) { :client }
244
154
  let(:socket) { unix_server_socket }
245
155
 
246
156
  it 'returns UNIXServer' do
@@ -278,7 +188,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
278
188
 
279
189
  it 'returns TCPSocket' do
280
190
  peer_server_socket
281
- configured.to_io.should be_instance_of TCPSocket
191
+ configured.to_io.should be_instance_of Socket
282
192
  end
283
193
  end
284
194
 
@@ -315,7 +225,6 @@ shared_examples_for 'Arachni::Reactor::Connection' do
315
225
  if: Arachni::Reactor.supports_unix_sockets? do
316
226
 
317
227
  let(:connection) { echo_client_handler }
318
- let(:role) { :client }
319
228
  let(:socket) { unix_server_socket }
320
229
 
321
230
  it 'returns true' do
@@ -381,10 +290,10 @@ shared_examples_for 'Arachni::Reactor::Connection' do
381
290
 
382
291
  reactor.run_in_thread
383
292
 
384
- connection.attach( reactor ).should be_true
293
+ connection.attach( reactor ).should be_truthy
385
294
  sleep 1
386
295
 
387
- reactor.attached?( configured ).should be_true
296
+ reactor.attached?( configured ).should be_truthy
388
297
  end
389
298
 
390
299
  it 'calls #on_attach' do
@@ -410,7 +319,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
410
319
  connection.attach reactor
411
320
  sleep 0.1 while connection.detached?
412
321
 
413
- connection.attach( reactor ).should be_false
322
+ connection.attach( reactor ).should be_falsey
414
323
  end
415
324
  end
416
325
 
@@ -428,11 +337,11 @@ shared_examples_for 'Arachni::Reactor::Connection' do
428
337
  r.run_in_thread
429
338
 
430
339
  configured.should receive(:on_detach)
431
- connection.attach( r ).should be_true
340
+ connection.attach( r ).should be_truthy
432
341
 
433
342
  sleep 2
434
343
 
435
- r.attached?( configured ).should be_true
344
+ r.attached?( configured ).should be_truthy
436
345
  end
437
346
  end
438
347
  end
@@ -454,7 +363,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
454
363
  connection.detach
455
364
  sleep 0.1 while connection.attached?
456
365
 
457
- reactor.attached?( configured ).should be_false
366
+ reactor.attached?( configured ).should be_falsey
458
367
  end
459
368
 
460
369
  it 'calls #on_detach' do
@@ -479,7 +388,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
479
388
  let(:socket) { client_socket }
480
389
 
481
390
  it 'appends the given data to the send-buffer' do
482
- s = peer_server_socket
391
+ peer_server_socket
483
392
  reactor.run_in_thread
484
393
 
485
394
  configured
@@ -488,8 +397,8 @@ shared_examples_for 'Arachni::Reactor::Connection' do
488
397
  received = ''
489
398
 
490
399
  t = Thread.new do
491
- s = s.accept
492
- received << s.read( data.size ) while received.size != data.size
400
+ sleep 0.1 while !accepted
401
+ received << accepted.read( data.size ) while received.size != data.size
493
402
  all_read = true
494
403
  end
495
404
 
@@ -548,13 +457,13 @@ shared_examples_for 'Arachni::Reactor::Connection' do
548
457
  let(:socket) { client_socket }
549
458
 
550
459
  it "reads a maximum of #{Arachni::Reactor::Connection::BLOCK_SIZE} bytes at a time" do
551
- s = peer_server_socket
460
+ peer_server_socket
552
461
  configured
553
462
 
554
463
  Thread.new do
555
- s = s.accept
556
- s.write data
557
- s.flush
464
+ sleep 0.1 while !accepted
465
+ accepted.write data
466
+ accepted.flush
558
467
  end
559
468
 
560
469
  while configured.received_data.to_s.size != data.size
@@ -567,15 +476,15 @@ shared_examples_for 'Arachni::Reactor::Connection' do
567
476
  end
568
477
 
569
478
  it 'passes the data to #on_read' do
570
- s = peer_server_socket
479
+ peer_server_socket
571
480
  configured
572
481
 
573
482
  data = "test\n"
574
483
 
575
484
  Thread.new do
576
- s = s.accept
577
- s.write data
578
- s.flush
485
+ sleep 0.1 while !accepted
486
+ accepted.write data
487
+ accepted.flush
579
488
  end
580
489
 
581
490
  configured._read while !configured.received_data
@@ -618,6 +527,8 @@ shared_examples_for 'Arachni::Reactor::Connection' do
618
527
  reactor.run_in_thread
619
528
  end
620
529
 
530
+ let(:port) { @port }
531
+ let(:host) { @host }
621
532
  let(:connection) { echo_client_handler }
622
533
  let(:role) { :client }
623
534
  let(:socket) { echo_client }
@@ -634,7 +545,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
634
545
  next
635
546
  end
636
547
 
637
- written.should == block_size
548
+ written.should <= block_size
638
549
  writes += 1
639
550
  end
640
551
 
@@ -647,17 +558,14 @@ shared_examples_for 'Arachni::Reactor::Connection' do
647
558
 
648
559
  writes = 0
649
560
  while configured.has_outgoing_data?
650
-
651
561
  IO.select( nil, [configured.socket] )
652
- if configured._write == 0
653
- IO.select( [configured.socket] )
654
- next
655
- end
562
+
563
+ next if configured._write == 0
656
564
 
657
565
  writes += 1
658
566
  end
659
567
 
660
- configured.on_write_count.should == writes
568
+ configured.on_write_count.should >= writes
661
569
  end
662
570
 
663
571
  context 'when the buffer is entirely consumed' do
@@ -668,20 +576,21 @@ shared_examples_for 'Arachni::Reactor::Connection' do
668
576
  while configured.has_outgoing_data?
669
577
  IO.select( nil, [configured.socket] )
670
578
 
671
- if (written = configured._write) == 0
579
+ if configured._write == 0
672
580
  IO.select( [configured.socket] )
673
581
  next
674
582
  end
675
-
676
- written.should == block_size
677
583
  end
678
584
 
679
- configured.called_on_flush.should be_true
585
+ configured.called_on_flush.should be_truthy
680
586
  end
681
587
  end
682
588
  end
683
589
 
684
590
  describe '#has_outgoing_data?' do
591
+ let(:port) { @port }
592
+ let(:host) { @host }
593
+
685
594
  let(:role) { :client }
686
595
  let(:socket) { echo_client }
687
596
 
@@ -692,18 +601,21 @@ shared_examples_for 'Arachni::Reactor::Connection' do
692
601
  configured.write 'test'
693
602
  sleep 0.1 while !configured.has_outgoing_data?
694
603
 
695
- configured.has_outgoing_data?.should be_true
604
+ configured.has_outgoing_data?.should be_truthy
696
605
  end
697
606
  end
698
607
 
699
608
  context 'when the send-buffer is empty' do
700
609
  it 'returns false' do
701
- configured.has_outgoing_data?.should be_false
610
+ configured.has_outgoing_data?.should be_falsey
702
611
  end
703
612
  end
704
613
  end
705
614
 
706
615
  describe '#closed?' do
616
+ let(:port) { @port }
617
+ let(:host) { @host }
618
+
707
619
  let(:role) { :client }
708
620
  let(:socket) { echo_client }
709
621
 
@@ -725,6 +637,9 @@ shared_examples_for 'Arachni::Reactor::Connection' do
725
637
  end
726
638
 
727
639
  describe '#close_without_callback' do
640
+ let(:port) { @port }
641
+ let(:host) { @host }
642
+
728
643
  let(:role) { :client }
729
644
  let(:socket) { echo_client }
730
645
 
@@ -753,6 +668,9 @@ shared_examples_for 'Arachni::Reactor::Connection' do
753
668
  end
754
669
 
755
670
  describe '#close' do
671
+ let(:port) { @port }
672
+ let(:host) { @host }
673
+
756
674
  let(:role) { :client }
757
675
  let(:socket) { echo_client }
758
676
 
@@ -158,7 +158,7 @@ shared_examples_for 'Arachni::Reactor' do
158
158
  end
159
159
 
160
160
  subject.should_not be_running
161
- running.should be_true
161
+ running.should be_truthy
162
162
  end
163
163
 
164
164
  context 'when no block is given' do
@@ -816,6 +816,9 @@ shared_examples_for 'Arachni::Reactor' do
816
816
  subject.listen( host, port, echo_server_handler, *options )
817
817
 
818
818
  @socket = tcp_writer.call( host, port, data )
819
+
820
+ sleep 5
821
+
819
822
  subject.connections.values.first.initialization_args.should == options
820
823
  end
821
824
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arachni-reactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta5
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2021-12-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Arachni::Reactor is a simple, lightweight, pure-Ruby implementation of the Reactor
@@ -93,49 +93,48 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">"
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
- version: 1.3.1
98
+ version: '0'
99
99
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.2.2
100
+ rubygems_version: 3.3.0.dev
102
101
  signing_key:
103
102
  specification_version: 4
104
103
  summary: A pure-Ruby implementation of the Reactor pattern.
105
104
  test_files:
106
- - spec/support/fixtures/pems/server/cert.pem
107
- - spec/support/fixtures/pems/server/key.pem
105
+ - spec/arachni/reactor/connection/tls_spec.rb
106
+ - spec/arachni/reactor/connection_spec.rb
107
+ - spec/arachni/reactor/iterator_spec.rb
108
+ - spec/arachni/reactor/queue_spec.rb
109
+ - spec/arachni/reactor/tasks/base.rb
110
+ - spec/arachni/reactor/tasks/delayed_spec.rb
111
+ - spec/arachni/reactor/tasks/one_off_spec.rb
112
+ - spec/arachni/reactor/tasks/periodic_spec.rb
113
+ - spec/arachni/reactor/tasks/persistent_spec.rb
114
+ - spec/arachni/reactor/tasks_spec.rb
115
+ - spec/arachni/reactor_spec.rb
116
+ - spec/arachni/reactor_tls_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/fixtures/handlers/echo_client.rb
119
+ - spec/support/fixtures/handlers/echo_client_tls.rb
120
+ - spec/support/fixtures/handlers/echo_server.rb
121
+ - spec/support/fixtures/handlers/echo_server_tls.rb
108
122
  - spec/support/fixtures/pems/cacert.pem
109
- - spec/support/fixtures/pems/client/foo-key.pem
110
123
  - spec/support/fixtures/pems/client/cert.pem
111
124
  - spec/support/fixtures/pems/client/foo-cert.pem
125
+ - spec/support/fixtures/pems/client/foo-key.pem
112
126
  - spec/support/fixtures/pems/client/key.pem
113
- - spec/support/fixtures/handlers/echo_client.rb
114
- - spec/support/fixtures/handlers/echo_server.rb
115
- - spec/support/fixtures/handlers/echo_client_tls.rb
116
- - spec/support/fixtures/handlers/echo_server_tls.rb
117
- - spec/support/servers/echo_unix.rb
118
- - spec/support/servers/echo_tls.rb
119
- - spec/support/servers/echo.rb
120
- - spec/support/servers/echo_unix_tls.rb
121
- - spec/support/helpers/utilities.rb
127
+ - spec/support/fixtures/pems/server/cert.pem
128
+ - spec/support/fixtures/pems/server/key.pem
122
129
  - spec/support/helpers/paths.rb
123
- - spec/support/lib/servers.rb
124
- - spec/support/lib/servers/runner.rb
130
+ - spec/support/helpers/utilities.rb
125
131
  - spec/support/lib/server_option_parser.rb
126
- - spec/support/shared/reactor.rb
132
+ - spec/support/lib/servers/runner.rb
133
+ - spec/support/lib/servers.rb
134
+ - spec/support/servers/echo.rb
135
+ - spec/support/servers/echo_tls.rb
136
+ - spec/support/servers/echo_unix.rb
137
+ - spec/support/servers/echo_unix_tls.rb
127
138
  - spec/support/shared/connection.rb
139
+ - spec/support/shared/reactor.rb
128
140
  - spec/support/shared/task.rb
129
- - spec/spec_helper.rb
130
- - spec/arachni/reactor_tls_spec.rb
131
- - spec/arachni/reactor_spec.rb
132
- - spec/arachni/reactor/queue_spec.rb
133
- - spec/arachni/reactor/tasks_spec.rb
134
- - spec/arachni/reactor/connection_spec.rb
135
- - spec/arachni/reactor/iterator_spec.rb
136
- - spec/arachni/reactor/connection/tls_spec.rb
137
- - spec/arachni/reactor/tasks/base.rb
138
- - spec/arachni/reactor/tasks/persistent_spec.rb
139
- - spec/arachni/reactor/tasks/delayed_spec.rb
140
- - spec/arachni/reactor/tasks/one_off_spec.rb
141
- - spec/arachni/reactor/tasks/periodic_spec.rb