qubitro-mqtt 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/qubitro-mqtt/client.rb +10 -10
- data/lib/qubitro-mqtt/packet.rb +14 -14
- data/lib/qubitro-mqtt/version.rb +1 -1
- data/spec/mqtt_client_spec.rb +14 -14
- data/spec/mqtt_packet_spec.rb +56 -56
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e45bcfabd6e2367a012443f034589db3f5b2c77c3c094194b9c5f40fbde2ffd
|
4
|
+
data.tar.gz: 033462023ec38750bef3e354254ac9695a6fa4498aca320792e8669a8ece2dd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b214109e69f71238e59479e284b09bf49cffaca0ec9b47555f5d37c0d69455395782a758518783119ca7063f53c79afa38d134db8da12507a46b5088d46db5f8
|
7
|
+
data.tar.gz: 66fade5d90ac5c4fc5575da1957778a0589364aa3d57af3ed051cc7f60b903d702c6d5c88cd2fa39ab0c48c85c3660dd01c3f846f0e6d2254da828118b3b0e98
|
data/lib/qubitro-mqtt/client.rb
CHANGED
@@ -35,11 +35,11 @@ module MQTT
|
|
35
35
|
# Number of seconds to wait for acknowledgement packets (default is 5 seconds)
|
36
36
|
attr_accessor :ack_timeout
|
37
37
|
|
38
|
-
#
|
39
|
-
attr_accessor :
|
38
|
+
# Device ID to authenticate to the server with
|
39
|
+
attr_accessor :deviceId
|
40
40
|
|
41
|
-
#
|
42
|
-
attr_accessor :
|
41
|
+
# Device Token to authenticate to the server with
|
42
|
+
attr_accessor :deviceToken
|
43
43
|
|
44
44
|
# The topic that the Will message is published to
|
45
45
|
attr_accessor :will_topic
|
@@ -68,8 +68,8 @@ module MQTT
|
|
68
68
|
:clean_session => true,
|
69
69
|
:client_id => nil,
|
70
70
|
:ack_timeout => 5,
|
71
|
-
:
|
72
|
-
:
|
71
|
+
:deviceId => nil,
|
72
|
+
:deviceToken => nil,
|
73
73
|
:will_topic => nil,
|
74
74
|
:will_payload => nil,
|
75
75
|
:will_qos => 0,
|
@@ -252,8 +252,8 @@ module MQTT
|
|
252
252
|
:clean_session => @clean_session,
|
253
253
|
:keep_alive => @keep_alive,
|
254
254
|
:client_id => @client_id,
|
255
|
-
:
|
256
|
-
:
|
255
|
+
:deviceId => @deviceId,
|
256
|
+
:deviceToken => @deviceToken,
|
257
257
|
:will_topic => @will_topic,
|
258
258
|
:will_payload => @will_payload,
|
259
259
|
:will_qos => @will_qos,
|
@@ -579,8 +579,8 @@ module MQTT
|
|
579
579
|
{
|
580
580
|
:host => uri.host,
|
581
581
|
:port => uri.port || nil,
|
582
|
-
:
|
583
|
-
:
|
582
|
+
:deviceId => uri.user ? URI.unescape(uri.user) : nil,
|
583
|
+
:deviceToken => uri.password ? URI.unescape(uri.password) : nil,
|
584
584
|
:ssl => ssl
|
585
585
|
}
|
586
586
|
end
|
data/lib/qubitro-mqtt/packet.rb
CHANGED
@@ -422,11 +422,11 @@ module MQTT
|
|
422
422
|
# The payload of the Will message
|
423
423
|
attr_accessor :will_payload
|
424
424
|
|
425
|
-
# The
|
426
|
-
attr_accessor :
|
425
|
+
# The deviceId for authenticating with the server
|
426
|
+
attr_accessor :deviceId
|
427
427
|
|
428
|
-
# The
|
429
|
-
attr_accessor :
|
428
|
+
# The deviceToken for authenticating with the server
|
429
|
+
attr_accessor :deviceToken
|
430
430
|
|
431
431
|
# Default attribute values
|
432
432
|
ATTR_DEFAULTS = {
|
@@ -438,8 +438,8 @@ module MQTT
|
|
438
438
|
:ack_timeout => 15,
|
439
439
|
:will_retain => false,
|
440
440
|
:will_payload => '',
|
441
|
-
:
|
442
|
-
:
|
441
|
+
:deviceId => nil,
|
442
|
+
:deviceToken => nil
|
443
443
|
}
|
444
444
|
|
445
445
|
# Create a new Client Connect packet
|
@@ -479,8 +479,8 @@ module MQTT
|
|
479
479
|
@connect_flags |= 0x04 unless @will_topic.nil?
|
480
480
|
@connect_flags |= ((@will_qos & 0x03) << 3)
|
481
481
|
@connect_flags |= 0x20 if @will_retain
|
482
|
-
@connect_flags |= 0x40 unless @
|
483
|
-
@connect_flags |= 0x80 unless @
|
482
|
+
@connect_flags |= 0x40 unless @deviceToken.nil?
|
483
|
+
@connect_flags |= 0x80 unless @deviceId.nil?
|
484
484
|
body += encode_bytes(@connect_flags)
|
485
485
|
|
486
486
|
body += encode_short(@keep_alive)
|
@@ -490,8 +490,8 @@ module MQTT
|
|
490
490
|
# The MQTT v3.1 specification says that the payload is a UTF-8 string
|
491
491
|
body += encode_string(@will_payload)
|
492
492
|
end
|
493
|
-
body += encode_string(@
|
494
|
-
body += encode_string(@
|
493
|
+
body += encode_string(@deviceId) unless @deviceId.nil?
|
494
|
+
body += encode_string(@deviceToken) unless @deviceToken.nil?
|
495
495
|
body
|
496
496
|
end
|
497
497
|
|
@@ -521,10 +521,10 @@ module MQTT
|
|
521
521
|
@will_payload = shift_string(buffer)
|
522
522
|
end
|
523
523
|
if ((@connect_flags & 0x80) >> 7) == 0x01 && buffer.bytesize > 0
|
524
|
-
@
|
524
|
+
@deviceId = shift_string(buffer)
|
525
525
|
end
|
526
526
|
if ((@connect_flags & 0x40) >> 6) == 0x01 && buffer.bytesize > 0 # rubocop: disable Style/GuardClause
|
527
|
-
@
|
527
|
+
@deviceToken = shift_string(buffer)
|
528
528
|
end
|
529
529
|
end
|
530
530
|
|
@@ -534,8 +534,8 @@ module MQTT
|
|
534
534
|
"keep_alive=#{keep_alive}"
|
535
535
|
str += ', clean' if clean_session
|
536
536
|
str += ", client_id='#{client_id}'"
|
537
|
-
str += ",
|
538
|
-
str += ',
|
537
|
+
str += ", deviceId='#{deviceId}'" unless deviceId.nil?
|
538
|
+
str += ', deviceToken=...' unless deviceToken.nil?
|
539
539
|
str + '>'
|
540
540
|
end
|
541
541
|
|
data/lib/qubitro-mqtt/version.rb
CHANGED
data/spec/mqtt_client_spec.rb
CHANGED
@@ -109,28 +109,28 @@ describe MQTT::Client do
|
|
109
109
|
expect(client.ssl).to be_truthy
|
110
110
|
end
|
111
111
|
|
112
|
-
it "with a URI containing a
|
112
|
+
it "with a URI containing a deviceId and deviceToken" do
|
113
113
|
client = MQTT::Client.new(URI.parse('mqtt://auser:bpass@mqtt.example.com'))
|
114
114
|
expect(client.host).to eq('mqtt.example.com')
|
115
115
|
expect(client.port).to eq(1883)
|
116
|
-
expect(client.
|
117
|
-
expect(client.
|
116
|
+
expect(client.deviceId).to eq('auser')
|
117
|
+
expect(client.deviceToken).to eq('bpass')
|
118
118
|
end
|
119
119
|
|
120
|
-
it "with a URI containing an escaped
|
120
|
+
it "with a URI containing an escaped deviceId and deviceToken" do
|
121
121
|
client = MQTT::Client.new(URI.parse('mqtt://foo%20bar:%40123%2B%25@mqtt.example.com'))
|
122
122
|
expect(client.host).to eq('mqtt.example.com')
|
123
123
|
expect(client.port).to eq(1883)
|
124
|
-
expect(client.
|
125
|
-
expect(client.
|
124
|
+
expect(client.deviceId).to eq('foo bar')
|
125
|
+
expect(client.deviceToken).to eq('@123+%')
|
126
126
|
end
|
127
127
|
|
128
|
-
it "with a URI containing a double escaped
|
128
|
+
it "with a URI containing a double escaped deviceId and deviceToken" do
|
129
129
|
client = MQTT::Client.new(URI.parse('mqtt://foo%2520bar:123%2525@mqtt.example.com'))
|
130
130
|
expect(client.host).to eq('mqtt.example.com')
|
131
131
|
expect(client.port).to eq(1883)
|
132
|
-
expect(client.
|
133
|
-
expect(client.
|
132
|
+
expect(client.deviceId).to eq('foo%20bar')
|
133
|
+
expect(client.deviceToken).to eq('123%25')
|
134
134
|
end
|
135
135
|
|
136
136
|
it "with a URI as a string" do
|
@@ -334,17 +334,17 @@ describe MQTT::Client do
|
|
334
334
|
client.connect('myclient')
|
335
335
|
end
|
336
336
|
|
337
|
-
it "should include the
|
338
|
-
client.
|
339
|
-
client.
|
337
|
+
it "should include the deviceId and deviceToken for an authenticated connection" do
|
338
|
+
client.deviceId = 'deviceId'
|
339
|
+
client.deviceToken = 'deviceToken'
|
340
340
|
client.connect('myclient')
|
341
341
|
expect(socket.string).to eq(
|
342
342
|
"\x10\x28"+
|
343
343
|
"\x00\x04MQTT"+
|
344
344
|
"\x04\xC2\x00\x0f"+
|
345
345
|
"\x00\x08myclient"+
|
346
|
-
"\x00\
|
347
|
-
"\x00\
|
346
|
+
"\x00\x08deviceId"+
|
347
|
+
"\x00\x08deviceToken"
|
348
348
|
)
|
349
349
|
end
|
350
350
|
|
data/spec/mqtt_packet_spec.rb
CHANGED
@@ -541,19 +541,19 @@ describe MQTT::Packet::Connect do
|
|
541
541
|
)
|
542
542
|
end
|
543
543
|
|
544
|
-
it "should output the correct bytes for a packet with a
|
544
|
+
it "should output the correct bytes for a packet with a deviceId and deviceToken" do
|
545
545
|
packet = MQTT::Packet::Connect.new(
|
546
546
|
:client_id => 'myclient',
|
547
|
-
:
|
548
|
-
:
|
547
|
+
:deviceId => 'deviceId',
|
548
|
+
:deviceToken => 'deviceToken'
|
549
549
|
)
|
550
550
|
expect(packet.to_s).to eq(
|
551
551
|
"\x10\x2A"+
|
552
552
|
"\x00\x06MQIsdp"+
|
553
553
|
"\x03\xC2\x00\x0f"+
|
554
554
|
"\x00\x08myclient"+
|
555
|
-
"\x00\
|
556
|
-
"\x00\
|
555
|
+
"\x00\x08deviceId"+
|
556
|
+
"\x00\x08deviceToken"
|
557
557
|
)
|
558
558
|
end
|
559
559
|
|
@@ -566,8 +566,8 @@ describe MQTT::Packet::Connect do
|
|
566
566
|
:will_retain => true,
|
567
567
|
:will_topic => 'will_topic',
|
568
568
|
:will_payload => 'will_message',
|
569
|
-
:
|
570
|
-
:
|
569
|
+
:deviceId => 'user0123456789',
|
570
|
+
:deviceToken => 'pass0123456789'
|
571
571
|
)
|
572
572
|
expect(packet.to_s).to eq(
|
573
573
|
"\x10\x5F"+ # fixed header (2)
|
@@ -577,9 +577,9 @@ describe MQTT::Packet::Connect do
|
|
577
577
|
"\x00\x1712345678901234567890123"+ # client identifier (25)
|
578
578
|
"\x00\x0Awill_topic"+ # will topic (12)
|
579
579
|
"\x00\x0Cwill_message"+ # will message (14)
|
580
|
-
"\x00\x0Euser0123456789"+ #
|
580
|
+
"\x00\x0Euser0123456789"+ # deviceId (16)
|
581
581
|
"\x00\x0Epass0123456789"
|
582
|
-
) #
|
582
|
+
) # deviceToken (16)
|
583
583
|
end
|
584
584
|
|
585
585
|
context 'protocol version 3.1.1' do
|
@@ -643,12 +643,12 @@ describe MQTT::Packet::Connect do
|
|
643
643
|
expect(packet.clean_session).to be_falsey
|
644
644
|
end
|
645
645
|
|
646
|
-
it "should set the the
|
647
|
-
expect(packet.
|
646
|
+
it "should set the the deviceId field of the packet to nil" do
|
647
|
+
expect(packet.deviceId).to be_nil
|
648
648
|
end
|
649
649
|
|
650
|
-
it "should set the the
|
651
|
-
expect(packet.
|
650
|
+
it "should set the the deviceToken field of the packet to nil" do
|
651
|
+
expect(packet.deviceToken).to be_nil
|
652
652
|
end
|
653
653
|
end
|
654
654
|
|
@@ -693,12 +693,12 @@ describe MQTT::Packet::Connect do
|
|
693
693
|
expect(packet.clean_session).to be_falsey
|
694
694
|
end
|
695
695
|
|
696
|
-
it "should set the the
|
697
|
-
expect(packet.
|
696
|
+
it "should set the the deviceId field of the packet to nil" do
|
697
|
+
expect(packet.deviceId).to be_nil
|
698
698
|
end
|
699
699
|
|
700
|
-
it "should set the the
|
701
|
-
expect(packet.
|
700
|
+
it "should set the the deviceToken field of the packet to nil" do
|
701
|
+
expect(packet.deviceToken).to be_nil
|
702
702
|
end
|
703
703
|
end
|
704
704
|
|
@@ -770,15 +770,15 @@ describe MQTT::Packet::Connect do
|
|
770
770
|
end
|
771
771
|
end
|
772
772
|
|
773
|
-
describe "when parsing a Connect packet with a
|
773
|
+
describe "when parsing a Connect packet with a deviceId and deviceToken" do
|
774
774
|
let(:packet) do
|
775
775
|
MQTT::Packet.parse(
|
776
776
|
"\x10\x2A"+
|
777
777
|
"\x00\x06MQIsdp"+
|
778
778
|
"\x03\xC0\x00\x0a"+
|
779
779
|
"\x00\x08myclient"+
|
780
|
-
"\x00\
|
781
|
-
"\x00\
|
780
|
+
"\x00\x08deviceId"+
|
781
|
+
"\x00\x08deviceToken"
|
782
782
|
)
|
783
783
|
end
|
784
784
|
|
@@ -812,64 +812,64 @@ describe MQTT::Packet::Connect do
|
|
812
812
|
expect(packet.keep_alive).to eq(10)
|
813
813
|
end
|
814
814
|
|
815
|
-
it "should set the
|
816
|
-
expect(packet.
|
817
|
-
expect(packet.
|
815
|
+
it "should set the Device ID of the packet correctly" do
|
816
|
+
expect(packet.deviceId).to eq('deviceId')
|
817
|
+
expect(packet.deviceId.encoding.to_s).to eq('UTF-8')
|
818
818
|
end
|
819
819
|
|
820
|
-
it "should set the
|
821
|
-
expect(packet.
|
822
|
-
expect(packet.
|
820
|
+
it "should set the Device ID of the packet correctly" do
|
821
|
+
expect(packet.deviceToken).to eq('deviceToken')
|
822
|
+
expect(packet.deviceToken.encoding.to_s).to eq('UTF-8')
|
823
823
|
end
|
824
824
|
end
|
825
825
|
|
826
|
-
describe "when parsing a Connect that has a
|
826
|
+
describe "when parsing a Connect that has a deviceId but no deviceToken" do
|
827
827
|
let(:packet) do
|
828
828
|
MQTT::Packet.parse(
|
829
|
-
"\x10\x20\x00\x06MQIsdp\x03\x80\x00\x0a\x00\x08myclient\x00\
|
829
|
+
"\x10\x20\x00\x06MQIsdp\x03\x80\x00\x0a\x00\x08myclient\x00\x08deviceId"
|
830
830
|
)
|
831
831
|
end
|
832
832
|
|
833
|
-
it "should set the
|
834
|
-
expect(packet.
|
835
|
-
expect(packet.
|
833
|
+
it "should set the Device ID of the packet correctly" do
|
834
|
+
expect(packet.deviceId).to eq('deviceId')
|
835
|
+
expect(packet.deviceId.encoding.to_s).to eq('UTF-8')
|
836
836
|
end
|
837
837
|
|
838
|
-
it "should set the
|
839
|
-
expect(packet.
|
838
|
+
it "should set the Device ID of the packet correctly" do
|
839
|
+
expect(packet.deviceToken).to be_nil
|
840
840
|
end
|
841
841
|
end
|
842
842
|
|
843
|
-
describe "when parsing a Connect that has a
|
843
|
+
describe "when parsing a Connect that has a deviceToken but no deviceId" do
|
844
844
|
let(:packet) do
|
845
845
|
MQTT::Packet.parse(
|
846
|
-
"\x10\x20\x00\x06MQIsdp\x03\x40\x00\x0a\x00\x08myclient\x00\
|
846
|
+
"\x10\x20\x00\x06MQIsdp\x03\x40\x00\x0a\x00\x08myclient\x00\x08deviceToken"
|
847
847
|
)
|
848
848
|
end
|
849
849
|
|
850
|
-
it "should set the
|
851
|
-
expect(packet.
|
850
|
+
it "should set the Device ID of the packet correctly" do
|
851
|
+
expect(packet.deviceId).to be_nil
|
852
852
|
end
|
853
853
|
|
854
|
-
it "should set the
|
855
|
-
expect(packet.
|
856
|
-
expect(packet.
|
854
|
+
it "should set the Device ID of the packet correctly" do
|
855
|
+
expect(packet.deviceToken).to eq('deviceToken')
|
856
|
+
expect(packet.deviceToken.encoding.to_s).to eq('UTF-8')
|
857
857
|
end
|
858
858
|
end
|
859
859
|
|
860
|
-
describe "when parsing a Connect packet has the
|
860
|
+
describe "when parsing a Connect packet has the deviceId and deviceToken flags set but doesn't have the fields" do
|
861
861
|
let(:packet) do
|
862
862
|
MQTT::Packet.parse(
|
863
863
|
"\x10\x16\x00\x06MQIsdp\x03\xC0\x00\x0a\x00\x08myclient"
|
864
864
|
)
|
865
865
|
end
|
866
866
|
|
867
|
-
it "should set the
|
868
|
-
expect(packet.
|
867
|
+
it "should set the Device ID of the packet correctly" do
|
868
|
+
expect(packet.deviceId).to be_nil
|
869
869
|
end
|
870
870
|
|
871
|
-
it "should set the
|
872
|
-
expect(packet.
|
871
|
+
it "should set the Device ID of the packet correctly" do
|
872
|
+
expect(packet.deviceToken).to be_nil
|
873
873
|
end
|
874
874
|
end
|
875
875
|
|
@@ -883,8 +883,8 @@ describe MQTT::Packet::Connect do
|
|
883
883
|
"\x00\x1712345678901234567890123"+ # client identifier (25)
|
884
884
|
"\x00\x0Awill_topic"+ # will topic (12)
|
885
885
|
"\x00\x0Cwill_message"+ # will message (14)
|
886
|
-
"\x00\x0Euser0123456789"+ #
|
887
|
-
"\x00\x0Epass0123456789" #
|
886
|
+
"\x00\x0Euser0123456789"+ # deviceId (16)
|
887
|
+
"\x00\x0Epass0123456789" # deviceToken (16)
|
888
888
|
)
|
889
889
|
end
|
890
890
|
|
@@ -936,14 +936,14 @@ describe MQTT::Packet::Connect do
|
|
936
936
|
expect(packet.will_payload.encoding.to_s).to eq('UTF-8')
|
937
937
|
end
|
938
938
|
|
939
|
-
it "should set the
|
940
|
-
expect(packet.
|
941
|
-
expect(packet.
|
939
|
+
it "should set the Device ID of the packet correctly" do
|
940
|
+
expect(packet.deviceId).to eq('user0123456789')
|
941
|
+
expect(packet.deviceId.encoding.to_s).to eq('UTF-8')
|
942
942
|
end
|
943
943
|
|
944
|
-
it "should set the
|
945
|
-
expect(packet.
|
946
|
-
expect(packet.
|
944
|
+
it "should set the Device ID of the packet correctly" do
|
945
|
+
expect(packet.deviceToken).to eq('pass0123456789')
|
946
|
+
expect(packet.deviceToken.encoding.to_s).to eq('UTF-8')
|
947
947
|
end
|
948
948
|
end
|
949
949
|
|
@@ -997,9 +997,9 @@ describe MQTT::Packet::Connect do
|
|
997
997
|
:keep_alive => 10,
|
998
998
|
:client_id => 'c123',
|
999
999
|
:clean_session => false,
|
1000
|
-
:
|
1000
|
+
:deviceId => 'foo'
|
1001
1001
|
)
|
1002
|
-
expect(packet.inspect).to eq("#<MQTT::Packet::Connect: keep_alive=10, client_id='c123',
|
1002
|
+
expect(packet.inspect).to eq("#<MQTT::Packet::Connect: keep_alive=10, client_id='c123', deviceId='foo'>")
|
1003
1003
|
end
|
1004
1004
|
end
|
1005
1005
|
|
@@ -1167,7 +1167,7 @@ describe MQTT::Packet::Connack do
|
|
1167
1167
|
end
|
1168
1168
|
|
1169
1169
|
it "should set the return message of the packet correctly" do
|
1170
|
-
expect(packet.return_msg).to match(/bad user name or
|
1170
|
+
expect(packet.return_msg).to match(/bad user name or deviceToken/i)
|
1171
1171
|
end
|
1172
1172
|
end
|
1173
1173
|
|