toq 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1 -0
- data/LICENSE.md +29 -0
- data/README.md +68 -0
- data/Rakefile +53 -0
- data/lib/toq/client/handler.rb +165 -0
- data/lib/toq/client.rb +249 -0
- data/lib/toq/exceptions.rb +152 -0
- data/lib/toq/message.rb +63 -0
- data/lib/toq/protocol.rb +101 -0
- data/lib/toq/proxy.rb +84 -0
- data/lib/toq/request.rb +59 -0
- data/lib/toq/response.rb +63 -0
- data/lib/toq/server/handler.rb +144 -0
- data/lib/toq/server.rb +276 -0
- data/lib/toq/version.rb +13 -0
- data/lib/toq.rb +13 -0
- data/spec/pems/cacert.pem +37 -0
- data/spec/pems/client/cert.pem +37 -0
- data/spec/pems/client/foo-cert.pem +39 -0
- data/spec/pems/client/foo-key.pem +51 -0
- data/spec/pems/client/key.pem +51 -0
- data/spec/pems/server/cert.pem +37 -0
- data/spec/pems/server/key.pem +51 -0
- data/spec/servers/basic.rb +3 -0
- data/spec/servers/server.rb +83 -0
- data/spec/servers/unix_socket.rb +8 -0
- data/spec/servers/with_ssl_primitives.rb +11 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/toq/client_spec.rb +397 -0
- data/spec/toq/exceptions_spec.rb +77 -0
- data/spec/toq/message_spec.rb +47 -0
- data/spec/toq/proxy_spec.rb +99 -0
- data/spec/toq/request_spec.rb +53 -0
- data/spec/toq/response_spec.rb +49 -0
- data/spec/toq/server_spec.rb +129 -0
- metadata +116 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Translator < Toq::Proxy
|
4
|
+
|
5
|
+
translate :foo do |response|
|
6
|
+
response.map(&:to_s)
|
7
|
+
end
|
8
|
+
|
9
|
+
translate :delay do |response, arguments|
|
10
|
+
[arguments, response.map(&:to_s)]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Toq::Proxy do
|
16
|
+
|
17
|
+
def wait
|
18
|
+
Raktr.global.wait rescue Raktr::Error::NotRunning
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
if Raktr.global.running?
|
23
|
+
Raktr.stop
|
24
|
+
end
|
25
|
+
|
26
|
+
Raktr.global.run_in_thread
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:translated_arguments) do
|
30
|
+
arguments.map(&:to_s)
|
31
|
+
end
|
32
|
+
let(:arguments) do
|
33
|
+
[
|
34
|
+
'one',
|
35
|
+
2,
|
36
|
+
{ three: 3 },
|
37
|
+
[ 4 ]
|
38
|
+
]
|
39
|
+
end
|
40
|
+
let(:reactor) { Raktr.global }
|
41
|
+
let(:client) { start_client( rpc_opts ) }
|
42
|
+
let(:handler) { 'test' }
|
43
|
+
let(:translator) { Translator.new( client, handler ) }
|
44
|
+
subject do
|
45
|
+
Toq::Proxy.new( client, handler )
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'forwards synchronous calls' do
|
49
|
+
subject.foo( arguments ).should == arguments
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'forwards synchronous calls' do
|
53
|
+
response = nil
|
54
|
+
subject.foo( arguments ) do |res|
|
55
|
+
response = res
|
56
|
+
Raktr.stop
|
57
|
+
end
|
58
|
+
wait
|
59
|
+
|
60
|
+
response.should == arguments
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '.translate' do
|
64
|
+
context 'when a synchronous call' do
|
65
|
+
context 'does not return an exception' do
|
66
|
+
it 'returns the translated result' do
|
67
|
+
translator.foo( arguments ).should == translated_arguments
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'returns an exception' do
|
72
|
+
it 'returns the exception'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when an asynchronous call' do
|
77
|
+
context 'does not result in an exception' do
|
78
|
+
it 'calls the block with the translated result' do
|
79
|
+
response = nil
|
80
|
+
translator.foo( arguments ) do |res|
|
81
|
+
response = res
|
82
|
+
Raktr.stop
|
83
|
+
end
|
84
|
+
wait
|
85
|
+
|
86
|
+
response.should == translated_arguments
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'results in an exception' do
|
91
|
+
it 'calls the block with the exception'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'passes the method arguments to the translator' do
|
96
|
+
translator.delay( arguments ).should == [arguments, translated_arguments]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Toq::Request do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#message' do
|
7
|
+
it 'should be an accessor' do
|
8
|
+
subject.message = 'test'
|
9
|
+
subject.message.should == 'test'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#args' do
|
14
|
+
it 'should be an accessor' do
|
15
|
+
subject.args = %w(test)
|
16
|
+
subject.args.should == %w(test)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#token' do
|
21
|
+
it 'should be an accessor' do
|
22
|
+
subject.token = 'blah'
|
23
|
+
subject.token.should == 'blah'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#callback' do
|
28
|
+
it 'should be an accessor' do
|
29
|
+
called = false
|
30
|
+
subject.callback = proc { called = true }
|
31
|
+
subject.callback.call
|
32
|
+
called.should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#prepare_for_tx' do
|
37
|
+
it 'should convert the request to a hash ready for transmission' do
|
38
|
+
subject.prepare_for_tx.should be_empty
|
39
|
+
|
40
|
+
described_class.new(
|
41
|
+
message: 'obj.method',
|
42
|
+
args: %w(test),
|
43
|
+
token: 'mytoken',
|
44
|
+
callback: proc{}
|
45
|
+
).prepare_for_tx.should =={
|
46
|
+
'args' => %w(test),
|
47
|
+
'message' => 'obj.method',
|
48
|
+
'token' => 'mytoken'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Toq::Response do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#obj' do
|
7
|
+
it 'should be an accessor' do
|
8
|
+
subject.obj = 'test'
|
9
|
+
subject.obj.should == 'test'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#exception' do
|
14
|
+
it 'should be an accessor' do
|
15
|
+
subject.exception = 'test'
|
16
|
+
subject.exception.should == 'test'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#exception?' do
|
21
|
+
context 'when #exception is not set' do
|
22
|
+
it 'returns false' do
|
23
|
+
subject.exception?.should be_false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when #exception is set' do
|
28
|
+
it 'returns true' do
|
29
|
+
subject.exception = 'stuff'
|
30
|
+
subject.exception?.should be_true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#async?' do
|
36
|
+
context 'by default' do
|
37
|
+
it 'should return false' do
|
38
|
+
subject.async?.should be_false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'after #async!' do
|
43
|
+
it 'should return false' do
|
44
|
+
subject.async!
|
45
|
+
subject.async?.should be_true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Toq::Server
|
4
|
+
public :async?, :async_check, :object_exist?, :public_method?
|
5
|
+
attr_accessor :proxy
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Toq::Server do
|
9
|
+
let(:options) { rpc_opts.merge( port: 7333 ) }
|
10
|
+
subject { start_server( options, true ) }
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
it 'should be able to properly setup class options' do
|
14
|
+
subject.opts.should == options
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when passed no connection information' do
|
18
|
+
it 'raises ArgumentError' do
|
19
|
+
begin
|
20
|
+
described_class.new({})
|
21
|
+
rescue => e
|
22
|
+
e.should be_kind_of ArgumentError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when passed a host but not a port' do
|
28
|
+
it 'raises ArgumentError' do
|
29
|
+
begin
|
30
|
+
described_class.new( host: 'test' )
|
31
|
+
rescue => e
|
32
|
+
e.should be_kind_of ArgumentError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when passed a port but not a host' do
|
38
|
+
it 'raises ArgumentError' do
|
39
|
+
begin
|
40
|
+
described_class.new( port: 9999 )
|
41
|
+
rescue => e
|
42
|
+
e.should be_kind_of ArgumentError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when passed an invalid port' do
|
48
|
+
it 'raises ArgumentError' do
|
49
|
+
begin
|
50
|
+
described_class.new( host: 'tt', port: 'blah' )
|
51
|
+
rescue => e
|
52
|
+
e.should be_kind_of ArgumentError
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'retains the supplied token' do
|
59
|
+
subject.token.should == options[:token]
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'has a Logger' do
|
63
|
+
subject.logger.class.should == ::Logger
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#alive?' do
|
67
|
+
it 'returns true' do
|
68
|
+
subject.should be_alive
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#async?' do
|
73
|
+
context 'when a method is async' do
|
74
|
+
it 'returns true' do
|
75
|
+
subject.async?( 'test', 'delay' ).should be_true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when a method is sync' do
|
80
|
+
it 'returns false' do
|
81
|
+
subject.async?( 'test', 'foo' ).should be_false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#async_check' do
|
87
|
+
context 'when a method is async' do
|
88
|
+
it 'returns true' do
|
89
|
+
subject.async_check( Test.new.method( :delay ) ).should be_true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when a method is sync' do
|
94
|
+
it 'returns false' do
|
95
|
+
subject.async_check( Test.new.method( :foo ) ).should be_false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#object_exist?' do
|
101
|
+
context 'when an object exists' do
|
102
|
+
it 'returns true' do
|
103
|
+
subject.object_exist?( 'test' ).should be_true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when an object does not exist' do
|
108
|
+
it 'returns false' do
|
109
|
+
subject.object_exist?( 'foo' ).should be_false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#public_method?' do
|
115
|
+
context 'when a method is public' do
|
116
|
+
it 'returns true' do
|
117
|
+
subject.public_method?( 'test', 'foo' ).should be_true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when a method is non-existent or not public' do
|
122
|
+
it 'returns false' do
|
123
|
+
subject.public_method?( 'test', 'bar' ).should be_false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: toq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tasos Laskos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: raktr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.1
|
27
|
+
description: |2
|
28
|
+
Toq is a simple and lightweight Remote Procedure Call protocol
|
29
|
+
used to provide the basis for Arachni's distributed infrastructure.
|
30
|
+
email: tasos.laskos@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.md
|
35
|
+
- LICENSE.md
|
36
|
+
- CHANGELOG.md
|
37
|
+
files:
|
38
|
+
- CHANGELOG.md
|
39
|
+
- LICENSE.md
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/toq.rb
|
43
|
+
- lib/toq/client.rb
|
44
|
+
- lib/toq/client/handler.rb
|
45
|
+
- lib/toq/exceptions.rb
|
46
|
+
- lib/toq/message.rb
|
47
|
+
- lib/toq/protocol.rb
|
48
|
+
- lib/toq/proxy.rb
|
49
|
+
- lib/toq/request.rb
|
50
|
+
- lib/toq/response.rb
|
51
|
+
- lib/toq/server.rb
|
52
|
+
- lib/toq/server/handler.rb
|
53
|
+
- lib/toq/version.rb
|
54
|
+
- spec/pems/cacert.pem
|
55
|
+
- spec/pems/client/cert.pem
|
56
|
+
- spec/pems/client/foo-cert.pem
|
57
|
+
- spec/pems/client/foo-key.pem
|
58
|
+
- spec/pems/client/key.pem
|
59
|
+
- spec/pems/server/cert.pem
|
60
|
+
- spec/pems/server/key.pem
|
61
|
+
- spec/servers/basic.rb
|
62
|
+
- spec/servers/server.rb
|
63
|
+
- spec/servers/unix_socket.rb
|
64
|
+
- spec/servers/with_ssl_primitives.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
- spec/toq/client_spec.rb
|
67
|
+
- spec/toq/exceptions_spec.rb
|
68
|
+
- spec/toq/message_spec.rb
|
69
|
+
- spec/toq/proxy_spec.rb
|
70
|
+
- spec/toq/request_spec.rb
|
71
|
+
- spec/toq/response_spec.rb
|
72
|
+
- spec/toq/server_spec.rb
|
73
|
+
homepage: https://github.com/qadron/toq
|
74
|
+
licenses:
|
75
|
+
- BSD 3-Clause
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- "--charset=UTF-8"
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.1.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Simple RPC protocol.
|
97
|
+
test_files:
|
98
|
+
- spec/pems/server/cert.pem
|
99
|
+
- spec/pems/server/key.pem
|
100
|
+
- spec/pems/cacert.pem
|
101
|
+
- spec/pems/client/foo-key.pem
|
102
|
+
- spec/pems/client/cert.pem
|
103
|
+
- spec/pems/client/foo-cert.pem
|
104
|
+
- spec/pems/client/key.pem
|
105
|
+
- spec/servers/with_ssl_primitives.rb
|
106
|
+
- spec/servers/unix_socket.rb
|
107
|
+
- spec/servers/server.rb
|
108
|
+
- spec/servers/basic.rb
|
109
|
+
- spec/toq/client_spec.rb
|
110
|
+
- spec/toq/server_spec.rb
|
111
|
+
- spec/toq/request_spec.rb
|
112
|
+
- spec/toq/message_spec.rb
|
113
|
+
- spec/toq/response_spec.rb
|
114
|
+
- spec/toq/exceptions_spec.rb
|
115
|
+
- spec/toq/proxy_spec.rb
|
116
|
+
- spec/spec_helper.rb
|