toq 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4a52cfe51fc062860cb41237c2453b35ccc2b7c7447491a8fb0e3bb5578c26c
4
- data.tar.gz: 58c73eef95e49b2cd66ab977b3d6fc70a3705f0a79000c0c2db05bc50804618f
3
+ metadata.gz: 272f1b4331d14f8c5d4b9dcb5969e83a6c6f189de4cfe38a533c4d0660d44d23
4
+ data.tar.gz: 43752df680609784b637d8e5398403b96190899b1492ce870cac212dd72d9ee5
5
5
  SHA512:
6
- metadata.gz: e74a30760feac7886f77c025f975df9fd9d4cb0aa36d8f3105f74b1fbbc43508b259db5a2f6d443f268b88174b6cdc9f17149766f88ed3b47408b9363a099d79
7
- data.tar.gz: d9cde530727fdb95148c404a0d02884c46278f2537d88c55e99e1c0393a056b892ae9d9aa01bfaa9acfb47f23a28a4cca6dd67a8a9e627cb150cb276d3614ae7
6
+ metadata.gz: 9c9de3857a967e239b15a6160d6aed561fbb0e3a3bd31a0e9040f7b84b4ef33a5f12205f1fc17e042d466355d318a1073ee4b5955ef246fdbbf6cd1039c5d159
7
+ data.tar.gz: ea66f7e0a9ae201bbdcffe8c6220bf989f680f5a8aa54fff297ac6c6fc89e8cf95fc7c2bcc113dc6a8d4c19da5ad53eab2c0faba5d59a326e24f14802852ed12
data/lib/toq/client.rb CHANGED
@@ -91,10 +91,6 @@ class Client
91
91
 
92
92
  @reactor = Raktr.new
93
93
 
94
- @reactor.on_error do |e|
95
- p e
96
- end
97
-
98
94
  @connections = @reactor.create_queue
99
95
  @connection_count = 0
100
96
  end
@@ -116,6 +116,15 @@ module Exceptions
116
116
 
117
117
  end
118
118
 
119
+ class UnsafeMethod < Base
120
+
121
+ # @return [Bool] true
122
+ def rpc_unsafe_method_error?
123
+ true
124
+ end
125
+
126
+ end
127
+
119
128
  # An invalid method has been called.
120
129
  #
121
130
  # Occurs when a remote method doesn't exist or isn't public.
data/lib/toq/server.rb CHANGED
@@ -100,10 +100,6 @@ class Server
100
100
 
101
101
  @reactor = Raktr.global
102
102
 
103
- @reactor.on_error do |e|
104
- @logger.error( 'System' ){ "#{e}" }
105
- end
106
-
107
103
  clear_handlers
108
104
  end
109
105
 
@@ -192,6 +188,12 @@ class Server
192
188
  raise Exceptions::InvalidObject.new( msg )
193
189
  end
194
190
 
191
+ if !method_safe?( obj_name, meth_name )
192
+ msg = "Trying to access unsafe method '#{meth_name}'."
193
+ @logger.error( 'Call' ){ msg + " [on behalf of #{peer_ip_addr}]" }
194
+ raise Exceptions::UnsafeMethod.new( msg )
195
+ end
196
+
195
197
  # The handler needs to know if this is an async call because if it is
196
198
  # we'll have already send the response and it doesn't need to do
197
199
  # transmit anything.
@@ -263,6 +265,28 @@ class Server
263
265
  !!@objects[obj_name]
264
266
  end
265
267
 
268
+ def method_safe?( obj_name, meth_name )
269
+ ancestors = @objects[obj_name].class.ancestors - [Object, Kernel, BasicObject]
270
+
271
+ ancestors.each do |ancestor|
272
+ case ancestor
273
+ when Class
274
+ if ancestor.allocate.public_methods( false ).include? meth_name.to_sym
275
+ return true
276
+ end
277
+
278
+ when Module
279
+ object = Object.new
280
+ object.extend( ancestor )
281
+ if object.public_methods( false ).include? meth_name.to_sym
282
+ return true
283
+ end
284
+ end
285
+ end
286
+
287
+ false
288
+ end
289
+
266
290
  end
267
291
 
268
292
  end
data/lib/toq/version.rb CHANGED
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Toq
10
10
 
11
- VERSION = '0.0.4'
11
+ VERSION = '0.1.0'
12
12
 
13
13
  end
@@ -45,14 +45,30 @@ def rpc_opts_with_mixed_ssl_primitives
45
45
  )
46
46
  end
47
47
 
48
+ module MyModule
49
+ def in_module
50
+ true
51
+ end
52
+ end
53
+
48
54
  class Parent
55
+ include MyModule
56
+
49
57
  def foo( arg )
50
58
  arg
51
59
  end
60
+
61
+ def in_parent
62
+ true
63
+ end
52
64
  end
53
65
 
54
66
  class Test < Parent
55
67
 
68
+ def in_child
69
+ true
70
+ end
71
+
56
72
  def delay( arg, &block )
57
73
  Raktr.global.run_in_thread if !Raktr.global.running?
58
74
  Raktr.global.delay( 1 ) { block.call( arg ) }
@@ -68,6 +84,11 @@ class Test < Parent
68
84
  end
69
85
  end
70
86
 
87
+ private
88
+
89
+ def private_method
90
+ true
91
+ end
71
92
  end
72
93
 
73
94
  def start_server( opts, do_not_start = false )
@@ -8,6 +8,13 @@ end
8
8
  describe Toq::Server do
9
9
  let(:options) { rpc_opts.merge( port: 7333 ) }
10
10
  subject { start_server( options, true ) }
11
+ let(:server) { start_server( options ) }
12
+ let(:client) { start_client( options ) }
13
+
14
+ before :all do
15
+ Thread.new { server }
16
+ client
17
+ end
11
18
 
12
19
  describe '#initialize' do
13
20
  it 'should be able to properly setup class options' do
@@ -63,6 +70,37 @@ describe Toq::Server do
63
70
  subject.logger.class.should == ::Logger
64
71
  end
65
72
 
73
+ context 'when a method is public' do
74
+ it 'can be called' do
75
+ expect( client.call('test.in_child') ).to be_truthy
76
+ end
77
+ end
78
+
79
+ context 'when a method is private' do
80
+ it 'cannot be called' do
81
+ expect { client.call('test.private_method') }.to raise_error Toq::Exceptions::UnsafeMethod
82
+ end
83
+ end
84
+
85
+ context 'when a method is inherited' do
86
+ it 'can be called' do
87
+ expect( client.call('test.in_parent') ).to be_truthy
88
+ expect( client.call('test.in_module') ).to be_truthy
89
+ end
90
+ end
91
+
92
+ context 'when a method is inherited from Kernel' do
93
+ it 'cannot be called' do
94
+ expect { client.call('test.exec', 'ls') }.to raise_error Toq::Exceptions::UnsafeMethod
95
+ end
96
+ end
97
+
98
+ context 'when a method is inherited from Object' do
99
+ it 'cannot be called' do
100
+ expect { client.call('test.included_modules') }.to raise_error Toq::Exceptions::UnsafeMethod
101
+ end
102
+ end
103
+
66
104
  describe '#alive?' do
67
105
  it 'returns true' do
68
106
  subject.should be_alive
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-18 00:00:00.000000000 Z
11
+ date: 2024-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raktr
@@ -74,7 +74,7 @@ homepage: https://github.com/qadron/toq
74
74
  licenses:
75
75
  - BSD 3-Clause
76
76
  metadata: {}
77
- post_install_message:
77
+ post_install_message:
78
78
  rdoc_options:
79
79
  - "--charset=UTF-8"
80
80
  require_paths:
@@ -90,27 +90,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 3.4.9
94
- signing_key:
93
+ rubygems_version: 3.4.22
94
+ signing_key:
95
95
  specification_version: 4
96
96
  summary: Simple RPC protocol.
97
97
  test_files:
98
- - spec/spec_helper.rb
99
- - spec/toq/request_spec.rb
100
- - spec/toq/response_spec.rb
101
- - spec/toq/client_spec.rb
102
- - spec/toq/exceptions_spec.rb
103
- - spec/toq/server_spec.rb
104
- - spec/toq/proxy_spec.rb
105
- - spec/toq/message_spec.rb
106
- - spec/servers/server.rb
107
- - spec/servers/unix_socket.rb
108
98
  - spec/servers/with_ssl_primitives.rb
109
99
  - spec/servers/basic.rb
110
- - spec/pems/cacert.pem
111
- - spec/pems/server/cert.pem
112
- - spec/pems/server/key.pem
113
- - spec/pems/client/foo-key.pem
114
- - spec/pems/client/foo-cert.pem
100
+ - spec/servers/server.rb
101
+ - spec/servers/unix_socket.rb
115
102
  - spec/pems/client/cert.pem
116
103
  - spec/pems/client/key.pem
104
+ - spec/pems/client/foo-cert.pem
105
+ - spec/pems/client/foo-key.pem
106
+ - spec/pems/server/cert.pem
107
+ - spec/pems/server/key.pem
108
+ - spec/pems/cacert.pem
109
+ - spec/spec_helper.rb
110
+ - spec/toq/proxy_spec.rb
111
+ - spec/toq/client_spec.rb
112
+ - spec/toq/response_spec.rb
113
+ - spec/toq/server_spec.rb
114
+ - spec/toq/message_spec.rb
115
+ - spec/toq/request_spec.rb
116
+ - spec/toq/exceptions_spec.rb