xrbp 0.1.0 → 0.1.1

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: a89c7310e04f3827f8252e3b4954036e6c75a703a21bb91e0a5c57e80817c495
4
- data.tar.gz: 060e83ec60961220e4f62665a4464a7b7f9da11d96895828a814e7c218025b69
3
+ metadata.gz: 92361edaa1feff8405d57bd715093cd1211d0adb2b0175f5d3f6493542526c3c
4
+ data.tar.gz: a9a9d1e8a6d1c2682f8e4c685ca0c7f73da74b37bee211af2afc39ac53600cd9
5
5
  SHA512:
6
- metadata.gz: 1cf32ec6375e44970df3612fce1eeede573d1d9501a83927de70643d207027b9e448b3a330522a2264a9b002b1e472d2334f02daadf6bf74814ab0a79c72bee5
7
- data.tar.gz: 384f666fbfc87b752ef432aa2cbebc9b4819e92f1d627698e37e396083776e7a4aa5bb0846b0749cd1d892289cac1dc9386e205854505e6738028439ddfc596a
6
+ metadata.gz: 7e327415d681a20d7e9d5abdbaf5d0e052a7562124f83a8171645fda5321b2a692be042d8230881c4a3cd13c032c661aa2c6566b87574aabf16482a0d436fc8c
7
+ data.tar.gz: b26cfa8b7a106f15385d4210e1b8972771c3400e57721f72095f1a2f84504cd6e91d0a22fb2f2a958c17e37e22652cf6041c10196f732a58788aab72eab1497f
data/lib/xrbp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module XRBP
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end # module XRBP
@@ -0,0 +1,10 @@
1
+ class Object
2
+ # XXX: allow any object to be serialzed via yaml
3
+ # by overriding 'psych' serializer callback
4
+ def force_serializable!
5
+ class << self
6
+ def encode_with(coder)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ module XRBP
2
+ # XXX need to manually set handshake,
3
+ # else will be different each time,
4
+ # messing up recordings
5
+ class TestHandshake
6
+ def version
7
+ 13
8
+ end
9
+
10
+ def to_s
11
+ "GET / HTTP/1.1\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nHost: s1.ripple.com:443\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: 0tTEDtzkyx8JPC2rIYYIzA==\r\n\r\n"
12
+ end
13
+
14
+ def finished?
15
+ true
16
+ end
17
+
18
+ def <<(r)
19
+ end
20
+ end
21
+
22
+ module WebSocket
23
+ class Client
24
+ def stub_handshake!
25
+ @handshake = XRBP::TestHandshake.new
26
+ end
27
+ end # class Client
28
+ end # module WebSocket
29
+ end # module XRBP
@@ -0,0 +1,18 @@
1
+ require 'camcorder'
2
+ require 'camcorder/rspec'
3
+
4
+ Camcorder.config.recordings_dir = 'spec/recordings'
5
+
6
+ require 'xrbp'
7
+
8
+ RSpec.configure do |config|
9
+ config.expect_with :rspec do |expectations|
10
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
11
+ end
12
+
13
+ config.mock_with :rspec do |mocks|
14
+ mocks.verify_partial_doubles = true
15
+ end
16
+
17
+ config.shared_context_metadata_behavior = :apply_to_host_groups
18
+ end
@@ -0,0 +1,120 @@
1
+ require_relative '../../helpers/test_handshake'
2
+ require_relative '../../helpers/force_serializable'
3
+
4
+ describe XRBP::WebSocket::Client do
5
+ subject { described_class.new "wss://s1.ripple.com:443" }
6
+ let(:socket) { subject.send(:socket) }
7
+ let(:pool) { subject.send(:pool) }
8
+
9
+ before(:each) do
10
+ subject.stub_handshake!
11
+ subject.force_serializable!
12
+ Camcorder.intercept_constructor XRBP::WebSocket::Socket
13
+ end
14
+
15
+ after(:each) do
16
+ Camcorder.deintercept_constructor XRBP::WebSocket::Socket
17
+ end
18
+
19
+ describe '#connect' do
20
+ after(:each) do
21
+ pool.kill
22
+ pool.wait_for_termination
23
+ end
24
+
25
+ it "connects to client" do
26
+ # XXX we are recording socket, cannot add expections to it
27
+ socket = double
28
+ subject.instance_variable_set(:@socket, socket)
29
+ expect(socket).to receive(:connect)
30
+ expect(socket).to receive(:write)
31
+ expect(socket).to receive(:read_next)
32
+
33
+ subject.connect
34
+ end
35
+
36
+ it "performs handshake" do
37
+ expect(subject).to receive(:handshake!)
38
+ subject.connect
39
+ end
40
+
41
+ it "starts reading" do
42
+ expect(subject).to receive(:start_read)
43
+ subject.connect
44
+ end
45
+
46
+ it "is open" do
47
+ subject.connect
48
+ expect(subject).to be_open
49
+ end
50
+
51
+ context "connection error" do
52
+ it "is closed"
53
+ end
54
+
55
+ context "handshake error" do
56
+ it "is closed"
57
+ end
58
+
59
+ context "read error" do
60
+ it "is closed"
61
+ end
62
+ end
63
+
64
+ it 'is not opened' do
65
+ expect(subject).to_not be_open
66
+ end
67
+
68
+ it 'is closed' do
69
+ expect(subject).to be_closed
70
+ end
71
+
72
+ it 'is completed' do
73
+ expect(subject).to be_completed
74
+ end
75
+
76
+ describe "#close" do
77
+ it "closes connection" do
78
+ subject.connect
79
+ subject.close
80
+ expect(subject).to be_closed
81
+ end
82
+
83
+ it "results in completed connection" do
84
+ subject.connect
85
+ subject.close
86
+ expect(subject).to be_completed
87
+ end
88
+ end
89
+
90
+ describe "#send_data" do
91
+ let(:socket) { double }
92
+
93
+ before(:each) do
94
+ # XXX we are recording socket, cannot add expections to it
95
+ subject.instance_variable_set(:@socket, socket)
96
+
97
+ # XXX stub data_frame as it will contain random data
98
+ expect(subject).to receive(:data_frame).with("foobar", :text).and_return "frame"
99
+
100
+ # setup connection state
101
+ expect(subject).to receive(:handshaked?).and_return true
102
+ expect(subject).to receive(:closed?).and_return false
103
+ end
104
+
105
+ it "sends data" do
106
+ expect(socket).to receive(:write_nonblock).with("frame")
107
+
108
+ subject.send_data("foobar")
109
+ end
110
+
111
+ context "error is thrown" do
112
+ it "closes the connection asynchronously" do
113
+ expect(socket).to receive(:write_nonblock).and_raise Errno::EPIPE
114
+ expect(subject).to receive(:async_close).with(Errno::EPIPE)
115
+
116
+ subject.send_data("foobar")
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,13 @@
1
+ describe XRBP::WebSocket::Command do
2
+ context "command specified" do
3
+ subject { described_class.new(command: 'test') }
4
+
5
+ it 'returns command' do
6
+ expect(subject.requesting).to eq 'test'
7
+ end
8
+
9
+ it 'is requesting' do
10
+ expect(subject).to be_requesting('test')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,108 @@
1
+ describe XRBP::WebSocket::Connection do
2
+ subject { XRBP::WebSocket::Connection.new 'wss://test.com:443' }
3
+ let(:client){ subject.client }
4
+
5
+ it 'is not initialized' do
6
+ expect(subject).to_not be_initialized
7
+ end
8
+
9
+ it 'is not open' do
10
+ expect(subject).to_not be_open
11
+ end
12
+
13
+ it 'is closed' do
14
+ expect(subject).to be_closed
15
+ end
16
+
17
+ it 'is completed' do
18
+ expect(subject).to be_completed
19
+ end
20
+
21
+ context "client exists" do
22
+ before(:each) do
23
+ subject.client
24
+ end
25
+
26
+ it "is initialized" do
27
+ expect(subject).to be_initialized
28
+ end
29
+ end
30
+
31
+ context "client is open" do
32
+ before(:each) do
33
+ expect(client).to receive(:open?).and_return true
34
+ end
35
+
36
+ it "is open" do
37
+ expect(subject).to be_open
38
+ end
39
+
40
+ it "is not closed" do
41
+ expect(subject).to_not be_closed
42
+ end
43
+ end
44
+
45
+ context "client is not completed" do
46
+ before(:each) do
47
+ expect(client).to receive(:completed?).and_return false
48
+ end
49
+
50
+ it "is not completed" do
51
+ expect(subject).to_not be_completed
52
+ end
53
+ end
54
+
55
+ describe "#connect" do
56
+ it "connects to client" do
57
+ expect(client).to receive(:connect)
58
+ subject.connect
59
+ end
60
+ end
61
+
62
+ describe "#close!" do
63
+ it "closes client" do
64
+ expect(client).to receive(:open?).and_return true
65
+ expect(client).to receive(:close)
66
+ subject.close!
67
+ end
68
+ end
69
+
70
+ describe "#close!" do
71
+ it "async closes client" do
72
+ expect(client).to receive(:open?).and_return true
73
+ expect(client).to receive(:async_close)
74
+ subject.async_close!
75
+ end
76
+ end
77
+
78
+ describe "#send_data" do
79
+ it "sends data via client" do
80
+ expect(client).to receive(:send_data).with("foo")
81
+ subject.send_data("foo")
82
+ end
83
+ end
84
+
85
+ describe "#add_work" do
86
+ it "adds work to client pool" do
87
+ expect(client).to receive(:add_work)
88
+ subject.add_work do
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "#next_connection" do
94
+ context "no parent" do
95
+ it "returns nil" do
96
+ expect(subject.next_connection(nil)).to be_nil
97
+ end
98
+ end
99
+
100
+ it "returns parent's next connection" do
101
+ parent = double
102
+ expect(parent).to receive(:next_connection).with(:foo).and_return :bar
103
+
104
+ subject.parent = parent
105
+ expect(subject.next_connection(:foo)).to eq(:bar)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe XRBP::WebSocket::Message do
4
+ subject { described_class.new 'Test message' }
5
+ let(:connection) { XRBP::WebSocket::Connection.new "*" }
6
+
7
+ it 'returns message text' do
8
+ expect(subject.to_s).to eq 'Test message'
9
+ end
10
+
11
+ it 'waits for signal' do
12
+ expect(subject.signal).to be(subject)
13
+ end
14
+
15
+ it 'waits for connection close' do
16
+ expect(connection).to receive(:closed?).and_return true
17
+ subject.connection = connection
18
+ expect(subject.wait).to be_nil
19
+ end
20
+
21
+ it 'returns proc which waites for signal' do
22
+ expect(subject.bl.call).to be(subject)
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ #describe XRBP::WebSocket::Plugins::CommandDispatcher do
2
+ # let(:connection) {
3
+ # XRBP::WebSocket::Connection.new "wss://s1.ripple.com:443" do |c|
4
+ # c.add_plugin :command_dispatcher
5
+ # end
6
+ # }
7
+ #
8
+ # before(:each) do
9
+ # #connection.client.stub_handshake!
10
+ # connection.client.force_serializable!
11
+ # Camcorder.intercept_constructor XRBP::WebSocket::Socket
12
+ #
13
+ # # XXX fix random
14
+ # allow(SecureRandom).to receive(:random_bytes).with(4).and_return('1234')
15
+ # end
16
+ #
17
+ # after(:each) do
18
+ # Camcorder.deintercept_constructor XRBP::WebSocket::Socket
19
+ # end
20
+ #
21
+ # it "sends command and returns response" do
22
+ # connection.connect
23
+ # puts connection.cmd XRBP::WebSocket::Cmds::ServerInfo.new
24
+ # end
25
+ #end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrbp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dev Null Productions
@@ -206,7 +206,15 @@ files:
206
206
  - lib/xrbp/websocket/plugins/message_dispatcher.rb
207
207
  - lib/xrbp/websocket/plugins/result_parser.rb
208
208
  - lib/xrbp/websocket/socket.rb
209
- homepage: https://devnull.network
209
+ - spec/helpers/force_serializable.rb
210
+ - spec/helpers/test_handshake.rb
211
+ - spec/spec_helper.rb
212
+ - spec/xrbp/websocket/client_spec.rb
213
+ - spec/xrbp/websocket/command_spec.rb
214
+ - spec/xrbp/websocket/connection_spec.rb
215
+ - spec/xrbp/websocket/message_spec.rb
216
+ - spec/xrbp/websocket/plugins/cmd_dispatcher_spec.rb
217
+ homepage: https://github.com/DevNullProd/XRBP
210
218
  licenses:
211
219
  - MIT
212
220
  metadata: {}