mqtt 0.3.1 → 0.4.0
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.
- checksums.yaml +15 -0
- data/NEWS.md +13 -0
- data/README.md +99 -49
- data/lib/mqtt.rb +14 -1
- data/lib/mqtt/client.rb +93 -53
- data/lib/mqtt/packet.rb +6 -6
- data/lib/mqtt/patches/string_encoding.rb +4 -0
- data/lib/mqtt/sn/packet.rb +763 -0
- data/lib/mqtt/version.rb +1 -1
- data/spec/mqtt_client_spec.rb +147 -51
- data/spec/mqtt_packet_spec.rb +67 -68
- data/spec/mqtt_sn_packet_spec.rb +1721 -0
- data/spec/zz_client_integration_spec.rb +22 -1
- metadata +22 -31
data/lib/mqtt/version.rb
CHANGED
data/spec/mqtt_client_spec.rb
CHANGED
@@ -168,6 +168,14 @@ describe MQTT::Client do
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
+
describe "setting a client certificate directly" do
|
172
|
+
it "should add a certificate to the SSL context" do
|
173
|
+
expect(client.ssl_context.cert).to be_nil
|
174
|
+
client.cert = File.read(fixture_path('client.pem'))
|
175
|
+
expect(client.ssl_context.cert).to be_a(OpenSSL::X509::Certificate)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
171
179
|
describe "setting a client private key file path" do
|
172
180
|
it "should add a certificate to the SSL context" do
|
173
181
|
expect(client.ssl_context.key).to be_nil
|
@@ -176,6 +184,34 @@ describe MQTT::Client do
|
|
176
184
|
end
|
177
185
|
end
|
178
186
|
|
187
|
+
describe "setting a client private key directly" do
|
188
|
+
it "should add a certificate to the SSL context" do
|
189
|
+
expect(client.ssl_context.key).to be_nil
|
190
|
+
client.key = File.read(fixture_path('client.key'))
|
191
|
+
expect(client.ssl_context.key).to be_a(OpenSSL::PKey::RSA)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "setting an encrypted client private key, w/the correct passphrase" do
|
196
|
+
let(:key_pass) { 'mqtt' }
|
197
|
+
|
198
|
+
it "should add the decrypted certificate to the SSL context" do
|
199
|
+
expect(client.ssl_context.key).to be_nil
|
200
|
+
client.key_file = [fixture_path('client.pass.key'), key_pass]
|
201
|
+
expect(client.ssl_context.key).to be_a(OpenSSL::PKey::RSA)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe "setting an encrypted client private key, w/an incorrect passphrase" do
|
206
|
+
let(:key_pass) { 'ttqm' }
|
207
|
+
|
208
|
+
it "should raise an OpenSSL::PKey::RSAError exception" do
|
209
|
+
expect(client.ssl_context.key).to be_nil
|
210
|
+
expect { client.key_file = [fixture_path('client.pass.key'), key_pass] }.to(
|
211
|
+
raise_error(OpenSSL::PKey::RSAError, /Neither PUB key nor PRIV key/))
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
179
215
|
describe "setting a Certificate Authority file path" do
|
180
216
|
it "should add a CA file path to the SSL context" do
|
181
217
|
expect(client.ssl_context.ca_file).to be_nil
|
@@ -253,7 +289,7 @@ describe MQTT::Client do
|
|
253
289
|
client.connect('myclient')
|
254
290
|
end
|
255
291
|
|
256
|
-
it "should
|
292
|
+
it "should raise an exception if no host is configured" do
|
257
293
|
expect {
|
258
294
|
client = MQTT::Client.new
|
259
295
|
client.connect
|
@@ -262,9 +298,19 @@ describe MQTT::Client do
|
|
262
298
|
)
|
263
299
|
end
|
264
300
|
|
265
|
-
|
266
|
-
|
267
|
-
|
301
|
+
context "if a block is given" do
|
302
|
+
it "should disconnect after connecting" do
|
303
|
+
expect(client).to receive(:disconnect).once
|
304
|
+
client.connect('myclient') { nil }
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should disconnect even if the block raises an exception" do
|
308
|
+
expect(client).to receive(:disconnect).once
|
309
|
+
begin
|
310
|
+
client.connect('myclient') { raise StandardError }
|
311
|
+
rescue StandardError
|
312
|
+
end
|
313
|
+
end
|
268
314
|
end
|
269
315
|
|
270
316
|
it "should not disconnect after connecting, if no block is given" do
|
@@ -287,7 +333,7 @@ describe MQTT::Client do
|
|
287
333
|
end
|
288
334
|
|
289
335
|
context "no client id is given" do
|
290
|
-
it "should
|
336
|
+
it "should raise an exception if the clean session flag is false" do
|
291
337
|
expect {
|
292
338
|
client.client_id = nil
|
293
339
|
client.clean_session = false
|
@@ -376,7 +422,7 @@ describe MQTT::Client do
|
|
376
422
|
expect(client.will_retain).to be_falsey
|
377
423
|
end
|
378
424
|
|
379
|
-
it "should have set the Will's retain
|
425
|
+
it "should have set the Will's retain QoS value to 1" do
|
380
426
|
expect(client.will_qos).to eq(1)
|
381
427
|
end
|
382
428
|
|
@@ -423,37 +469,37 @@ describe MQTT::Client do
|
|
423
469
|
allow(IO).to receive(:select).and_return([[socket], [], []])
|
424
470
|
end
|
425
471
|
|
426
|
-
it "should not
|
472
|
+
it "should not raise an exception for a successful CONNACK packet" do
|
427
473
|
socket.write("\x20\x02\x00\x00")
|
428
474
|
socket.rewind
|
429
475
|
expect { client.send(:receive_connack) }.not_to raise_error
|
430
476
|
end
|
431
477
|
|
432
|
-
it "should
|
478
|
+
it "should raise an exception if the packet type isn't CONNACK" do
|
433
479
|
socket.write("\xD0\x00")
|
434
480
|
socket.rewind
|
435
481
|
expect { client.send(:receive_connack) }.to raise_error(MQTT::ProtocolException)
|
436
482
|
end
|
437
483
|
|
438
|
-
it "should
|
484
|
+
it "should raise an exception if the CONNACK packet return code is 'unacceptable protocol version'" do
|
439
485
|
socket.write("\x20\x02\x00\x01")
|
440
486
|
socket.rewind
|
441
487
|
expect { client.send(:receive_connack) }.to raise_error(MQTT::ProtocolException, /unacceptable protocol version/i)
|
442
488
|
end
|
443
489
|
|
444
|
-
it "should
|
490
|
+
it "should raise an exception if the CONNACK packet return code is 'client identifier rejected'" do
|
445
491
|
socket.write("\x20\x02\x00\x02")
|
446
492
|
socket.rewind
|
447
493
|
expect { client.send(:receive_connack) }.to raise_error(MQTT::ProtocolException, /client identifier rejected/i)
|
448
494
|
end
|
449
495
|
|
450
|
-
it "should
|
496
|
+
it "should raise an exception if the CONNACK packet return code is 'server unavailable'" do
|
451
497
|
socket.write("\x20\x02\x00\x03")
|
452
498
|
socket.rewind
|
453
499
|
expect { client.send(:receive_connack) }.to raise_error(MQTT::ProtocolException, /server unavailable/i)
|
454
500
|
end
|
455
501
|
|
456
|
-
it "should
|
502
|
+
it "should raise an exception if the CONNACK packet return code is an unknown" do
|
457
503
|
socket.write("\x20\x02\x00\xAA")
|
458
504
|
socket.rewind
|
459
505
|
expect { client.send(:receive_connack) }.to raise_error(MQTT::ProtocolException, /connection refused/i)
|
@@ -491,23 +537,6 @@ describe MQTT::Client do
|
|
491
537
|
end
|
492
538
|
end
|
493
539
|
|
494
|
-
describe "when calling the 'ping' method" do
|
495
|
-
before(:each) do
|
496
|
-
client.instance_variable_set('@socket', socket)
|
497
|
-
end
|
498
|
-
|
499
|
-
it "should write a valid PINGREQ packet to the socket" do
|
500
|
-
client.ping
|
501
|
-
expect(socket.string).to eq("\xC0\x00")
|
502
|
-
end
|
503
|
-
|
504
|
-
it "should update the time a ping was last sent" do
|
505
|
-
client.instance_variable_set('@last_pingreq', 0)
|
506
|
-
client.ping
|
507
|
-
expect(client.instance_variable_get('@last_pingreq')).not_to eq(0)
|
508
|
-
end
|
509
|
-
end
|
510
|
-
|
511
540
|
describe "when calling the 'publish' method" do
|
512
541
|
before(:each) do
|
513
542
|
client.instance_variable_set('@socket', socket)
|
@@ -523,12 +552,14 @@ describe MQTT::Client do
|
|
523
552
|
expect(socket.string).to eq("\x31\x0e\x00\x05topicpayload")
|
524
553
|
end
|
525
554
|
|
526
|
-
it "should write a valid PUBLISH packet to the socket with the
|
555
|
+
it "should write a valid PUBLISH packet to the socket with the QoS set to 1" do
|
556
|
+
inject_puback(1)
|
527
557
|
client.publish('topic','payload', false, 1)
|
528
558
|
expect(socket.string).to eq("\x32\x10\x00\x05topic\x00\x01payload")
|
529
559
|
end
|
530
560
|
|
531
|
-
it "should write a valid PUBLISH packet to the socket with the
|
561
|
+
it "should write a valid PUBLISH packet to the socket with the QoS set to 2" do
|
562
|
+
inject_puback(1)
|
532
563
|
client.publish('topic','payload', false, 2)
|
533
564
|
expect(socket.string).to eq("\x34\x10\x00\x05topic\x00\x01payload")
|
534
565
|
end
|
@@ -538,7 +569,12 @@ describe MQTT::Client do
|
|
538
569
|
expect(socket.string).to eq("\x30\x06\x00\x04test")
|
539
570
|
end
|
540
571
|
|
541
|
-
it "should
|
572
|
+
it "should write a valid PUBLISH packet with frozen payload" do
|
573
|
+
client.publish('topic', 'payload'.freeze, false, 0)
|
574
|
+
expect(socket.string).to eq("\x30\x0e\x00\x05topicpayload")
|
575
|
+
end
|
576
|
+
|
577
|
+
it "should raise an ArgumentError exception, if the topic is nil" do
|
542
578
|
expect {
|
543
579
|
client.publish(nil)
|
544
580
|
}.to raise_error(
|
@@ -547,7 +583,7 @@ describe MQTT::Client do
|
|
547
583
|
)
|
548
584
|
end
|
549
585
|
|
550
|
-
it "should
|
586
|
+
it "should raise an ArgumentError exception, if the topic is empty" do
|
551
587
|
expect {
|
552
588
|
client.publish("")
|
553
589
|
}.to raise_error(
|
@@ -555,6 +591,16 @@ describe MQTT::Client do
|
|
555
591
|
'Topic name cannot be empty'
|
556
592
|
)
|
557
593
|
end
|
594
|
+
|
595
|
+
it "correctly assigns consecutive ids to packets with QoS 1" do
|
596
|
+
inject_puback(1)
|
597
|
+
inject_puback(2)
|
598
|
+
|
599
|
+
expect(client).to receive(:send_packet) { |packet| expect(packet.id).to eq(1) }
|
600
|
+
client.publish "topic", "message", false, 1
|
601
|
+
expect(client).to receive(:send_packet) { |packet| expect(packet.id).to eq(2) }
|
602
|
+
client.publish "topic", "message", false, 1
|
603
|
+
end
|
558
604
|
end
|
559
605
|
|
560
606
|
describe "when calling the 'subscribe' method" do
|
@@ -616,14 +662,14 @@ describe MQTT::Client do
|
|
616
662
|
client.instance_variable_set('@socket', socket)
|
617
663
|
end
|
618
664
|
|
619
|
-
it "should
|
665
|
+
it "should successfully receive a valid PUBLISH packet with a QoS 0" do
|
620
666
|
inject_packet(:topic => 'topic0', :payload => 'payload0', :qos => 0)
|
621
667
|
topic,payload = client.get
|
622
668
|
expect(topic).to eq('topic0')
|
623
669
|
expect(payload).to eq('payload0')
|
624
670
|
end
|
625
671
|
|
626
|
-
it "should
|
672
|
+
it "should successfully receive a valid PUBLISH packet with a QoS 1" do
|
627
673
|
inject_packet(:topic => 'topic1', :payload => 'payload1', :qos => 1)
|
628
674
|
topic,payload = client.get
|
629
675
|
expect(topic).to eq('topic1')
|
@@ -631,8 +677,20 @@ describe MQTT::Client do
|
|
631
677
|
expect(client.queue_empty?).to be_truthy
|
632
678
|
end
|
633
679
|
|
680
|
+
it "acks calling #get_packet and qos=1" do
|
681
|
+
inject_packet(:topic => 'topic1', :payload => 'payload1', :qos => 1)
|
682
|
+
expect(client).to receive(:send_packet).with(an_instance_of(MQTT::Packet::Puback))
|
683
|
+
client.get_packet
|
684
|
+
end
|
685
|
+
|
686
|
+
it "acks calling #get and qos=1" do
|
687
|
+
inject_packet(:topic => 'topic1', :payload => 'payload1', :qos => 1)
|
688
|
+
expect(client).to receive(:send_packet).with(an_instance_of(MQTT::Packet::Puback))
|
689
|
+
client.get
|
690
|
+
end
|
691
|
+
|
634
692
|
context "with a block" do
|
635
|
-
it "should
|
693
|
+
it "should successfully receive more than 1 message" do
|
636
694
|
inject_packet(:topic => 'topic0', :payload => 'payload0')
|
637
695
|
inject_packet(:topic => 'topic1', :payload => 'payload1')
|
638
696
|
payloads = []
|
@@ -643,6 +701,17 @@ describe MQTT::Client do
|
|
643
701
|
expect(payloads.size).to eq(2)
|
644
702
|
expect(payloads).to eq(['payload0', 'payload1'])
|
645
703
|
end
|
704
|
+
|
705
|
+
it "acks when qos > 1 after running the block" do
|
706
|
+
inject_packet(:topic => 'topic1', :payload => 'payload1', :qos => 1)
|
707
|
+
inject_packet(:topic => 'topic2', :payload => 'payload1')
|
708
|
+
expect(client).to receive(:send_packet).with(an_instance_of(MQTT::Packet::Puback))
|
709
|
+
payloads = []
|
710
|
+
client.get do |topic,payload|
|
711
|
+
payloads << payload
|
712
|
+
break if payloads.size > 1
|
713
|
+
end
|
714
|
+
end
|
646
715
|
end
|
647
716
|
end
|
648
717
|
|
@@ -651,7 +720,7 @@ describe MQTT::Client do
|
|
651
720
|
client.instance_variable_set('@socket', socket)
|
652
721
|
end
|
653
722
|
|
654
|
-
it "should
|
723
|
+
it "should successfully receive a valid PUBLISH packet with a QoS 0" do
|
655
724
|
inject_packet(:topic => 'topic0', :payload => 'payload0', :qos => 0)
|
656
725
|
packet = client.get_packet
|
657
726
|
expect(packet.class).to eq(MQTT::Packet::Publish)
|
@@ -660,7 +729,7 @@ describe MQTT::Client do
|
|
660
729
|
expect(packet.payload).to eq('payload0')
|
661
730
|
end
|
662
731
|
|
663
|
-
it "should
|
732
|
+
it "should successfully receive a valid PUBLISH packet with a QoS 1" do
|
664
733
|
inject_packet(:topic => 'topic1', :payload => 'payload1', :qos => 1)
|
665
734
|
packet = client.get_packet
|
666
735
|
expect(packet.class).to eq(MQTT::Packet::Publish)
|
@@ -671,7 +740,7 @@ describe MQTT::Client do
|
|
671
740
|
end
|
672
741
|
|
673
742
|
context "with a block" do
|
674
|
-
it "should
|
743
|
+
it "should successfully receive more than 1 packet" do
|
675
744
|
inject_packet(:topic => 'topic0', :payload => 'payload0')
|
676
745
|
inject_packet(:topic => 'topic1', :payload => 'payload1')
|
677
746
|
packets = []
|
@@ -729,10 +798,15 @@ describe MQTT::Client do
|
|
729
798
|
expect(@read_queue.size).to eq(0)
|
730
799
|
end
|
731
800
|
|
732
|
-
it "should
|
733
|
-
expect(
|
734
|
-
|
735
|
-
|
801
|
+
it "should close the socket if there is an exception" do
|
802
|
+
expect(socket).to receive(:close).once
|
803
|
+
allow(MQTT::Packet).to receive(:read).and_raise(MQTT::Exception)
|
804
|
+
client.send(:receive_packet)
|
805
|
+
end
|
806
|
+
|
807
|
+
it "should pass exceptions up to parent thread" do
|
808
|
+
expect(@parent_thread).to receive(:raise).once
|
809
|
+
allow(MQTT::Packet).to receive(:read).and_raise(MQTT::Exception)
|
736
810
|
client.send(:receive_packet)
|
737
811
|
end
|
738
812
|
|
@@ -742,17 +816,34 @@ describe MQTT::Client do
|
|
742
816
|
client.send :receive_packet
|
743
817
|
expect(client.last_ping_response).to be_within(1).of Time.now
|
744
818
|
end
|
819
|
+
end
|
820
|
+
|
821
|
+
describe "when calling the 'keep_alive!' method" do
|
822
|
+
before(:each) do
|
823
|
+
client.instance_variable_set('@socket', socket)
|
824
|
+
end
|
745
825
|
|
746
|
-
it "should
|
747
|
-
|
748
|
-
|
749
|
-
|
826
|
+
it "should send a ping packet if one is due" do
|
827
|
+
client.instance_variable_set('@last_ping_request', Time.at(0))
|
828
|
+
client.send('keep_alive!')
|
829
|
+
expect(socket.string).to eq("\xC0\x00")
|
750
830
|
end
|
751
831
|
|
752
|
-
it "should
|
753
|
-
|
754
|
-
|
755
|
-
client.
|
832
|
+
it "should update the time a ping was last sent" do
|
833
|
+
client.instance_variable_set('@last_ping_request', Time.at(0))
|
834
|
+
client.send('keep_alive!')
|
835
|
+
expect(client.instance_variable_get('@last_ping_request')).not_to eq(0)
|
836
|
+
end
|
837
|
+
|
838
|
+
it "should raise an exception if no ping response has been received" do
|
839
|
+
client.instance_variable_set('@last_ping_request', Time.now)
|
840
|
+
client.instance_variable_set('@last_ping_response', Time.at(0))
|
841
|
+
expect {
|
842
|
+
client.send('keep_alive!')
|
843
|
+
}.to raise_error(
|
844
|
+
MQTT::ProtocolException,
|
845
|
+
/No Ping Response received for \d+ seconds/
|
846
|
+
)
|
756
847
|
end
|
757
848
|
end
|
758
849
|
|
@@ -797,4 +888,9 @@ describe MQTT::Client do
|
|
797
888
|
client.instance_variable_get('@read_queue').push(packet)
|
798
889
|
end
|
799
890
|
|
891
|
+
def inject_puback(packet_id)
|
892
|
+
packet = MQTT::Packet::Puback.new(:id => packet_id)
|
893
|
+
client.instance_variable_get('@pubacks')[packet_id] = packet
|
894
|
+
end
|
895
|
+
|
800
896
|
end
|
data/spec/mqtt_packet_spec.rb
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
$:.unshift(File.dirname(__FILE__))
|
5
5
|
|
6
6
|
require 'spec_helper'
|
7
|
-
require 'mqtt'
|
8
7
|
|
9
8
|
describe MQTT::Packet do
|
10
9
|
|
@@ -96,7 +95,7 @@ end
|
|
96
95
|
|
97
96
|
describe MQTT::Packet::Publish do
|
98
97
|
describe "when creating a packet" do
|
99
|
-
it "should allow you to set the packet
|
98
|
+
it "should allow you to set the packet QoS level as a hash parameter" do
|
100
99
|
packet = MQTT::Packet::Publish.new( :qos => 2 )
|
101
100
|
expect(packet.qos).to eq(2)
|
102
101
|
end
|
@@ -106,7 +105,7 @@ describe MQTT::Packet::Publish do
|
|
106
105
|
expect(packet.retain).to be_truthy
|
107
106
|
end
|
108
107
|
|
109
|
-
it "should
|
108
|
+
it "should raise an exception the QoS is greater than 2" do
|
110
109
|
expect {
|
111
110
|
packet = MQTT::Packet::Publish.new( :qos => 3 )
|
112
111
|
}.to raise_error(
|
@@ -114,7 +113,7 @@ describe MQTT::Packet::Publish do
|
|
114
113
|
)
|
115
114
|
end
|
116
115
|
|
117
|
-
it "should
|
116
|
+
it "should raise an exception the QoS is less than 0" do
|
118
117
|
expect {
|
119
118
|
packet = MQTT::Packet::Publish.new( :qos => -1 )
|
120
119
|
}.to raise_error(
|
@@ -159,22 +158,22 @@ describe MQTT::Packet::Publish do
|
|
159
158
|
end
|
160
159
|
|
161
160
|
describe "when serialising a packet" do
|
162
|
-
it "should output the correct bytes for a packet with default
|
161
|
+
it "should output the correct bytes for a packet with default QoS and no flags" do
|
163
162
|
packet = MQTT::Packet::Publish.new( :topic => 'test', :payload => 'hello world' )
|
164
163
|
expect(packet.to_s).to eq("\x30\x11\x00\x04testhello world")
|
165
164
|
end
|
166
165
|
|
167
|
-
it "should output the correct bytes for a packet with
|
166
|
+
it "should output the correct bytes for a packet with QoS 1 and no flags" do
|
168
167
|
packet = MQTT::Packet::Publish.new( :id => 5, :qos => 1, :topic => 'a/b', :payload => 'hello world' )
|
169
168
|
expect(packet.to_s).to eq("\x32\x12\x00\x03a/b\x00\x05hello world")
|
170
169
|
end
|
171
170
|
|
172
|
-
it "should output the correct bytes for a packet with
|
171
|
+
it "should output the correct bytes for a packet with QoS 2 and retain flag set" do
|
173
172
|
packet = MQTT::Packet::Publish.new( :id => 5, :qos => 2, :retain => true, :topic => 'c/d', :payload => 'hello world' )
|
174
173
|
expect(packet.to_s).to eq("\x35\x12\x00\x03c/d\x00\x05hello world")
|
175
174
|
end
|
176
175
|
|
177
|
-
it "should output the correct bytes for a packet with
|
176
|
+
it "should output the correct bytes for a packet with QoS 2 and dup flag set" do
|
178
177
|
packet = MQTT::Packet::Publish.new( :id => 5, :qos => 2, :duplicate => true, :topic => 'c/d', :payload => 'hello world' )
|
179
178
|
expect(packet.to_s).to eq("\x3C\x12\x00\x03c/d\x00\x05hello world")
|
180
179
|
end
|
@@ -194,7 +193,7 @@ describe MQTT::Packet::Publish do
|
|
194
193
|
expect(packet.to_s).to eq("\x30\x0c\x00\x06symbol1234")
|
195
194
|
end
|
196
195
|
|
197
|
-
it "should
|
196
|
+
it "should raise an exception when there is no topic name" do
|
198
197
|
expect {
|
199
198
|
MQTT::Packet::Publish.new.to_s
|
200
199
|
}.to raise_error(
|
@@ -202,7 +201,7 @@ describe MQTT::Packet::Publish do
|
|
202
201
|
)
|
203
202
|
end
|
204
203
|
|
205
|
-
it "should
|
204
|
+
it "should raise an exception when there is an empty topic name" do
|
206
205
|
expect {
|
207
206
|
MQTT::Packet::Publish.new( :topic => '' ).to_s
|
208
207
|
}.to raise_error(
|
@@ -212,7 +211,7 @@ describe MQTT::Packet::Publish do
|
|
212
211
|
end
|
213
212
|
|
214
213
|
describe "when serialising an oversized packet" do
|
215
|
-
it "should
|
214
|
+
it "should raise an exception when body is bigger than 256MB" do
|
216
215
|
expect {
|
217
216
|
packet = MQTT::Packet::Publish.new( :topic => 'test', :payload => 'x'*268435455 )
|
218
217
|
packet.to_s
|
@@ -222,14 +221,14 @@ describe MQTT::Packet::Publish do
|
|
222
221
|
end
|
223
222
|
end
|
224
223
|
|
225
|
-
describe "when parsing a packet with
|
224
|
+
describe "when parsing a packet with QoS 0" do
|
226
225
|
let(:packet) { MQTT::Packet.parse( "\x30\x11\x00\x04testhello world" ) }
|
227
226
|
|
228
227
|
it "should correctly create the right type of packet object" do
|
229
228
|
expect(packet.class).to eq(MQTT::Packet::Publish)
|
230
229
|
end
|
231
230
|
|
232
|
-
it "should set the
|
231
|
+
it "should set the QoS level correctly" do
|
233
232
|
expect(packet.qos).to eq(0)
|
234
233
|
end
|
235
234
|
|
@@ -252,14 +251,14 @@ describe MQTT::Packet::Publish do
|
|
252
251
|
end
|
253
252
|
end
|
254
253
|
|
255
|
-
describe "when parsing a packet with
|
254
|
+
describe "when parsing a packet with QoS 2 and retain and dup flags set" do
|
256
255
|
let(:packet) { MQTT::Packet.parse( "\x3D\x12\x00\x03c/d\x00\x05hello world" ) }
|
257
256
|
|
258
257
|
it "should correctly create the right type of packet object" do
|
259
258
|
expect(packet.class).to eq(MQTT::Packet::Publish)
|
260
259
|
end
|
261
260
|
|
262
|
-
it "should set the
|
261
|
+
it "should set the QoS level correctly" do
|
263
262
|
expect(packet.qos).to eq(2)
|
264
263
|
end
|
265
264
|
|
@@ -299,7 +298,7 @@ describe MQTT::Packet::Publish do
|
|
299
298
|
end
|
300
299
|
|
301
300
|
describe "when parsing a packet with a QoS value of 3" do
|
302
|
-
it "should
|
301
|
+
it "should raise an exception" do
|
303
302
|
expect {
|
304
303
|
packet = MQTT::Packet.parse( "\x36\x12\x00\x03a/b\x00\x05hello world" )
|
305
304
|
}.to raise_error(
|
@@ -310,7 +309,7 @@ describe MQTT::Packet::Publish do
|
|
310
309
|
end
|
311
310
|
|
312
311
|
describe "when parsing a packet with QoS value of 0 and DUP set" do
|
313
|
-
it "should
|
312
|
+
it "should raise an exception" do
|
314
313
|
expect {
|
315
314
|
packet = MQTT::Packet.parse( "\x38\x10\x00\x03a/bhello world" )
|
316
315
|
}.to raise_error(
|
@@ -412,7 +411,7 @@ describe MQTT::Packet::Publish do
|
|
412
411
|
expect(packet.body_length).to eq(17)
|
413
412
|
end
|
414
413
|
|
415
|
-
it "should set the
|
414
|
+
it "should set the QoS level correctly" do
|
416
415
|
expect(packet.qos).to eq(0)
|
417
416
|
end
|
418
417
|
|
@@ -469,7 +468,7 @@ describe MQTT::Packet::Connect do
|
|
469
468
|
end
|
470
469
|
|
471
470
|
context "protocol version 3.1.0" do
|
472
|
-
it "should
|
471
|
+
it "should raise an exception when there is no client identifier" do
|
473
472
|
expect {
|
474
473
|
MQTT::Packet::Connect.new(:version => '3.1.0', :client_id => '').to_s
|
475
474
|
}.to raise_error(
|
@@ -477,7 +476,7 @@ describe MQTT::Packet::Connect do
|
|
477
476
|
)
|
478
477
|
end
|
479
478
|
|
480
|
-
it "should
|
479
|
+
it "should raise an exception when the client identifier is too long" do
|
481
480
|
expect {
|
482
481
|
client_id = '0EB8D2FE7C254715B4467C5B2ECAD100'
|
483
482
|
MQTT::Packet::Connect.new(:version => '3.1.0', :client_id => client_id).to_s
|
@@ -508,7 +507,7 @@ describe MQTT::Packet::Connect do
|
|
508
507
|
end
|
509
508
|
end
|
510
509
|
|
511
|
-
it "should
|
510
|
+
it "should raise an exception if the keep alive value is less than 0" do
|
512
511
|
expect {
|
513
512
|
MQTT::Packet::Connect.new(:client_id => 'test', :keep_alive => -2).to_s
|
514
513
|
}.to raise_error(
|
@@ -583,7 +582,7 @@ describe MQTT::Packet::Connect do
|
|
583
582
|
end
|
584
583
|
|
585
584
|
context 'an invalid protocol version number' do
|
586
|
-
it "should
|
585
|
+
it "should raise a protocol exception" do
|
587
586
|
expect {
|
588
587
|
packet = MQTT::Packet::Connect.new( :version => 'x.x.x', :client_id => 'myclient' )
|
589
588
|
}.to raise_error(
|
@@ -744,7 +743,7 @@ describe MQTT::Packet::Connect do
|
|
744
743
|
expect(packet.clean_session).to be_truthy
|
745
744
|
end
|
746
745
|
|
747
|
-
it "should set the
|
746
|
+
it "should set the QoS of the Will should be 1" do
|
748
747
|
expect(packet.will_qos).to eq(1)
|
749
748
|
end
|
750
749
|
|
@@ -941,7 +940,7 @@ describe MQTT::Packet::Connect do
|
|
941
940
|
end
|
942
941
|
|
943
942
|
describe "when parsing packet with an unknown protocol name" do
|
944
|
-
it "should
|
943
|
+
it "should raise a protocol exception" do
|
945
944
|
expect {
|
946
945
|
packet = MQTT::Packet.parse(
|
947
946
|
"\x10\x16\x00\x06FooBar\x03\x00\x00\x0a\x00\x08myclient"
|
@@ -954,7 +953,7 @@ describe MQTT::Packet::Connect do
|
|
954
953
|
end
|
955
954
|
|
956
955
|
describe "when parsing packet with an unknown protocol level" do
|
957
|
-
it "should
|
956
|
+
it "should raise a protocol exception" do
|
958
957
|
expect {
|
959
958
|
packet = MQTT::Packet.parse(
|
960
959
|
"\x10\x16\x00\x06MQIsdp\x02\x00\x00\x0a\x00\x08myclient"
|
@@ -967,7 +966,7 @@ describe MQTT::Packet::Connect do
|
|
967
966
|
end
|
968
967
|
|
969
968
|
describe "when parsing packet with invalid fixed header flags" do
|
970
|
-
it "should
|
969
|
+
it "should raise a protocol exception" do
|
971
970
|
expect {
|
972
971
|
MQTT::Packet.parse(
|
973
972
|
"\x13\x16\x00\x06MQIsdp\x03\x00\x00\x0a\x00\x08myclient"
|
@@ -1199,7 +1198,7 @@ describe MQTT::Packet::Connack do
|
|
1199
1198
|
end
|
1200
1199
|
|
1201
1200
|
describe "when parsing packet with invalid Connack flags set" do
|
1202
|
-
it "should
|
1201
|
+
it "should raise an exception" do
|
1203
1202
|
expect {
|
1204
1203
|
packet = MQTT::Packet.parse( "\x20\x02\xff\x05" )
|
1205
1204
|
}.to raise_error(
|
@@ -1210,7 +1209,7 @@ describe MQTT::Packet::Connack do
|
|
1210
1209
|
end
|
1211
1210
|
|
1212
1211
|
describe "when parsing packet with extra bytes on the end" do
|
1213
|
-
it "should
|
1212
|
+
it "should raise an exception" do
|
1214
1213
|
expect {
|
1215
1214
|
packet = MQTT::Packet.parse( "\x20\x03\x00\x00\x00" )
|
1216
1215
|
}.to raise_error(
|
@@ -1221,7 +1220,7 @@ describe MQTT::Packet::Connack do
|
|
1221
1220
|
end
|
1222
1221
|
|
1223
1222
|
describe "when parsing packet with invalid fixed header flags" do
|
1224
|
-
it "should
|
1223
|
+
it "should raise a protocol exception" do
|
1225
1224
|
expect {
|
1226
1225
|
MQTT::Packet.parse( "\x23\x02\x00\x00" )
|
1227
1226
|
}.to raise_error(
|
@@ -1264,7 +1263,7 @@ describe MQTT::Packet::Puback do
|
|
1264
1263
|
end
|
1265
1264
|
|
1266
1265
|
describe "when parsing packet with extra bytes on the end" do
|
1267
|
-
it "should
|
1266
|
+
it "should raise an exception" do
|
1268
1267
|
expect {
|
1269
1268
|
packet = MQTT::Packet.parse( "\x40\x03\x12\x34\x00" )
|
1270
1269
|
}.to raise_error(
|
@@ -1275,7 +1274,7 @@ describe MQTT::Packet::Puback do
|
|
1275
1274
|
end
|
1276
1275
|
|
1277
1276
|
describe "when parsing packet with invalid fixed header flags" do
|
1278
|
-
it "should
|
1277
|
+
it "should raise a protocol exception" do
|
1279
1278
|
expect {
|
1280
1279
|
MQTT::Packet.parse( "\x43\x02\x12\x34" )
|
1281
1280
|
}.to raise_error(
|
@@ -1312,7 +1311,7 @@ describe MQTT::Packet::Pubrec do
|
|
1312
1311
|
end
|
1313
1312
|
|
1314
1313
|
describe "when parsing packet with extra bytes on the end" do
|
1315
|
-
it "should
|
1314
|
+
it "should raise an exception" do
|
1316
1315
|
expect {
|
1317
1316
|
packet = MQTT::Packet.parse( "\x50\x03\x12\x34\x00" )
|
1318
1317
|
}.to raise_error(
|
@@ -1323,7 +1322,7 @@ describe MQTT::Packet::Pubrec do
|
|
1323
1322
|
end
|
1324
1323
|
|
1325
1324
|
describe "when parsing packet with invalid fixed header flags" do
|
1326
|
-
it "should
|
1325
|
+
it "should raise a protocol exception" do
|
1327
1326
|
expect {
|
1328
1327
|
MQTT::Packet.parse( "\x53\x02\x12\x34" )
|
1329
1328
|
}.to raise_error(
|
@@ -1360,7 +1359,7 @@ describe MQTT::Packet::Pubrel do
|
|
1360
1359
|
end
|
1361
1360
|
|
1362
1361
|
describe "when parsing packet with extra bytes on the end" do
|
1363
|
-
it "should
|
1362
|
+
it "should raise an exception" do
|
1364
1363
|
expect {
|
1365
1364
|
packet = MQTT::Packet.parse( "\x62\x03\x12\x34\x00" )
|
1366
1365
|
}.to raise_error(
|
@@ -1371,7 +1370,7 @@ describe MQTT::Packet::Pubrel do
|
|
1371
1370
|
end
|
1372
1371
|
|
1373
1372
|
describe "when parsing packet with invalid fixed header flags" do
|
1374
|
-
it "should
|
1373
|
+
it "should raise a protocol exception" do
|
1375
1374
|
expect {
|
1376
1375
|
MQTT::Packet.parse( "\x60\x02\x12\x34" )
|
1377
1376
|
}.to raise_error(
|
@@ -1408,7 +1407,7 @@ describe MQTT::Packet::Pubcomp do
|
|
1408
1407
|
end
|
1409
1408
|
|
1410
1409
|
describe "when parsing packet with extra bytes on the end" do
|
1411
|
-
it "should
|
1410
|
+
it "should raise an exception" do
|
1412
1411
|
expect {
|
1413
1412
|
MQTT::Packet.parse( "\x70\x03\x12\x34\x00" )
|
1414
1413
|
}.to raise_error(
|
@@ -1419,7 +1418,7 @@ describe MQTT::Packet::Pubcomp do
|
|
1419
1418
|
end
|
1420
1419
|
|
1421
1420
|
describe "when parsing packet with invalid fixed header flags" do
|
1422
|
-
it "should
|
1421
|
+
it "should raise a protocol exception" do
|
1423
1422
|
expect {
|
1424
1423
|
MQTT::Packet.parse( "\x72\x02\x12\x34" )
|
1425
1424
|
}.to raise_error(
|
@@ -1464,7 +1463,7 @@ describe MQTT::Packet::Subscribe do
|
|
1464
1463
|
expect(packet.topics).to eq([['a/b', 0], ['b/c', 1]])
|
1465
1464
|
end
|
1466
1465
|
|
1467
|
-
it "should
|
1466
|
+
it "should raise an exception when setting topic with a non-string" do
|
1468
1467
|
expect {
|
1469
1468
|
packet.topics = 56
|
1470
1469
|
}.to raise_error(
|
@@ -1484,7 +1483,7 @@ describe MQTT::Packet::Subscribe do
|
|
1484
1483
|
expect(packet.to_s).to eq("\x82\x0e\000\x06\x00\x03a/b\x00\x00\x03c/d\x01")
|
1485
1484
|
end
|
1486
1485
|
|
1487
|
-
it "should
|
1486
|
+
it "should raise an exception when no topics are given" do
|
1488
1487
|
expect {
|
1489
1488
|
MQTT::Packet::Subscribe.new.to_s
|
1490
1489
|
}.to raise_error(
|
@@ -1534,7 +1533,7 @@ describe MQTT::Packet::Subscribe do
|
|
1534
1533
|
end
|
1535
1534
|
|
1536
1535
|
describe "when parsing packet with invalid fixed header flags" do
|
1537
|
-
it "should
|
1536
|
+
it "should raise a protocol exception" do
|
1538
1537
|
expect {
|
1539
1538
|
MQTT::Packet.parse( "\x80\x08\x00\x01\x00\x03a/b\x00" )
|
1540
1539
|
}.to raise_error(
|
@@ -1569,15 +1568,15 @@ describe MQTT::Packet::Suback do
|
|
1569
1568
|
expect(packet.to_s).to eq("\x90\x04\x00\x06\x00\x01")
|
1570
1569
|
end
|
1571
1570
|
|
1572
|
-
it "should
|
1571
|
+
it "should raise an exception when no granted QoSs are given" do
|
1573
1572
|
expect {
|
1574
1573
|
MQTT::Packet::Suback.new( :id => 7 ).to_s
|
1575
1574
|
}.to raise_error(
|
1576
|
-
'no granted
|
1575
|
+
'no granted QoS given when serialising packet'
|
1577
1576
|
)
|
1578
1577
|
end
|
1579
1578
|
|
1580
|
-
it "should
|
1579
|
+
it "should raise an exception if the granted QoS is not an integer" do
|
1581
1580
|
expect {
|
1582
1581
|
MQTT::Packet::Suback.new( :id => 8, :return_codes => :foo ).to_s
|
1583
1582
|
}.to raise_error(
|
@@ -1586,7 +1585,7 @@ describe MQTT::Packet::Suback do
|
|
1586
1585
|
end
|
1587
1586
|
end
|
1588
1587
|
|
1589
|
-
describe "when parsing a packet with a single
|
1588
|
+
describe "when parsing a packet with a single QoS value of 0" do
|
1590
1589
|
let(:packet) { MQTT::Packet.parse( "\x90\x03\x12\x34\x00" ) }
|
1591
1590
|
|
1592
1591
|
it "should correctly create the right type of packet object" do
|
@@ -1597,12 +1596,12 @@ describe MQTT::Packet::Suback do
|
|
1597
1596
|
expect(packet.id).to eq(0x1234)
|
1598
1597
|
end
|
1599
1598
|
|
1600
|
-
it "should set the Granted
|
1599
|
+
it "should set the Granted QoS of the packet correctly" do
|
1601
1600
|
expect(packet.return_codes).to eq([0])
|
1602
1601
|
end
|
1603
1602
|
end
|
1604
1603
|
|
1605
|
-
describe "when parsing a packet with two
|
1604
|
+
describe "when parsing a packet with two QoS values" do
|
1606
1605
|
let(:packet) { MQTT::Packet.parse( "\x90\x04\x12\x34\x01\x01" ) }
|
1607
1606
|
|
1608
1607
|
it "should correctly create the right type of packet object" do
|
@@ -1613,13 +1612,13 @@ describe MQTT::Packet::Suback do
|
|
1613
1612
|
expect(packet.id).to eq(0x1234)
|
1614
1613
|
end
|
1615
1614
|
|
1616
|
-
it "should set the Granted
|
1615
|
+
it "should set the Granted QoS of the packet correctly" do
|
1617
1616
|
expect(packet.return_codes).to eq([1,1])
|
1618
1617
|
end
|
1619
1618
|
end
|
1620
1619
|
|
1621
1620
|
describe "when parsing packet with invalid fixed header flags" do
|
1622
|
-
it "should
|
1621
|
+
it "should raise a protocol exception" do
|
1623
1622
|
expect {
|
1624
1623
|
MQTT::Packet.parse( "\x92\x03\x12\x34\x00" )
|
1625
1624
|
}.to raise_error(
|
@@ -1666,7 +1665,7 @@ describe MQTT::Packet::Unsubscribe do
|
|
1666
1665
|
expect(packet.to_s).to eq("\xa2\x0c\000\006\000\003a/b\000\003c/d")
|
1667
1666
|
end
|
1668
1667
|
|
1669
|
-
it "should
|
1668
|
+
it "should raise an exception when no topics are given" do
|
1670
1669
|
expect {
|
1671
1670
|
MQTT::Packet::Unsubscribe.new.to_s
|
1672
1671
|
}.to raise_error(
|
@@ -1692,7 +1691,7 @@ describe MQTT::Packet::Unsubscribe do
|
|
1692
1691
|
end
|
1693
1692
|
|
1694
1693
|
describe "when parsing packet with invalid fixed header flags" do
|
1695
|
-
it "should
|
1694
|
+
it "should raise a protocol exception" do
|
1696
1695
|
expect {
|
1697
1696
|
MQTT::Packet.parse( "\xa0\x07\x00\x05\x00\x03a/b" )
|
1698
1697
|
}.to raise_error(
|
@@ -1738,7 +1737,7 @@ describe MQTT::Packet::Unsuback do
|
|
1738
1737
|
end
|
1739
1738
|
|
1740
1739
|
describe "when parsing packet with extra bytes on the end" do
|
1741
|
-
it "should
|
1740
|
+
it "should raise an exception" do
|
1742
1741
|
expect {
|
1743
1742
|
packet = MQTT::Packet.parse( "\xB0\x03\x12\x34\x00" )
|
1744
1743
|
}.to raise_error(
|
@@ -1749,7 +1748,7 @@ describe MQTT::Packet::Unsuback do
|
|
1749
1748
|
end
|
1750
1749
|
|
1751
1750
|
describe "when parsing packet with invalid fixed header flags" do
|
1752
|
-
it "should
|
1751
|
+
it "should raise a protocol exception" do
|
1753
1752
|
expect {
|
1754
1753
|
MQTT::Packet.parse( "\xB2\x02\x12\x34" )
|
1755
1754
|
}.to raise_error(
|
@@ -1779,7 +1778,7 @@ describe MQTT::Packet::Pingreq do
|
|
1779
1778
|
expect(packet.class).to eq(MQTT::Packet::Pingreq)
|
1780
1779
|
end
|
1781
1780
|
|
1782
|
-
it "should
|
1781
|
+
it "should raise an exception if the packet has a payload" do
|
1783
1782
|
expect {
|
1784
1783
|
MQTT::Packet.parse( "\xC0\x05hello" )
|
1785
1784
|
}.to raise_error(
|
@@ -1789,7 +1788,7 @@ describe MQTT::Packet::Pingreq do
|
|
1789
1788
|
end
|
1790
1789
|
|
1791
1790
|
describe "when parsing packet with invalid fixed header flags" do
|
1792
|
-
it "should
|
1791
|
+
it "should raise a protocol exception" do
|
1793
1792
|
expect {
|
1794
1793
|
MQTT::Packet.parse( "\xC2\x00" )
|
1795
1794
|
}.to raise_error(
|
@@ -1819,7 +1818,7 @@ describe MQTT::Packet::Pingresp do
|
|
1819
1818
|
expect(packet.class).to eq(MQTT::Packet::Pingresp)
|
1820
1819
|
end
|
1821
1820
|
|
1822
|
-
it "should
|
1821
|
+
it "should raise an exception if the packet has a payload" do
|
1823
1822
|
expect {
|
1824
1823
|
MQTT::Packet.parse( "\xD0\x05hello" )
|
1825
1824
|
}.to raise_error(
|
@@ -1829,7 +1828,7 @@ describe MQTT::Packet::Pingresp do
|
|
1829
1828
|
end
|
1830
1829
|
|
1831
1830
|
describe "when parsing packet with invalid fixed header flags" do
|
1832
|
-
it "should
|
1831
|
+
it "should raise a protocol exception" do
|
1833
1832
|
expect {
|
1834
1833
|
MQTT::Packet.parse( "\xD2\x00" )
|
1835
1834
|
}.to raise_error(
|
@@ -1860,7 +1859,7 @@ describe MQTT::Packet::Disconnect do
|
|
1860
1859
|
expect(packet.class).to eq(MQTT::Packet::Disconnect)
|
1861
1860
|
end
|
1862
1861
|
|
1863
|
-
it "should
|
1862
|
+
it "should raise an exception if the packet has a payload" do
|
1864
1863
|
expect {
|
1865
1864
|
MQTT::Packet.parse( "\xE0\x05hello" )
|
1866
1865
|
}.to raise_error(
|
@@ -1870,7 +1869,7 @@ describe MQTT::Packet::Disconnect do
|
|
1870
1869
|
end
|
1871
1870
|
|
1872
1871
|
describe "when parsing packet with invalid fixed header flags" do
|
1873
|
-
it "should
|
1872
|
+
it "should raise a protocol exception" do
|
1874
1873
|
expect {
|
1875
1874
|
MQTT::Packet.parse( "\xE2\x00" )
|
1876
1875
|
}.to raise_error(
|
@@ -1889,7 +1888,7 @@ end
|
|
1889
1888
|
|
1890
1889
|
describe "Serialising an invalid packet" do
|
1891
1890
|
context "that has a no type" do
|
1892
|
-
it "should
|
1891
|
+
it "should raise an exception" do
|
1893
1892
|
expect {
|
1894
1893
|
MQTT::Packet.new.to_s
|
1895
1894
|
}.to raise_error(
|
@@ -1902,7 +1901,7 @@ end
|
|
1902
1901
|
|
1903
1902
|
describe "Reading in an invalid packet from a socket" do
|
1904
1903
|
context "that has 0 length" do
|
1905
|
-
it "should
|
1904
|
+
it "should raise an exception" do
|
1906
1905
|
expect {
|
1907
1906
|
socket = StringIO.new
|
1908
1907
|
MQTT::Packet.read(socket)
|
@@ -1914,7 +1913,7 @@ describe "Reading in an invalid packet from a socket" do
|
|
1914
1913
|
end
|
1915
1914
|
|
1916
1915
|
context "that has an incomplete packet length header" do
|
1917
|
-
it "should
|
1916
|
+
it "should raise an exception" do
|
1918
1917
|
expect {
|
1919
1918
|
socket = StringIO.new("\x30\xFF")
|
1920
1919
|
MQTT::Packet.read(socket)
|
@@ -1926,7 +1925,7 @@ describe "Reading in an invalid packet from a socket" do
|
|
1926
1925
|
end
|
1927
1926
|
|
1928
1927
|
context "that has the maximum number of bytes in the length header" do
|
1929
|
-
it "should
|
1928
|
+
it "should raise an exception" do
|
1930
1929
|
expect {
|
1931
1930
|
socket = StringIO.new("\x30\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
|
1932
1931
|
MQTT::Packet.read(socket)
|
@@ -1940,7 +1939,7 @@ end
|
|
1940
1939
|
|
1941
1940
|
describe "Parsing an invalid packet" do
|
1942
1941
|
context "that has no length" do
|
1943
|
-
it "should
|
1942
|
+
it "should raise an exception" do
|
1944
1943
|
expect {
|
1945
1944
|
MQTT::Packet.parse( "" )
|
1946
1945
|
}.to raise_error(
|
@@ -1951,7 +1950,7 @@ describe "Parsing an invalid packet" do
|
|
1951
1950
|
end
|
1952
1951
|
|
1953
1952
|
context "that has an invalid type identifier" do
|
1954
|
-
it "should
|
1953
|
+
it "should raise an exception" do
|
1955
1954
|
expect {
|
1956
1955
|
MQTT::Packet.parse( "\x00\x00" )
|
1957
1956
|
}.to raise_error(
|
@@ -1962,7 +1961,7 @@ describe "Parsing an invalid packet" do
|
|
1962
1961
|
end
|
1963
1962
|
|
1964
1963
|
context "that has an incomplete packet length header" do
|
1965
|
-
it "should
|
1964
|
+
it "should raise an exception" do
|
1966
1965
|
expect {
|
1967
1966
|
MQTT::Packet.parse( "\x30\xFF" )
|
1968
1967
|
}.to raise_error(
|
@@ -1973,7 +1972,7 @@ describe "Parsing an invalid packet" do
|
|
1973
1972
|
end
|
1974
1973
|
|
1975
1974
|
context "that has too many bytes in the length field" do
|
1976
|
-
it "should
|
1975
|
+
it "should raise an exception" do
|
1977
1976
|
expect {
|
1978
1977
|
MQTT::Packet.parse( "\x30\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" )
|
1979
1978
|
}.to raise_error(
|
@@ -1984,7 +1983,7 @@ describe "Parsing an invalid packet" do
|
|
1984
1983
|
end
|
1985
1984
|
|
1986
1985
|
context "that has a bigger buffer than expected" do
|
1987
|
-
it "should
|
1986
|
+
it "should raise an exception" do
|
1988
1987
|
expect {
|
1989
1988
|
MQTT::Packet.parse( "\x30\x11\x00\x04testhello big world" )
|
1990
1989
|
}.to raise_error(
|
@@ -1995,7 +1994,7 @@ describe "Parsing an invalid packet" do
|
|
1995
1994
|
end
|
1996
1995
|
|
1997
1996
|
context "that has a smaller buffer than expected" do
|
1998
|
-
it "should
|
1997
|
+
it "should raise an exception" do
|
1999
1998
|
expect {
|
2000
1999
|
MQTT::Packet.parse( "\x30\x11\x00\x04testhello" )
|
2001
2000
|
}.to raise_error(
|