arachni-rpc-em 0.1.3 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- require File.join( File.expand_path( File.dirname( __FILE__ ) ), '../../../', 'spec_helper' )
1
+ require 'spec_helper'
2
2
 
3
3
  describe Arachni::RPC::EM do
4
4
  end
@@ -1,4 +1,4 @@
1
- require File.join( File.expand_path( File.dirname( __FILE__ ) ), '../../../', 'spec_helper' )
1
+ require 'spec_helper'
2
2
 
3
3
  class Arachni::RPC::EM::Server
4
4
  public :async?, :async_check, :object_exist?, :public_method?
@@ -12,66 +12,118 @@ describe Arachni::RPC::EM::Server do
12
12
  @server = start_server( @opts, true )
13
13
  end
14
14
 
15
- describe "#initialize" do
16
- it "should be able to properly setup class options" do
15
+ describe '#initialize' do
16
+ it 'should be able to properly setup class options' do
17
17
  @server.opts.should == @opts
18
18
  end
19
+
20
+ context 'when passed no connection information' do
21
+ it 'raises ArgumentError' do
22
+ begin
23
+ described_class.new({})
24
+ rescue => e
25
+ e.should be_kind_of ArgumentError
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'when passed a host but not a port' do
31
+ it 'raises ArgumentError' do
32
+ begin
33
+ described_class.new( host: 'test' )
34
+ rescue => e
35
+ e.should be_kind_of ArgumentError
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'when passed a port but not a host' do
41
+ it 'raises ArgumentError' do
42
+ begin
43
+ described_class.new( port: 9999 )
44
+ rescue => e
45
+ e.should be_kind_of ArgumentError
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'when passed an invalid port' do
51
+ it 'raises ArgumentError' do
52
+ begin
53
+ described_class.new( host: 'tt', port: 'blah' )
54
+ rescue => e
55
+ e.should be_kind_of ArgumentError
56
+ end
57
+ end
58
+ end
19
59
  end
20
60
 
21
- it "should retain the supplied token" do
61
+ it 'retains the supplied token' do
22
62
  @server.token.should == @opts[:token]
23
63
  end
24
64
 
25
- it "should have a Logger" do
65
+ it 'has a Logger' do
26
66
  @server.logger.class.should == ::Logger
27
67
  end
28
68
 
29
- describe "#alive?" do
69
+ describe '#alive?' do
30
70
  subject { @server.alive? }
31
71
  it { should == true }
32
72
  end
33
73
 
34
- describe "#async?" do
35
-
36
- it "should return true for async methods" do
37
- @server.async?( 'test', 'async_foo' ).should be_true
74
+ describe '#async?' do
75
+ context 'when a method is async' do
76
+ it 'returns true' do
77
+ @server.async?( 'test', 'async_foo' ).should be_true
78
+ end
38
79
  end
39
80
 
40
- it "should return false for sync methods" do
41
- @server.async?( 'test', 'foo' ).should be_false
81
+ context 'when a method is sync' do
82
+ it 'returns false' do
83
+ @server.async?( 'test', 'foo' ).should be_false
84
+ end
42
85
  end
43
86
  end
44
87
 
45
- describe "#async_check" do
46
-
47
- it "should return true for async methods" do
48
- @server.async_check( Test.new.method( :async_foo ) ).should be_true
88
+ describe '#async_check' do
89
+ context 'when a method is async' do
90
+ it 'returns true' do
91
+ @server.async_check( Test.new.method( :async_foo ) ).should be_true
92
+ end
49
93
  end
50
94
 
51
- it "should return false for sync methods" do
52
- @server.async_check( Test.new.method( :foo ) ).should be_false
95
+ context 'when a method is sync' do
96
+ it 'returns false' do
97
+ @server.async_check( Test.new.method( :foo ) ).should be_false
98
+ end
53
99
  end
54
100
  end
55
101
 
56
- describe "#object_exist?" do
57
-
58
- it "should return true for valid objects" do
59
- @server.object_exist?( 'test' ).should be_true
102
+ describe '#object_exist?' do
103
+ context 'when an object exists' do
104
+ it 'returns true' do
105
+ @server.object_exist?( 'test' ).should be_true
106
+ end
60
107
  end
61
108
 
62
- it "should return false for inexistent objects" do
63
- @server.object_exist?( 'foo' ).should be_false
109
+ context 'when an object does not exist' do
110
+ it 'returns false' do
111
+ @server.object_exist?( 'foo' ).should be_false
112
+ end
64
113
  end
65
114
  end
66
115
 
67
- describe "#public_method?" do
68
-
69
- it "should return true for public methods" do
70
- @server.public_method?( 'test', 'foo' ).should be_true
116
+ describe '#public_method?' do
117
+ context 'when a method is public' do
118
+ it 'returns true' do
119
+ @server.public_method?( 'test', 'foo' ).should be_true
120
+ end
71
121
  end
72
122
 
73
- it "should return false for inexistent or non-public methods" do
74
- @server.public_method?( 'test', 'bar' ).should be_false
123
+ context 'when a method is non-existent or not public' do
124
+ it 'returns false' do
125
+ @server.public_method?( 'test', 'bar' ).should be_false
126
+ end
75
127
  end
76
128
  end
77
129
 
@@ -1,4 +1,4 @@
1
- require File.join( File.expand_path( File.dirname( __FILE__ ) ), '../../../', 'spec_helper' )
1
+ require 'spec_helper'
2
2
 
3
3
  class SSL
4
4
  include Arachni::RPC::EM::SSL
@@ -8,8 +8,11 @@
8
8
 
9
9
  =end
10
10
 
11
- $cwd = cwd = File.expand_path( File.dirname( __FILE__ ) )
12
- require File.join( cwd, '../../lib/arachni/rpc/', 'em' )
11
+ require_relative '../../lib/arachni/rpc/em'
12
+
13
+ def pems_path
14
+ File.expand_path( File.dirname( __FILE__ ) + '/../' )
15
+ end
13
16
 
14
17
  def rpc_opts
15
18
  {
@@ -20,26 +23,34 @@ def rpc_opts
20
23
  }
21
24
  end
22
25
 
26
+ def rpc_opts_with_socket
27
+ opts = rpc_opts
28
+ opts.delete( :host )
29
+ opts.delete( :port )
30
+
31
+ opts.merge( socket: '/tmp/arachni-rpc-em-test' )
32
+ end
33
+
23
34
  def rpc_opts_with_ssl_primitives
24
35
  rpc_opts.merge(
25
36
  port: 7332,
26
- ssl_ca: cwd + '/pems/cacert.pem',
27
- ssl_pkey: cwd + '/pems/client/key.pem',
28
- ssl_cert: cwd + '/pems/client/cert.pem'
37
+ ssl_ca: pems_path + '/pems/cacert.pem',
38
+ ssl_pkey: pems_path + '/pems/client/key.pem',
39
+ ssl_cert: pems_path + '/pems/client/cert.pem'
29
40
  )
30
41
  end
31
42
 
32
43
  def rpc_opts_with_invalid_ssl_primitives
33
44
  rpc_opts_with_ssl_primitives.merge(
34
- ssl_pkey: cwd + '/pems/client/foo-key.pem',
35
- ssl_cert: cwd + '/pems/client/foo-cert.pem'
45
+ ssl_pkey: pems_path + '/pems/client/foo-key.pem',
46
+ ssl_cert: pems_path + '/pems/client/foo-cert.pem'
36
47
  )
37
48
  end
38
49
 
39
50
  def rpc_opts_with_mixed_ssl_primitives
40
51
  rpc_opts_with_ssl_primitives.merge(
41
- ssl_pkey: cwd + '/pems/client/key.pem',
42
- ssl_cert: cwd + '/pems/client/foo-cert.pem'
52
+ ssl_pkey: pems_path + '/pems/client/key.pem',
53
+ ssl_cert: pems_path + '/pems/client/foo-cert.pem'
43
54
  )
44
55
  end
45
56
 
@@ -51,16 +62,14 @@ end
51
62
 
52
63
  class Test < Parent
53
64
 
54
- # in order to make inherited methods accessible you've got to explicitly
55
- # make them public
65
+ # In order to make inherited methods accessible you've got to explicitly
66
+ # make them public.
56
67
  private :foo
57
68
  public :foo
58
69
 
59
- #
60
70
  # Uses EventMachine to call the block asynchronously
61
- #
62
71
  def async_foo( arg, &block )
63
- ::EM.schedule { ::EM.defer { block.call( arg ) if block_given? } }
72
+ ::EM.schedule { block.call( arg ) if block_given? }
64
73
  end
65
74
 
66
75
  end
@@ -0,0 +1,11 @@
1
+ require_relative 'server'
2
+
3
+ $stdout.reopen( '/dev/null', 'w' )
4
+ $stderr.reopen( '/dev/null', 'w' )
5
+
6
+ opts = rpc_opts.merge(
7
+ socket: '/tmp/arachni-rpc-em-test',
8
+ serializer: Marshal
9
+ )
10
+
11
+ start_server( opts )
@@ -3,10 +3,9 @@ require_relative 'server'
3
3
  $stdout.reopen( '/dev/null', 'w' )
4
4
  $stderr.reopen( '/dev/null', 'w' )
5
5
 
6
- cwd = File.expand_path( File.dirname( __FILE__ ) )
7
6
  opts = rpc_opts.merge(
8
- port: 7333,
9
- serializer: YAML,
7
+ port: 7333,
8
+ serializer: YAML,
10
9
  fallback_serializer: Marshal
11
10
  )
12
11
 
@@ -1,5 +1,8 @@
1
1
  require_relative 'server'
2
2
 
3
+ $stdout.reopen( '/dev/null', 'w' )
4
+ $stderr.reopen( '/dev/null', 'w' )
5
+
3
6
  cwd = File.expand_path( File.dirname( __FILE__ ) )
4
7
  opts = rpc_opts.merge(
5
8
  port: 7332,
@@ -1,12 +1,8 @@
1
1
  require 'rspec'
2
2
  require 'timeout'
3
3
 
4
- def cwd
5
- File.expand_path( File.dirname( __FILE__ ) )
6
- end
7
-
8
- require File.join( cwd, '../lib/arachni/rpc/', 'em' )
9
- require File.join( cwd, 'servers', 'server' )
4
+ require_relative '../lib/arachni/rpc/em'
5
+ require_relative 'servers/server'
10
6
 
11
7
  def start_client( opts )
12
8
  Arachni::RPC::EM::Client.new( opts )
@@ -14,8 +10,8 @@ end
14
10
 
15
11
  def quiet_fork( &block )
16
12
  fork {
17
- $stdout.reopen( '/dev/null', 'w' )
18
- $stderr.reopen( '/dev/null', 'w' )
13
+ #$stdout.reopen( '/dev/null', 'w' )
14
+ #$stderr.reopen( '/dev/null', 'w' )
19
15
  block.call
20
16
  }
21
17
  end
@@ -30,9 +26,11 @@ RSpec.configure do |config|
30
26
  config.add_formatter :documentation
31
27
 
32
28
  config.before( :suite ) do
29
+ cwd = File.expand_path( File.dirname( __FILE__ ) )
33
30
  server_pids << quiet_spawn( File.join( cwd, 'servers', 'basic.rb' ) )
34
31
  server_pids << quiet_spawn( File.join( cwd, 'servers', 'with_ssl_primitives.rb' ) )
35
32
  server_pids << quiet_spawn( File.join( cwd, 'servers', 'with_fallback.rb' ) )
33
+ server_pids << quiet_spawn( File.join( cwd, 'servers', 'unix_socket.rb' ) )
36
34
  server_pids.each { |pid| Process.detach( pid ) }
37
35
  sleep 2
38
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arachni-rpc-em
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
12
+ date: 2013-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -59,6 +59,38 @@ dependencies:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.1.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
62
94
  description: ! " EventMachine-based client and server implementation of Arachni-RPC
63
95
  supporting\n TLS encryption, asynchronous and synchronous requests and\n
64
96
  \ capable of handling remote asynchronous calls that require a block.\n"
@@ -78,8 +110,10 @@ files:
78
110
  - lib/arachni/rpc/em/em.rb
79
111
  - lib/arachni/rpc/em/client.rb
80
112
  - lib/arachni/rpc/em/server.rb
113
+ - lib/arachni/rpc/em/server/handler.rb
81
114
  - lib/arachni/rpc/em/protocol.rb
82
115
  - lib/arachni/rpc/em/connection_utilities.rb
116
+ - lib/arachni/rpc/em/client/handler.rb
83
117
  - lib/arachni/rpc/em/ssl.rb
84
118
  - lib/arachni/rpc/em.rb
85
119
  - examples/client.EM.run.rb
@@ -99,6 +133,7 @@ files:
99
133
  - spec/spec_helper.rb
100
134
  - spec/servers/with_fallback.rb
101
135
  - spec/servers/server.rb
136
+ - spec/servers/unix_socket.rb
102
137
  - spec/servers/basic.rb
103
138
  - spec/servers/with_ssl_primitives.rb
104
139
  homepage: https://github.com/Arachni/arachni-rpc-em
@@ -114,12 +149,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
149
  - - ! '>='
115
150
  - !ruby/object:Gem::Version
116
151
  version: '0'
152
+ segments:
153
+ - 0
154
+ hash: 2951551250671031886
117
155
  required_rubygems_version: !ruby/object:Gem::Requirement
118
156
  none: false
119
157
  requirements:
120
158
  - - ! '>='
121
159
  - !ruby/object:Gem::Version
122
160
  version: '0'
161
+ segments:
162
+ - 0
163
+ hash: 2951551250671031886
123
164
  requirements: []
124
165
  rubyforge_project:
125
166
  rubygems_version: 1.8.25
@@ -142,5 +183,7 @@ test_files:
142
183
  - spec/spec_helper.rb
143
184
  - spec/servers/with_fallback.rb
144
185
  - spec/servers/server.rb
186
+ - spec/servers/unix_socket.rb
145
187
  - spec/servers/basic.rb
146
188
  - spec/servers/with_ssl_primitives.rb
189
+ has_rdoc: