ably-rest 0.8.15 → 0.9.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 +4 -4
- data/lib/submodules/ably-ruby/CHANGELOG.md +61 -48
- data/lib/submodules/ably-ruby/README.md +0 -6
- data/lib/submodules/ably-ruby/ably.gemspec +1 -1
- data/lib/submodules/ably-ruby/lib/ably/auth.rb +37 -32
- data/lib/submodules/ably-ruby/lib/ably/modules/event_emitter.rb +15 -30
- data/lib/submodules/ably-ruby/lib/ably/modules/model_common.rb +0 -25
- data/lib/submodules/ably-ruby/lib/ably/realtime/auth.rb +30 -18
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +3 -3
- data/lib/submodules/ably-ruby/lib/ably/realtime/client.rb +0 -3
- data/lib/submodules/ably-ruby/lib/ably/realtime/client/incoming_message_dispatcher.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection/connection_manager.rb +3 -3
- data/lib/submodules/ably-ruby/lib/ably/realtime/presence/members_map.rb +3 -3
- data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +6 -6
- data/lib/submodules/ably-ruby/lib/ably/version.rb +2 -2
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/auth_spec.rb +66 -53
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb +8 -10
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/client_spec.rb +3 -3
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +12 -48
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +38 -79
- data/lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb +74 -40
- data/lib/submodules/ably-ruby/spec/acceptance/rest/base_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +4 -2
- data/lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb +21 -26
- data/lib/submodules/ably-ruby/spec/acceptance/rest/presence_spec.rb +12 -10
- data/lib/submodules/ably-ruby/spec/unit/modules/event_emitter_spec.rb +51 -109
- data/lib/submodules/ably-ruby/spec/unit/realtime/presence_spec.rb +3 -3
- metadata +4 -3
@@ -92,14 +92,12 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
92
92
|
|
93
93
|
it 'reattaches' do
|
94
94
|
channel.attach do
|
95
|
-
channel.once(:failed) do
|
96
|
-
expect(channel).to be_failed
|
97
|
-
channel.attach do
|
98
|
-
expect(channel).to be_attached
|
99
|
-
stop_reactor
|
100
|
-
end
|
101
|
-
end
|
102
95
|
channel.transition_state_machine :failed, reason: RuntimeError.new
|
96
|
+
expect(channel).to be_failed
|
97
|
+
channel.attach do
|
98
|
+
expect(channel).to be_attached
|
99
|
+
stop_reactor
|
100
|
+
end
|
103
101
|
end
|
104
102
|
end
|
105
103
|
end
|
@@ -193,8 +191,8 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
193
191
|
restricted_channel.attach
|
194
192
|
restricted_channel.once(:failed) do
|
195
193
|
restricted_client.close do
|
196
|
-
# A direct call to #
|
197
|
-
restricted_client.auth.
|
194
|
+
# A direct call to #authorize is synchronous
|
195
|
+
restricted_client.auth.authorize({}, key: api_key)
|
198
196
|
|
199
197
|
restricted_client.connect do
|
200
198
|
restricted_channel.once(:attached) do
|
@@ -373,7 +371,7 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
373
371
|
expect(message_id.uniq.count).to eql(1)
|
374
372
|
|
375
373
|
# Check that messages use index 0,1,2 in the ID
|
376
|
-
message_indexes = messages.map { |msg| msg.id.split(':')
|
374
|
+
message_indexes = messages.map { |msg| msg.id.split(':')[1] }
|
377
375
|
expect(message_indexes).to include("0", "1", "2")
|
378
376
|
stop_reactor
|
379
377
|
end
|
@@ -62,7 +62,7 @@ describe Ably::Realtime::Client, :event_machine do
|
|
62
62
|
context 'with valid :key and :use_token_auth option set to true' do
|
63
63
|
let(:client_options) { default_options.merge(use_token_auth: true) }
|
64
64
|
|
65
|
-
it 'automatically
|
65
|
+
it 'automatically authorizes on connect and generates a token' do
|
66
66
|
connection.on(:connected) do
|
67
67
|
expect(subject.auth.current_token_details).to_not be_nil
|
68
68
|
expect(auth_params[:access_token]).to_not be_nil
|
@@ -116,7 +116,7 @@ describe Ably::Realtime::Client, :event_machine do
|
|
116
116
|
|
117
117
|
context 'when the returned token has a client_id' do
|
118
118
|
it "sets Auth#client_id to the new token's client_id immediately when connecting" do
|
119
|
-
subject.auth.
|
119
|
+
subject.auth.authorize do
|
120
120
|
expect(subject.connection).to be_connecting
|
121
121
|
expect(subject.auth.client_id).to eql(client_id)
|
122
122
|
stop_reactor
|
@@ -124,7 +124,7 @@ describe Ably::Realtime::Client, :event_machine do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
it "sets Client#client_id to the new token's client_id immediately when connecting" do
|
127
|
-
subject.auth.
|
127
|
+
subject.auth.authorize do
|
128
128
|
expect(subject.connection).to be_connecting
|
129
129
|
expect(subject.client_id).to eql(client_id)
|
130
130
|
stop_reactor
|
@@ -60,9 +60,9 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
60
60
|
|
61
61
|
context 'for renewable tokens' do
|
62
62
|
context 'that are valid for the duration of the test' do
|
63
|
-
context 'with valid pre
|
63
|
+
context 'with valid pre authorized token expiring in the future' do
|
64
64
|
it 'uses the existing token created by Auth' do
|
65
|
-
client.auth.
|
65
|
+
client.auth.authorize(ttl: 300)
|
66
66
|
expect(client.auth).to_not receive(:request_token)
|
67
67
|
connection.once(:connected) do
|
68
68
|
stop_reactor
|
@@ -101,8 +101,8 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
101
101
|
context 'opening a new connection' do
|
102
102
|
context 'with almost expired tokens' do
|
103
103
|
before do
|
104
|
-
#
|
105
|
-
client.auth.
|
104
|
+
# Authorize synchronously to ensure token has been issued
|
105
|
+
client.auth.authorize_sync(ttl: ttl)
|
106
106
|
end
|
107
107
|
|
108
108
|
let(:ttl) { 2 }
|
@@ -615,23 +615,16 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
615
615
|
end
|
616
616
|
end
|
617
617
|
|
618
|
-
it 'is set to 0 when a message is received
|
619
|
-
channel.publish('event', 'data')
|
620
|
-
channel.subscribe do
|
618
|
+
it 'is set to 0 when a message sent ACK is received' do
|
619
|
+
channel.publish('event', 'data') do
|
621
620
|
expect(connection.serial).to eql(0)
|
622
621
|
stop_reactor
|
623
622
|
end
|
624
623
|
end
|
625
624
|
|
626
|
-
it 'is set to 1 when the second message is received' do
|
625
|
+
it 'is set to 1 when the second message sent ACK is received' do
|
627
626
|
channel.publish('event', 'data') do
|
628
|
-
channel.publish('event', 'data')
|
629
|
-
end
|
630
|
-
|
631
|
-
messages = []
|
632
|
-
channel.subscribe do |message|
|
633
|
-
messages << message
|
634
|
-
if messages.length == 2
|
627
|
+
channel.publish('event', 'data') do
|
635
628
|
expect(connection.serial).to eql(1)
|
636
629
|
stop_reactor
|
637
630
|
end
|
@@ -891,16 +884,11 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
891
884
|
expect(connection.serial).to eql(expected_serial)
|
892
885
|
|
893
886
|
channel.attach do
|
894
|
-
channel.publish('event', 'data')
|
895
|
-
channel.subscribe do
|
896
|
-
channel.unsubscribe
|
897
|
-
|
887
|
+
channel.publish('event', 'data') do
|
898
888
|
expected_serial += 1 # attach message received
|
899
889
|
expect(connection.serial).to eql(expected_serial)
|
900
890
|
|
901
|
-
channel.publish('event', 'data')
|
902
|
-
channel.subscribe do
|
903
|
-
channel.unsubscribe
|
891
|
+
channel.publish('event', 'data') do
|
904
892
|
expected_serial += 1 # attach message received
|
905
893
|
expect(connection.serial).to eql(expected_serial)
|
906
894
|
|
@@ -1290,22 +1278,6 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
1290
1278
|
end
|
1291
1279
|
|
1292
1280
|
context 'connection state change' do
|
1293
|
-
# See https://github.com/ably/ably-ruby/issues/103
|
1294
|
-
it 'emits event to all and single subscribers' do
|
1295
|
-
connected_emitted = []
|
1296
|
-
block = Proc.new do |state_change|
|
1297
|
-
if state_change.current == :connected
|
1298
|
-
connected_emitted << state_change
|
1299
|
-
EventMachine.add_timer(0.5) do
|
1300
|
-
expect(connected_emitted.length).to eql(2)
|
1301
|
-
stop_reactor
|
1302
|
-
end
|
1303
|
-
end
|
1304
|
-
end
|
1305
|
-
connection.on(&block)
|
1306
|
-
connection.on(:connected, &block)
|
1307
|
-
end
|
1308
|
-
|
1309
1281
|
it 'emits a ConnectionStateChange object' do
|
1310
1282
|
connection.on(:connected) do |connection_state_change|
|
1311
1283
|
expect(connection_state_change).to be_a(Ably::Models::ConnectionStateChange)
|
@@ -1314,14 +1286,6 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
1314
1286
|
end
|
1315
1287
|
|
1316
1288
|
context 'ConnectionStateChange object' do
|
1317
|
-
def unbind
|
1318
|
-
if connection.transport
|
1319
|
-
connection.transport.unbind
|
1320
|
-
else
|
1321
|
-
EventMachine.add_timer(0.005) { unbind }
|
1322
|
-
end
|
1323
|
-
end
|
1324
|
-
|
1325
1289
|
it 'has current state' do
|
1326
1290
|
connection.on(:connected) do |connection_state_change|
|
1327
1291
|
expect(connection_state_change.current).to eq(:connected)
|
@@ -1385,7 +1349,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
1385
1349
|
expect(connection_state_change.retry_in).to eql(0)
|
1386
1350
|
stop_reactor
|
1387
1351
|
end
|
1388
|
-
unbind
|
1352
|
+
EventMachine.add_timer(0.005) { connection.transport.unbind }
|
1389
1353
|
end
|
1390
1354
|
end
|
1391
1355
|
|
@@ -1406,7 +1370,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
1406
1370
|
expect(connection_state_change.retry_in).to be > 0
|
1407
1371
|
stop_reactor
|
1408
1372
|
end
|
1409
|
-
unbind
|
1373
|
+
EventMachine.add_timer(0.005) { connection.transport.unbind }
|
1410
1374
|
end
|
1411
1375
|
connection.transport.unbind
|
1412
1376
|
end
|
@@ -42,11 +42,9 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
42
42
|
|
43
43
|
def setup_test(method_name, args, options)
|
44
44
|
if options[:enter_first]
|
45
|
-
presence_client_one.
|
46
|
-
presence_client_one.unsubscribe
|
45
|
+
presence_client_one.public_send(method_name.to_s.gsub(/leave|update/, 'enter'), args) do
|
47
46
|
yield
|
48
47
|
end
|
49
|
-
presence_client_one.public_send(method_name.to_s.gsub(/leave|update/, 'enter'), args)
|
50
48
|
else
|
51
49
|
yield
|
52
50
|
end
|
@@ -470,14 +468,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
470
468
|
|
471
469
|
context 'once server sync is complete' do
|
472
470
|
it 'behaves like an Enumerable allowing direct access to current members' do
|
473
|
-
presence_client_one.enter
|
474
|
-
presence_client_two.enter
|
475
|
-
|
476
|
-
entered = 0
|
477
|
-
presence_client_one.subscribe(:enter) do
|
478
|
-
entered += 1
|
479
|
-
next unless entered == 2
|
480
|
-
|
471
|
+
when_all(presence_client_one.enter, presence_client_two.enter) do
|
481
472
|
presence_anonymous_client.members.once(:in_sync) do
|
482
473
|
expect(presence_anonymous_client.members.count).to eql(2)
|
483
474
|
member_ids = presence_anonymous_client.members.map(&:member_key)
|
@@ -504,10 +495,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
504
495
|
|
505
496
|
context 'when attaching to a channel with members present' do
|
506
497
|
it 'is false and the presence channel will subsequently be synced' do
|
507
|
-
presence_client_one.enter
|
508
|
-
presence_client_one.subscribe(:enter) do
|
509
|
-
presence_client_one.unsubscribe :enter
|
510
|
-
|
498
|
+
presence_client_one.enter do
|
511
499
|
channel_anonymous_client.attach do
|
512
500
|
expect(channel_anonymous_client.presence).to_not be_sync_complete
|
513
501
|
channel_anonymous_client.presence.get(wait_for_sync: true) do
|
@@ -692,18 +680,16 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
692
680
|
it 'waits until sync is complete', em_timeout: 30 do # allow for slow connections and lots of messages
|
693
681
|
enter_expected_count.times do |index|
|
694
682
|
EventMachine.add_timer(index / 10) do
|
695
|
-
presence_client_one.enter_client("client:#{index}")
|
696
|
-
|
697
|
-
|
683
|
+
presence_client_one.enter_client("client:#{index}") do |message|
|
684
|
+
entered << message
|
685
|
+
next unless entered.count == enter_expected_count
|
698
686
|
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
expect(members.count).to eql(enter_expected_count)
|
706
|
-
stop_reactor
|
687
|
+
presence_anonymous_client.get(wait_for_sync: true) do |members|
|
688
|
+
expect(members.map(&:client_id).uniq.count).to eql(enter_expected_count)
|
689
|
+
expect(members.count).to eql(enter_expected_count)
|
690
|
+
stop_reactor
|
691
|
+
end
|
692
|
+
end
|
707
693
|
end
|
708
694
|
end
|
709
695
|
end
|
@@ -711,21 +697,19 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
711
697
|
|
712
698
|
context 'by default' do
|
713
699
|
it 'it does not wait for sync', em_timeout: 30 do # allow for slow connections and lots of messages
|
714
|
-
enter_expected_count.times do |
|
715
|
-
EventMachine.add_timer(
|
716
|
-
presence_client_one.enter_client
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
expect(members.count).to eql(0)
|
728
|
-
stop_reactor
|
700
|
+
enter_expected_count.times do |index|
|
701
|
+
EventMachine.add_timer(index / 10) do
|
702
|
+
presence_client_one.enter_client("client:#{index}") do |message|
|
703
|
+
entered << message
|
704
|
+
next unless entered.count == enter_expected_count
|
705
|
+
|
706
|
+
channel_anonymous_client.attach do
|
707
|
+
presence_anonymous_client.get do |members|
|
708
|
+
expect(presence_anonymous_client.members).to_not be_in_sync
|
709
|
+
expect(members.count).to eql(0)
|
710
|
+
stop_reactor
|
711
|
+
end
|
712
|
+
end
|
729
713
|
end
|
730
714
|
end
|
731
715
|
end
|
@@ -912,25 +896,15 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
912
896
|
|
913
897
|
context 'and sync is complete' do
|
914
898
|
it 'does not cache members that have left' do
|
915
|
-
|
916
|
-
|
917
|
-
presence_client_one.subscribe(:enter) do
|
918
|
-
presence_client_one.unsubscribe :enter
|
919
|
-
|
899
|
+
presence_client_one.enter enter_data do
|
920
900
|
expect(presence_client_one.members).to be_in_sync
|
921
901
|
expect(presence_client_one.members.send(:members).count).to eql(1)
|
922
902
|
presence_client_one.leave data
|
923
903
|
end
|
924
904
|
|
925
|
-
presence_client_one.enter(enter_data) do
|
926
|
-
enter_ack = true
|
927
|
-
end
|
928
|
-
|
929
905
|
presence_client_one.subscribe(:leave) do |presence_message|
|
930
|
-
presence_client_one.unsubscribe :leave
|
931
906
|
expect(presence_message.data).to eql(data)
|
932
907
|
expect(presence_client_one.members.send(:members).count).to eql(0)
|
933
|
-
expect(enter_ack).to eql(true)
|
934
908
|
stop_reactor
|
935
909
|
end
|
936
910
|
end
|
@@ -1316,9 +1290,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1316
1290
|
# skip 'it fails if the connection changes to failed state'
|
1317
1291
|
|
1318
1292
|
it 'returns the current members on the channel' do
|
1319
|
-
presence_client_one.enter
|
1320
|
-
presence_client_one.subscribe(:enter) do
|
1321
|
-
presence_client_one.unsubscribe :enter
|
1293
|
+
presence_client_one.enter do
|
1322
1294
|
presence_client_one.get do |members|
|
1323
1295
|
expect(members.count).to eq(1)
|
1324
1296
|
|
@@ -1379,10 +1351,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1379
1351
|
end
|
1380
1352
|
|
1381
1353
|
it 'does not wait for SYNC to complete if :wait_for_sync option is false' do
|
1382
|
-
presence_client_one.enter
|
1383
|
-
presence_client_one.subscribe(:enter) do
|
1384
|
-
presence_client_one.unsubscribe :enter
|
1385
|
-
|
1354
|
+
presence_client_one.enter do
|
1386
1355
|
presence_client_two.get(wait_for_sync: false) do |members|
|
1387
1356
|
expect(members.count).to eql(0)
|
1388
1357
|
stop_reactor
|
@@ -1393,13 +1362,11 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1393
1362
|
context 'when a member enters and then leaves' do
|
1394
1363
|
it 'has no members' do
|
1395
1364
|
presence_client_one.enter do
|
1396
|
-
presence_client_one.leave
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
expect(members.count).to eq(0)
|
1402
|
-
stop_reactor
|
1365
|
+
presence_client_one.leave do
|
1366
|
+
presence_client_one.get do |members|
|
1367
|
+
expect(members.count).to eq(0)
|
1368
|
+
stop_reactor
|
1369
|
+
end
|
1403
1370
|
end
|
1404
1371
|
end
|
1405
1372
|
end
|
@@ -1557,10 +1524,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1557
1524
|
|
1558
1525
|
context 'REST #get' do
|
1559
1526
|
it 'returns current members' do
|
1560
|
-
presence_client_one.enter
|
1561
|
-
presence_client_one.subscribe(:enter) do
|
1562
|
-
presence_client_one.unsubscribe :enter
|
1563
|
-
|
1527
|
+
presence_client_one.enter(data_payload) do
|
1564
1528
|
members_page = channel_rest_client_one.presence.get
|
1565
1529
|
this_member = members_page.items.first
|
1566
1530
|
|
@@ -1574,10 +1538,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1574
1538
|
|
1575
1539
|
it 'returns no members once left' do
|
1576
1540
|
presence_client_one.enter(data_payload) do
|
1577
|
-
presence_client_one.leave
|
1578
|
-
presence_client_one.subscribe(:leave) do
|
1579
|
-
presence_client_one.unsubscribe :leave
|
1580
|
-
|
1541
|
+
presence_client_one.leave do
|
1581
1542
|
members_page = channel_rest_client_one.presence.get
|
1582
1543
|
expect(members_page.items.count).to eql(0)
|
1583
1544
|
stop_reactor
|
@@ -1693,8 +1654,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1693
1654
|
|
1694
1655
|
context '#get' do
|
1695
1656
|
it 'returns a list of members with decrypted data' do
|
1696
|
-
encrypted_channel.presence.enter(data)
|
1697
|
-
encrypted_channel.presence.subscribe(:enter) do
|
1657
|
+
encrypted_channel.presence.enter(data) do
|
1698
1658
|
encrypted_channel.presence.get do |members|
|
1699
1659
|
member = members.first
|
1700
1660
|
expect(member.encoding).to be_nil
|
@@ -1707,8 +1667,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1707
1667
|
|
1708
1668
|
context 'REST #get' do
|
1709
1669
|
it 'returns a list of members with decrypted data' do
|
1710
|
-
encrypted_channel.presence.enter(data)
|
1711
|
-
encrypted_channel.presence.subscribe(:enter) do
|
1670
|
+
encrypted_channel.presence.enter(data) do
|
1712
1671
|
member = channel_rest_client_one.presence.get.items.first
|
1713
1672
|
expect(member.encoding).to be_nil
|
1714
1673
|
expect(member.data).to eql(data)
|
@@ -1779,7 +1738,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1779
1738
|
context 'connection failure mid-way through a large member sync' do
|
1780
1739
|
let(:members_count) { 250 }
|
1781
1740
|
let(:sync_pages_received) { [] }
|
1782
|
-
let(:client_options) { default_options.merge(log_level: :
|
1741
|
+
let(:client_options) { default_options.merge(log_level: :error) }
|
1783
1742
|
|
1784
1743
|
it 'resumes the SYNC operation', em_timeout: 15 do
|
1785
1744
|
when_all(*members_count.times.map do |index|
|
@@ -445,8 +445,8 @@ describe Ably::Auth do
|
|
445
445
|
expect(request_token.client_id).to eql(client_id)
|
446
446
|
end
|
447
447
|
|
448
|
-
context 'when
|
449
|
-
before { auth.
|
448
|
+
context 'when authorized' do
|
449
|
+
before { auth.authorize(token_params, auth_callback: auth_callback) }
|
450
450
|
|
451
451
|
it "sets Auth#client_id to the new token's client_id" do
|
452
452
|
expect(auth.client_id).to eql(client_id)
|
@@ -500,8 +500,8 @@ describe Ably::Auth do
|
|
500
500
|
expect(token_details.capability).to eql(capability)
|
501
501
|
end
|
502
502
|
|
503
|
-
context 'when
|
504
|
-
before { auth.
|
503
|
+
context 'when authorized' do
|
504
|
+
before { auth.authorize(token_params, auth_callback: auth_callback) }
|
505
505
|
|
506
506
|
it "sets Auth#client_id to the new token's client_id" do
|
507
507
|
expect(auth.client_id).to eql(client_id)
|
@@ -583,13 +583,13 @@ describe Ably::Auth do
|
|
583
583
|
end
|
584
584
|
end
|
585
585
|
|
586
|
-
context 'before #
|
586
|
+
context 'before #authorize has been called' do
|
587
587
|
it 'has no current_token_details' do
|
588
588
|
expect(auth.current_token_details).to be_nil
|
589
589
|
end
|
590
590
|
end
|
591
591
|
|
592
|
-
describe '#
|
592
|
+
describe '#authorize (#RSA10, #RSA10j)' do
|
593
593
|
context 'when called for the first time since the client has been instantiated' do
|
594
594
|
let(:auth_options) do
|
595
595
|
{ auth_url: 'http://somewhere.com/' }
|
@@ -600,15 +600,15 @@ describe Ably::Auth do
|
|
600
600
|
|
601
601
|
it 'passes all auth_options and token_params to #request_token' do
|
602
602
|
expect(auth).to receive(:request_token).with(token_params, auth_options)
|
603
|
-
auth.
|
603
|
+
auth.authorize token_params, auth_options
|
604
604
|
end
|
605
605
|
|
606
606
|
it 'returns a valid token' do
|
607
|
-
expect(auth.
|
607
|
+
expect(auth.authorize).to be_a(Ably::Models::TokenDetails)
|
608
608
|
end
|
609
609
|
|
610
|
-
it 'issues a new token
|
611
|
-
expect { auth.
|
610
|
+
it 'issues a new token every time (#RSA10a)' do
|
611
|
+
expect { auth.authorize }.to change { auth.current_token_details }
|
612
612
|
end
|
613
613
|
end
|
614
614
|
|
@@ -624,8 +624,8 @@ describe Ably::Auth do
|
|
624
624
|
it 'only queries the server time once and then works out the offset, query_time option is never persisted' do
|
625
625
|
expect(client).to receive(:time).once.and_return(server_time)
|
626
626
|
|
627
|
-
auth.
|
628
|
-
auth.
|
627
|
+
auth.authorize({}, query_time: true)
|
628
|
+
auth.authorize({})
|
629
629
|
expect(auth.auth_options).to_not have_key(:query_time)
|
630
630
|
end
|
631
631
|
end
|
@@ -634,26 +634,26 @@ describe Ably::Auth do
|
|
634
634
|
let(:default_token_params) { { ttl: 23 } }
|
635
635
|
|
636
636
|
before do
|
637
|
-
auth.
|
637
|
+
auth.authorize default_token_params
|
638
638
|
end
|
639
639
|
|
640
640
|
it 'has no effect on the defaults when null and TokenParam defaults remain the same' do
|
641
641
|
old_token = auth.current_token_details
|
642
|
-
auth.
|
642
|
+
auth.authorize
|
643
643
|
expect(old_token).to_not eql(auth.current_token_details)
|
644
644
|
expect(auth.token_params[:ttl]).to eql(23)
|
645
645
|
end
|
646
646
|
|
647
647
|
it 'updates defaults when present and all previous configured TokenParams are discarded' do
|
648
648
|
old_token = auth.current_token_details
|
649
|
-
auth.
|
649
|
+
auth.authorize({ client_id: 'bob' })
|
650
650
|
expect(old_token).to_not eql(auth.current_token_details)
|
651
651
|
expect(auth.token_params[:ttl]).to_not eql(23)
|
652
652
|
expect(auth.token_params[:client_id]).to eql('bob')
|
653
653
|
end
|
654
654
|
|
655
655
|
it 'updates Auth#token_params attribute with an immutable hash' do
|
656
|
-
auth.
|
656
|
+
auth.authorize({ client_id: 'bob' })
|
657
657
|
expect { auth.token_params['key_name'] = 'new_name' }.to raise_error RuntimeError, /can't modify frozen.*Hash/
|
658
658
|
end
|
659
659
|
end
|
@@ -669,68 +669,63 @@ describe Ably::Auth do
|
|
669
669
|
stub_const 'Ably::Models::TokenDetails::TOKEN_EXPIRY_BUFFER', 0 # allow token to be used even if about to expire
|
670
670
|
stub_const 'Ably::Auth::TOKEN_DEFAULTS', Ably::Auth::TOKEN_DEFAULTS.merge(renew_token_buffer: 0) # Ensure tokens issued expire immediately after issue
|
671
671
|
|
672
|
-
auth.
|
672
|
+
auth.authorize(nil, default_auth_options)
|
673
673
|
@old_token = auth.current_token_details
|
674
674
|
sleep token_ttl + 0.5
|
675
675
|
end
|
676
676
|
|
677
677
|
it 'has no effect on the defaults when null and AuthOptions defaults remain the same' do
|
678
|
-
auth.
|
678
|
+
auth.authorize(nil, nil)
|
679
679
|
expect(@old_token).to_not eql(auth.current_token_details)
|
680
680
|
expect(auth.options[:auth_callback]).to eql(auth_callback)
|
681
681
|
end
|
682
682
|
|
683
683
|
it 'updates defaults when present and all previous configured AuthOptions are discarded' do
|
684
|
-
auth.
|
684
|
+
auth.authorize(nil, auth_method: :post)
|
685
685
|
expect(@old_token).to_not eql(auth.current_token_details)
|
686
686
|
expect(auth.options[:auth_callback]).to be_nil
|
687
687
|
expect(auth.options[:auth_method]).to eql(:post)
|
688
688
|
end
|
689
689
|
|
690
690
|
it 'updates Auth#options attribute with an immutable hash' do
|
691
|
-
auth.
|
691
|
+
auth.authorize(nil, auth_callback: Proc.new { '1231232.12321:12321312' })
|
692
692
|
expect { auth.options['key_name'] = 'new_name' }.to raise_error RuntimeError, /can't modify frozen.*Hash/
|
693
693
|
end
|
694
694
|
end
|
695
695
|
|
696
696
|
context 'with previous authorisation' do
|
697
697
|
before do
|
698
|
-
auth.
|
698
|
+
auth.authorize
|
699
699
|
expect(auth.current_token_details).to_not be_expired
|
700
700
|
end
|
701
701
|
|
702
|
-
it 'does not request a token if current_token_details has not expired' do
|
703
|
-
expect(auth).to_not receive(:request_token)
|
704
|
-
auth.authorise
|
705
|
-
end
|
706
|
-
|
707
702
|
it 'requests a new token if token is expired' do
|
708
703
|
allow(auth.current_token_details).to receive(:expired?).and_return(true)
|
709
704
|
expect(auth).to receive(:request_token)
|
710
|
-
expect { auth.
|
705
|
+
expect { auth.authorize }.to change { auth.current_token_details }
|
711
706
|
end
|
712
707
|
|
713
|
-
it 'issues a new token
|
714
|
-
expect { auth.
|
708
|
+
it 'issues a new token every time #authorize is called' do
|
709
|
+
expect { auth.authorize({}) }.to change { auth.current_token_details }
|
715
710
|
end
|
716
711
|
end
|
717
712
|
|
718
|
-
it 'updates the persisted token params that are then used for subsequent
|
713
|
+
it 'updates the persisted token params that are then used for subsequent authorize requests' do
|
719
714
|
expect(auth.token_params[:ttl]).to_not eql(26)
|
720
|
-
auth.
|
715
|
+
auth.authorize(ttl: 26)
|
721
716
|
expect(auth.token_params[:ttl]).to eql(26)
|
722
717
|
end
|
723
718
|
|
724
|
-
it 'updates the persisted auth options that are then used for subsequent
|
719
|
+
it 'updates the persisted auth options that are then used for subsequent authorize requests' do
|
725
720
|
expect(auth.options[:authUrl]).to be_nil
|
726
|
-
auth.
|
721
|
+
auth.authorize({}, authUrl: 'http://foo.com')
|
727
722
|
expect(auth.options[:authUrl]).to eql('http://foo.com')
|
728
723
|
end
|
729
724
|
|
730
725
|
context 'with a Proc for the :auth_callback option' do
|
731
726
|
let(:client_id) { random_str }
|
732
727
|
let!(:token) do
|
733
|
-
auth.
|
728
|
+
auth.authorize({}, auth_callback: Proc.new do
|
734
729
|
@block_called ||= 0
|
735
730
|
@block_called += 1
|
736
731
|
auth.create_token_request(client_id: client_id)
|
@@ -800,7 +795,7 @@ describe Ably::Auth do
|
|
800
795
|
let(:auth_token_object) { auth_client.auth.request_token }
|
801
796
|
|
802
797
|
it 'rejects a TokenDetails object with an incompatible client_id and raises an exception' do
|
803
|
-
expect { client.auth.
|
798
|
+
expect { client.auth.authorize({}) }.to raise_error Ably::Exceptions::IncompatibleClientId
|
804
799
|
end
|
805
800
|
end
|
806
801
|
|
@@ -808,7 +803,7 @@ describe Ably::Auth do
|
|
808
803
|
let(:auth_token_object) { auth_client.auth.create_token_request }
|
809
804
|
|
810
805
|
it 'rejects a TokenRequests object with an incompatible client_id and raises an exception' do
|
811
|
-
expect { client.auth.
|
806
|
+
expect { client.auth.authorize({}) }.to raise_error Ably::Exceptions::IncompatibleClientId
|
812
807
|
end
|
813
808
|
end
|
814
809
|
|
@@ -816,7 +811,7 @@ describe Ably::Auth do
|
|
816
811
|
let(:auth_token_object) { auth_client.auth.request_token(client_id: 'different').token }
|
817
812
|
|
818
813
|
it 'rejects a TokenRequests object with an incompatible client_id and raises an exception' do
|
819
|
-
client.auth.
|
814
|
+
client.auth.authorize({})
|
820
815
|
expect(client.client_id).to eql(client_id)
|
821
816
|
end
|
822
817
|
end
|
@@ -838,7 +833,7 @@ describe Ably::Auth do
|
|
838
833
|
auth_callback = Proc.new { subject }
|
839
834
|
client_without_api_key = Ably::Rest::Client.new(default_options.merge(auth_callback: auth_callback))
|
840
835
|
expect(client_without_api_key.auth).to be_using_token_auth
|
841
|
-
expect { client_without_api_key.auth.
|
836
|
+
expect { client_without_api_key.auth.authorize }.to_not raise_error
|
842
837
|
end
|
843
838
|
|
844
839
|
it 'uses the key name from the client' do
|
@@ -897,7 +892,7 @@ describe Ably::Auth do
|
|
897
892
|
it 'uses these capabilities when Ably issues an actual token' do
|
898
893
|
auth_callback = Proc.new { subject }
|
899
894
|
client_without_api_key = Ably::Rest::Client.new(default_options.merge(auth_callback: auth_callback))
|
900
|
-
client_without_api_key.auth.
|
895
|
+
client_without_api_key.auth.authorize
|
901
896
|
expect(client_without_api_key.auth.current_token_details.capability).to eql(capability)
|
902
897
|
end
|
903
898
|
end
|
@@ -1008,7 +1003,7 @@ describe Ably::Auth do
|
|
1008
1003
|
auth.create_token_request(token_attributes)
|
1009
1004
|
end
|
1010
1005
|
client = Ably::Rest::Client.new(auth_callback: auth_callback, environment: environment, protocol: protocol)
|
1011
|
-
client.auth.
|
1006
|
+
client.auth.authorize
|
1012
1007
|
end
|
1013
1008
|
end
|
1014
1009
|
end
|
@@ -1202,5 +1197,44 @@ describe Ably::Auth do
|
|
1202
1197
|
expect(auth).to be_using_basic_auth
|
1203
1198
|
end
|
1204
1199
|
end
|
1200
|
+
|
1201
|
+
context 'deprecated #authorise' do
|
1202
|
+
let(:client_options) { default_options.merge(key: api_key, logger: custom_logger_object) }
|
1203
|
+
let(:custom_logger) do
|
1204
|
+
Class.new do
|
1205
|
+
def initialize
|
1206
|
+
@messages = []
|
1207
|
+
end
|
1208
|
+
|
1209
|
+
[:fatal, :error, :warn, :info, :debug].each do |severity|
|
1210
|
+
define_method severity do |message|
|
1211
|
+
@messages << [severity, message]
|
1212
|
+
end
|
1213
|
+
end
|
1214
|
+
|
1215
|
+
def logs
|
1216
|
+
@messages
|
1217
|
+
end
|
1218
|
+
|
1219
|
+
def level
|
1220
|
+
1
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
def level=(new_level)
|
1224
|
+
end
|
1225
|
+
end
|
1226
|
+
end
|
1227
|
+
let(:custom_logger_object) { custom_logger.new }
|
1228
|
+
|
1229
|
+
it 'logs a deprecation warning (#RSA10l)' do
|
1230
|
+
client.auth.authorise
|
1231
|
+
expect(custom_logger_object.logs.find { |severity, message| message.match(/authorise.*deprecated/i)} ).to_not be_nil
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
it 'returns a valid token (#RSA10l)' do
|
1235
|
+
response = client.auth.authorise
|
1236
|
+
expect(response).to be_a(Ably::Models::TokenDetails)
|
1237
|
+
end
|
1238
|
+
end
|
1205
1239
|
end
|
1206
1240
|
end
|