spec/mqtt_packet_spec.rb in qubitro-mqtt-0.0.6 vs spec/mqtt_packet_spec.rb in qubitro-mqtt-0.0.7
- old
+ new
@@ -539,23 +539,23 @@
"\x00\x08myclient"+
"\x00\x05topic\x00\x05hello"
)
end
- it "should output the correct bytes for a packet with a username and password" do
+ it "should output the correct bytes for a packet with a deviceId and deviceToken" do
packet = MQTT::Packet::Connect.new(
:client_id => 'myclient',
- :username => 'username',
- :password => 'password'
+ :deviceId => 'deviceId',
+ :deviceToken => 'deviceToken'
)
expect(packet.to_s).to eq(
"\x10\x2A"+
"\x00\x06MQIsdp"+
"\x03\xC2\x00\x0f"+
"\x00\x08myclient"+
- "\x00\x08username"+
- "\x00\x08password"
+ "\x00\x08deviceId"+
+ "\x00\x08deviceToken"
)
end
it "should output the correct bytes for a packet with everything" do
packet = MQTT::Packet::Connect.new(
@@ -564,24 +564,24 @@
:keep_alive => 65535,
:will_qos => 2,
:will_retain => true,
:will_topic => 'will_topic',
:will_payload => 'will_message',
- :username => 'user0123456789',
- :password => 'pass0123456789'
+ :deviceId => 'user0123456789',
+ :deviceToken => 'pass0123456789'
)
expect(packet.to_s).to eq(
"\x10\x5F"+ # fixed header (2)
"\x00\x06MQIsdp"+ # protocol name (8)
"\x03\xf6"+ # protocol level + flags (2)
"\xff\xff"+ # keep alive (2)
"\x00\x1712345678901234567890123"+ # client identifier (25)
"\x00\x0Awill_topic"+ # will topic (12)
"\x00\x0Cwill_message"+ # will message (14)
- "\x00\x0Euser0123456789"+ # username (16)
+ "\x00\x0Euser0123456789"+ # deviceId (16)
"\x00\x0Epass0123456789"
- ) # password (16)
+ ) # deviceToken (16)
end
context 'protocol version 3.1.1' do
it "should output the correct bytes for a packet with no flags" do
packet = MQTT::Packet::Connect.new( :version => '3.1.1', :client_id => 'myclient' )
@@ -641,16 +641,16 @@
it "should set not have the clean session flag set" do
expect(packet.clean_session).to be_falsey
end
- it "should set the the username field of the packet to nil" do
- expect(packet.username).to be_nil
+ it "should set the the deviceId field of the packet to nil" do
+ expect(packet.deviceId).to be_nil
end
- it "should set the the password field of the packet to nil" do
- expect(packet.password).to be_nil
+ it "should set the the deviceToken field of the packet to nil" do
+ expect(packet.deviceToken).to be_nil
end
end
describe "when parsing a simple 3.1.1 Connect packet" do
let(:packet) do
@@ -691,16 +691,16 @@
it "should set not have the clean session flag set" do
expect(packet.clean_session).to be_falsey
end
- it "should set the the username field of the packet to nil" do
- expect(packet.username).to be_nil
+ it "should set the the deviceId field of the packet to nil" do
+ expect(packet.deviceId).to be_nil
end
- it "should set the the password field of the packet to nil" do
- expect(packet.password).to be_nil
+ it "should set the the deviceToken field of the packet to nil" do
+ expect(packet.deviceToken).to be_nil
end
end
describe "when parsing a Connect packet with the clean session flag set" do
let(:packet) do
@@ -768,19 +768,19 @@
expect(packet.will_payload).to eq('hello')
expect(packet.will_payload.encoding.to_s).to eq('UTF-8')
end
end
- describe "when parsing a Connect packet with a username and password" do
+ describe "when parsing a Connect packet with a deviceId and deviceToken" do
let(:packet) do
MQTT::Packet.parse(
"\x10\x2A"+
"\x00\x06MQIsdp"+
"\x03\xC0\x00\x0a"+
"\x00\x08myclient"+
- "\x00\x08username"+
- "\x00\x08password"
+ "\x00\x08deviceId"+
+ "\x00\x08deviceToken"
)
end
it "should correctly create the right type of packet object" do
expect(packet.class).to eq(MQTT::Packet::Connect)
@@ -810,68 +810,68 @@
it "should set the Keep Alive Timer of the packet correctly" do
expect(packet.keep_alive).to eq(10)
end
- it "should set the Username of the packet correctly" do
- expect(packet.username).to eq('username')
- expect(packet.username.encoding.to_s).to eq('UTF-8')
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceId).to eq('deviceId')
+ expect(packet.deviceId.encoding.to_s).to eq('UTF-8')
end
- it "should set the Username of the packet correctly" do
- expect(packet.password).to eq('password')
- expect(packet.password.encoding.to_s).to eq('UTF-8')
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceToken).to eq('deviceToken')
+ expect(packet.deviceToken.encoding.to_s).to eq('UTF-8')
end
end
- describe "when parsing a Connect that has a username but no password" do
+ describe "when parsing a Connect that has a deviceId but no deviceToken" do
let(:packet) do
MQTT::Packet.parse(
- "\x10\x20\x00\x06MQIsdp\x03\x80\x00\x0a\x00\x08myclient\x00\x08username"
+ "\x10\x20\x00\x06MQIsdp\x03\x80\x00\x0a\x00\x08myclient\x00\x08deviceId"
)
end
- it "should set the Username of the packet correctly" do
- expect(packet.username).to eq('username')
- expect(packet.username.encoding.to_s).to eq('UTF-8')
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceId).to eq('deviceId')
+ expect(packet.deviceId.encoding.to_s).to eq('UTF-8')
end
- it "should set the Username of the packet correctly" do
- expect(packet.password).to be_nil
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceToken).to be_nil
end
end
- describe "when parsing a Connect that has a password but no username" do
+ describe "when parsing a Connect that has a deviceToken but no deviceId" do
let(:packet) do
MQTT::Packet.parse(
- "\x10\x20\x00\x06MQIsdp\x03\x40\x00\x0a\x00\x08myclient\x00\x08password"
+ "\x10\x20\x00\x06MQIsdp\x03\x40\x00\x0a\x00\x08myclient\x00\x08deviceToken"
)
end
- it "should set the Username of the packet correctly" do
- expect(packet.username).to be_nil
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceId).to be_nil
end
- it "should set the Username of the packet correctly" do
- expect(packet.password).to eq('password')
- expect(packet.password.encoding.to_s).to eq('UTF-8')
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceToken).to eq('deviceToken')
+ expect(packet.deviceToken.encoding.to_s).to eq('UTF-8')
end
end
- describe "when parsing a Connect packet has the username and password flags set but doesn't have the fields" do
+ describe "when parsing a Connect packet has the deviceId and deviceToken flags set but doesn't have the fields" do
let(:packet) do
MQTT::Packet.parse(
"\x10\x16\x00\x06MQIsdp\x03\xC0\x00\x0a\x00\x08myclient"
)
end
- it "should set the Username of the packet correctly" do
- expect(packet.username).to be_nil
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceId).to be_nil
end
- it "should set the Username of the packet correctly" do
- expect(packet.password).to be_nil
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceToken).to be_nil
end
end
describe "when parsing a Connect packet with every option set" do
let(:packet) do
@@ -881,12 +881,12 @@
"\x03\xf6"+ # protocol level + flags (2)
"\xff\xff"+ # keep alive (2)
"\x00\x1712345678901234567890123"+ # client identifier (25)
"\x00\x0Awill_topic"+ # will topic (12)
"\x00\x0Cwill_message"+ # will message (14)
- "\x00\x0Euser0123456789"+ # username (16)
- "\x00\x0Epass0123456789" # password (16)
+ "\x00\x0Euser0123456789"+ # deviceId (16)
+ "\x00\x0Epass0123456789" # deviceToken (16)
)
end
it "should correctly create the right type of packet object" do
expect(packet.class).to eq(MQTT::Packet::Connect)
@@ -934,18 +934,18 @@
it "should set the Will payload of the packet correctly" do
expect(packet.will_payload).to eq('will_message')
expect(packet.will_payload.encoding.to_s).to eq('UTF-8')
end
- it "should set the Username of the packet correctly" do
- expect(packet.username).to eq('user0123456789')
- expect(packet.username.encoding.to_s).to eq('UTF-8')
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceId).to eq('user0123456789')
+ expect(packet.deviceId.encoding.to_s).to eq('UTF-8')
end
- it "should set the Username of the packet correctly" do
- expect(packet.password).to eq('pass0123456789')
- expect(packet.password.encoding.to_s).to eq('UTF-8')
+ it "should set the Device ID of the packet correctly" do
+ expect(packet.deviceToken).to eq('pass0123456789')
+ expect(packet.deviceToken.encoding.to_s).to eq('UTF-8')
end
end
describe "when parsing packet with an unknown protocol name" do
it "should raise a protocol exception" do
@@ -995,13 +995,13 @@
it "should output correct string when parameters are given" do
packet = MQTT::Packet::Connect.new(
:keep_alive => 10,
:client_id => 'c123',
:clean_session => false,
- :username => 'foo'
+ :deviceId => 'foo'
)
- expect(packet.inspect).to eq("#<MQTT::Packet::Connect: keep_alive=10, client_id='c123', username='foo'>")
+ expect(packet.inspect).to eq("#<MQTT::Packet::Connect: keep_alive=10, client_id='c123', deviceId='foo'>")
end
end
describe "deprecated attributes" do
it "should still have a protocol_version method that is that same as protocol_level" do
@@ -1165,10 +1165,10 @@
it "should set the return code of the packet correctly" do
expect(packet.return_code).to eq(0x04)
end
it "should set the return message of the packet correctly" do
- expect(packet.return_msg).to match(/bad user name or password/i)
+ expect(packet.return_msg).to match(/bad user name or deviceToken/i)
end
end
describe "when parsing a server unavailable packet" do
let(:packet) do