ably 1.0.5 → 1.0.6
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/CHANGELOG.md +26 -1
- data/ably.gemspec +4 -3
- data/lib/ably/auth.rb +4 -4
- data/lib/ably/logger.rb +1 -1
- data/lib/ably/models/idiomatic_ruby_wrapper.rb +8 -8
- data/lib/ably/models/message.rb +6 -4
- data/lib/ably/models/presence_message.rb +6 -4
- data/lib/ably/modules/async_wrapper.rb +2 -2
- data/lib/ably/modules/conversions.rb +1 -1
- data/lib/ably/modules/encodeable.rb +1 -1
- data/lib/ably/modules/event_emitter.rb +2 -2
- data/lib/ably/modules/safe_deferrable.rb +1 -1
- data/lib/ably/modules/safe_yield.rb +1 -1
- data/lib/ably/modules/state_emitter.rb +5 -5
- data/lib/ably/realtime/auth.rb +1 -1
- data/lib/ably/realtime/channel.rb +3 -3
- data/lib/ably/realtime/channel/channel_manager.rb +2 -2
- data/lib/ably/realtime/client/incoming_message_dispatcher.rb +3 -2
- data/lib/ably/realtime/connection.rb +11 -6
- data/lib/ably/realtime/connection/websocket_transport.rb +1 -1
- data/lib/ably/realtime/presence.rb +3 -3
- data/lib/ably/realtime/presence/members_map.rb +6 -6
- data/lib/ably/rest/channel.rb +2 -2
- data/lib/ably/rest/client.rb +20 -12
- data/lib/ably/version.rb +1 -1
- data/spec/acceptance/realtime/auth_spec.rb +13 -37
- data/spec/acceptance/realtime/channel_history_spec.rb +7 -1
- data/spec/acceptance/realtime/channel_spec.rb +3 -3
- data/spec/acceptance/realtime/client_spec.rb +2 -2
- data/spec/acceptance/realtime/connection_failures_spec.rb +221 -7
- data/spec/acceptance/realtime/connection_spec.rb +13 -21
- data/spec/acceptance/realtime/message_spec.rb +2 -2
- data/spec/acceptance/realtime/presence_history_spec.rb +12 -3
- data/spec/acceptance/realtime/presence_spec.rb +10 -10
- data/spec/acceptance/rest/auth_spec.rb +21 -48
- data/spec/acceptance/rest/client_spec.rb +193 -68
- data/spec/shared/client_initializer_behaviour.rb +1 -9
- data/spec/spec_helper.rb +2 -0
- data/spec/support/event_emitter_helper.rb +31 -0
- data/spec/support/event_machine_helper.rb +1 -1
- data/spec/support/test_logger_helper.rb +42 -0
- data/spec/unit/logger_spec.rb +1 -9
- data/spec/unit/modules/async_wrapper_spec.rb +2 -2
- data/spec/unit/modules/event_emitter_spec.rb +3 -3
- data/spec/unit/modules/state_emitter_spec.rb +10 -10
- data/spec/unit/realtime/channel_spec.rb +1 -1
- data/spec/unit/realtime/connection_spec.rb +1 -1
- data/spec/unit/realtime/presence_spec.rb +1 -1
- data/spec/unit/rest/channel_spec.rb +22 -0
- data/spec/unit/util/pub_sub_spec.rb +3 -3
- metadata +26 -8
@@ -131,7 +131,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
131
131
|
let(:ttl) { 0.001 }
|
132
132
|
let(:auth_requests) { [] }
|
133
133
|
let(:token_callback) do
|
134
|
-
|
134
|
+
lambda do |token_params|
|
135
135
|
auth_requests << Time.now
|
136
136
|
Ably::Rest::Client.new(default_options).auth.request_token(ttl: ttl).token
|
137
137
|
end
|
@@ -246,7 +246,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
246
246
|
let(:ttl) { 4 }
|
247
247
|
let(:auth_requests) { [] }
|
248
248
|
let(:token_callback) do
|
249
|
-
|
249
|
+
lambda do |token_params|
|
250
250
|
sleep 2
|
251
251
|
auth_requests << Time.now
|
252
252
|
Ably::Rest::Client.new(default_options).auth.request_token(ttl: ttl).token
|
@@ -298,7 +298,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
298
298
|
context 'and subsequent token is invalid' do
|
299
299
|
let(:ttl) { 2 }
|
300
300
|
let(:token_callback) do
|
301
|
-
|
301
|
+
lambda do |token_params|
|
302
302
|
if @token_issued
|
303
303
|
"#{app_id}.invalid-token-invalid-token-invalid-token"
|
304
304
|
else
|
@@ -417,7 +417,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
417
417
|
let(:phases) { [:connecting, :connected] }
|
418
418
|
let(:events_emitted) { [] }
|
419
419
|
let(:test_expectation) do
|
420
|
-
|
420
|
+
lambda do
|
421
421
|
expect(events_emitted).to eq(phases)
|
422
422
|
stop_reactor
|
423
423
|
end
|
@@ -466,7 +466,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
466
466
|
been_disconnected = true
|
467
467
|
end
|
468
468
|
connection.once(:connecting) do
|
469
|
-
close_if_transport_available =
|
469
|
+
close_if_transport_available = lambda do
|
470
470
|
EventMachine.add_timer(0.001) do
|
471
471
|
if connection.transport
|
472
472
|
connection.transport.close_connection_after_writing
|
@@ -796,7 +796,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
796
796
|
end
|
797
797
|
end
|
798
798
|
|
799
|
-
ping_block =
|
799
|
+
ping_block = lambda do |time|
|
800
800
|
pings_complete << true
|
801
801
|
if pings_complete.length == 3
|
802
802
|
expect(heartbeat_ids.uniq.length).to eql(3)
|
@@ -980,7 +980,6 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
980
980
|
|
981
981
|
context 'transport-level heartbeats are supported in the websocket transport' do
|
982
982
|
it 'provides the heartbeats argument in the websocket connection params (#RTN23b)' do
|
983
|
-
skip 'Native heartbeats not yet supported in the WS driver https://github.com/ably/ably-ruby/issues/116'
|
984
983
|
expect(EventMachine).to receive(:connect) do |host, port, transport, object, url|
|
985
984
|
uri = URI.parse(url)
|
986
985
|
expect(CGI::parse(uri.query)['heartbeats'][0]).to eql('false')
|
@@ -990,12 +989,10 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
990
989
|
end
|
991
990
|
|
992
991
|
it 'receives websocket heartbeat messages (#RTN23b) [slow test as need to wait for heartbeat]', em_timeout: 45 do
|
993
|
-
skip "Heartbeats param is missing from realtime implementation, see https://github.com/ably/realtime/issues/656"
|
994
|
-
|
995
992
|
connection.once(:connected) do
|
996
993
|
connection.__incoming_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message|
|
997
994
|
if protocol_message.action == :heartbeat
|
998
|
-
expect(protocol_message.attributes[:source]).to eql(
|
995
|
+
expect(protocol_message.attributes[:source]).to eql(:websocket)
|
999
996
|
expect(connection.time_since_connection_confirmed_alive?).to be_within(1).of(0)
|
1000
997
|
stop_reactor
|
1001
998
|
end
|
@@ -1021,7 +1018,8 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
1021
1018
|
connection.once(:connected) do
|
1022
1019
|
connection.__incoming_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message|
|
1023
1020
|
if protocol_message.action == :heartbeat
|
1024
|
-
|
1021
|
+
next if protocol_message.attributes[:source] == :websocket # ignore the native heartbeats
|
1022
|
+
expect(protocol_message.attributes[:source]).to_not eql(:websocket)
|
1025
1023
|
expect(connection.time_since_connection_confirmed_alive?).to be_within(1).of(0)
|
1026
1024
|
stop_reactor
|
1027
1025
|
end
|
@@ -1176,24 +1174,18 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
1176
1174
|
end
|
1177
1175
|
|
1178
1176
|
context "opening a new connection using a recently disconnected connection's #recovery_key" do
|
1179
|
-
context 'connection#id
|
1180
|
-
it 'remains the same
|
1181
|
-
connection_key_consistent_part_regex = /.*?!([\w-]{5,})-\w+/
|
1177
|
+
context 'connection#id after recovery' do
|
1178
|
+
it 'remains the same' do
|
1182
1179
|
previous_connection_id = nil
|
1183
|
-
previous_connection_key = nil
|
1184
1180
|
|
1185
1181
|
connection.once(:connected) do
|
1186
1182
|
previous_connection_id = connection.id
|
1187
|
-
previous_connection_key = connection.key
|
1188
1183
|
connection.transition_state_machine! :failed
|
1189
1184
|
end
|
1190
1185
|
|
1191
1186
|
connection.once(:failed) do
|
1192
1187
|
recover_client = auto_close Ably::Realtime::Client.new(default_options.merge(recover: client.connection.recovery_key))
|
1193
1188
|
recover_client.connection.on(:connected) do
|
1194
|
-
expect(recover_client.connection.key[connection_key_consistent_part_regex, 1]).to_not be_nil
|
1195
|
-
expect(recover_client.connection.key[connection_key_consistent_part_regex, 1]).to eql(
|
1196
|
-
previous_connection_key[connection_key_consistent_part_regex, 1])
|
1197
1189
|
expect(recover_client.connection.id).to eql(previous_connection_id)
|
1198
1190
|
stop_reactor
|
1199
1191
|
end
|
@@ -1485,7 +1477,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
1485
1477
|
end
|
1486
1478
|
end
|
1487
1479
|
|
1488
|
-
close_connection_proc =
|
1480
|
+
close_connection_proc = lambda do
|
1489
1481
|
EventMachine.add_timer(0.001) do
|
1490
1482
|
if connection.transport.nil?
|
1491
1483
|
close_connection_proc.call
|
@@ -1523,7 +1515,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
1523
1515
|
# See https://github.com/ably/ably-ruby/issues/103
|
1524
1516
|
it 'emits event to all and single subscribers' do
|
1525
1517
|
connected_emitted = []
|
1526
|
-
block =
|
1518
|
+
block = lambda do |state_change|
|
1527
1519
|
if state_change.current == :connected
|
1528
1520
|
connected_emitted << state_change
|
1529
1521
|
EventMachine.add_timer(0.5) do
|
@@ -284,7 +284,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
284
284
|
end
|
285
285
|
|
286
286
|
it 'sends and receives the messages on both opened connections and calls the success callbacks for each message published', em_timeout: 10 do
|
287
|
-
check_message_and_callback_counts =
|
287
|
+
check_message_and_callback_counts = lambda do
|
288
288
|
if echos[:client] == expected_echos && echos[:other] == expected_echos
|
289
289
|
# Wait for message backlog to clear
|
290
290
|
EventMachine.add_timer(0.5) do
|
@@ -650,7 +650,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
650
650
|
let(:msgs_received) { [] }
|
651
651
|
|
652
652
|
it 'publishes the message again, later receives the ACK and only one message is ever received from Ably' do
|
653
|
-
on_reconnected =
|
653
|
+
on_reconnected = lambda do |*args|
|
654
654
|
expect(message_state).to be_empty
|
655
655
|
EventMachine.add_timer(2) do
|
656
656
|
expect(message_state).to contain_exactly(:delivered)
|
@@ -71,11 +71,14 @@ describe Ably::Realtime::Presence, 'history', :event_machine do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
context 'and two pages of messages' do
|
74
|
-
let(:wildcard_token) {
|
74
|
+
let(:wildcard_token) { lambda { |token_params| Ably::Rest::Client.new(default_options).auth.request_token(client_id: '*') } }
|
75
75
|
let(:client_one) { auto_close Ably::Realtime::Client.new(default_options.merge(auth_callback: wildcard_token)) }
|
76
76
|
let(:client_two) { auto_close Ably::Realtime::Client.new(default_options.merge(auth_callback: wildcard_token)) }
|
77
77
|
|
78
|
-
|
78
|
+
# TODO: Remove retry logic when presence history regression fixed
|
79
|
+
# https://github.com/ably/realtime/issues/1707
|
80
|
+
#
|
81
|
+
it 'retrieves two pages of messages before channel was attached', retry: 10, :retry_wait => 5 do
|
79
82
|
when_all(*10.times.map { |i| presence_client_two.enter_client("client:#{i}", presence_data_before_attach) }) do
|
80
83
|
when_all(*10.times.map { |i| presence_client_one.enter_client("client:#{i}", presence_data_after_attach) }) do
|
81
84
|
presence_client_one.history(until_attach: true, limit: 5) do |presence_page|
|
@@ -85,7 +88,13 @@ describe Ably::Realtime::Presence, 'history', :event_machine do
|
|
85
88
|
presence_page.next do |presence_next_page|
|
86
89
|
expect(presence_next_page.items.count).to eql(5)
|
87
90
|
expect(presence_next_page.items.map(&:data).uniq.first).to eql(presence_data_before_attach)
|
88
|
-
|
91
|
+
if presence_next_page.has_next?
|
92
|
+
presence_next_page.next do |last|
|
93
|
+
expect(last.items.count).to eql(0)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
expect(presence_next_page).to be_last
|
97
|
+
end
|
89
98
|
stop_reactor
|
90
99
|
end
|
91
100
|
end
|
@@ -14,7 +14,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
14
14
|
let(:client_two_id) { random_str }
|
15
15
|
let(:client_two) { auto_close Ably::Realtime::Client.new(client_options.merge(client_id: client_two_id)) }
|
16
16
|
|
17
|
-
let(:wildcard_token) {
|
17
|
+
let(:wildcard_token) { lambda { |token_params| Ably::Rest::Client.new(client_options).auth.request_token(client_id: '*') } }
|
18
18
|
let(:channel_name) { "presence-#{random_str(4)}" }
|
19
19
|
let(:channel_anonymous_client) { anonymous_client.channel(channel_name) }
|
20
20
|
let(:presence_anonymous_client) { channel_anonymous_client.presence }
|
@@ -1354,7 +1354,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1354
1354
|
clients << presence
|
1355
1355
|
next unless clients.count == 5
|
1356
1356
|
|
1357
|
-
wait_until(
|
1357
|
+
wait_until(lambda { updated_callback_count == 5 }) do
|
1358
1358
|
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1359
1359
|
expect(updated_callback_count).to eql(5)
|
1360
1360
|
stop_reactor
|
@@ -1388,7 +1388,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1388
1388
|
clients << presence
|
1389
1389
|
next unless clients.count == 5
|
1390
1390
|
|
1391
|
-
wait_until(
|
1391
|
+
wait_until(lambda { updated_callback_count == 5 }) do
|
1392
1392
|
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1393
1393
|
expect(updated_callback_count).to eql(5)
|
1394
1394
|
stop_reactor
|
@@ -1420,7 +1420,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1420
1420
|
clients << presence
|
1421
1421
|
next unless clients.count == 5
|
1422
1422
|
|
1423
|
-
wait_until(
|
1423
|
+
wait_until(lambda { left_callback_count == 5 }) do
|
1424
1424
|
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1425
1425
|
expect(left_callback_count).to eql(5)
|
1426
1426
|
stop_reactor
|
@@ -1442,7 +1442,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1442
1442
|
clients << presence
|
1443
1443
|
next unless clients.count == 5
|
1444
1444
|
|
1445
|
-
wait_until(
|
1445
|
+
wait_until(lambda { left_callback_count == 5 }) do
|
1446
1446
|
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1447
1447
|
expect(left_callback_count).to eql(5)
|
1448
1448
|
stop_reactor
|
@@ -1789,7 +1789,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1789
1789
|
clients_entered[:client_two] += 1
|
1790
1790
|
end
|
1791
1791
|
|
1792
|
-
wait_until(
|
1792
|
+
wait_until(lambda { clients_entered[:client_one] + clients_entered[:client_two] == total_members * 2 }) do
|
1793
1793
|
presence_anonymous_client.get(wait_for_sync: true) do |anonymous_members|
|
1794
1794
|
expect(anonymous_members.count).to eq(total_members)
|
1795
1795
|
expect(anonymous_members.map(&:client_id).uniq.count).to eq(total_members)
|
@@ -1886,7 +1886,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1886
1886
|
context 'with no arguments' do
|
1887
1887
|
it 'removes the callback for all presence events' do
|
1888
1888
|
when_all(channel_client_one.attach, channel_client_two.attach) do
|
1889
|
-
subscribe_callback =
|
1889
|
+
subscribe_callback = lambda { raise 'Should not be called' }
|
1890
1890
|
presence_client_two.subscribe(&subscribe_callback)
|
1891
1891
|
presence_client_two.unsubscribe(&subscribe_callback)
|
1892
1892
|
|
@@ -1904,7 +1904,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1904
1904
|
context 'with event name' do
|
1905
1905
|
it 'removes the callback for specified presence event' do
|
1906
1906
|
when_all(channel_client_one.attach, channel_client_two.attach) do
|
1907
|
-
subscribe_callback =
|
1907
|
+
subscribe_callback = lambda { raise 'Should not be called' }
|
1908
1908
|
presence_client_two.subscribe :leave, &subscribe_callback
|
1909
1909
|
presence_client_two.unsubscribe :leave, &subscribe_callback
|
1910
1910
|
|
@@ -2337,7 +2337,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
2337
2337
|
let(:present_only_capability) do
|
2338
2338
|
{ channel_name => ["presence"] }
|
2339
2339
|
end
|
2340
|
-
let(:present_only_callback) {
|
2340
|
+
let(:present_only_callback) { lambda { |token_params| Ably::Rest::Client.new(client_options).auth.request_token(client_id: '*', capability: present_only_capability) } }
|
2341
2341
|
let(:client_one) { auto_close Ably::Realtime::Client.new(client_options.merge(auth_callback: present_only_callback)) }
|
2342
2342
|
|
2343
2343
|
it 'receives presence updates for all presence events generated by the current connection and the presence map is kept up to date (#RTP17a)' do
|
@@ -2751,7 +2751,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
2751
2751
|
|
2752
2752
|
context 'channel transitions to the SUSPENDED state' do
|
2753
2753
|
let(:auth_callback) do
|
2754
|
-
|
2754
|
+
lambda do |token_params|
|
2755
2755
|
# Pause to allow presence updates to occur whilst disconnected
|
2756
2756
|
sleep 1
|
2757
2757
|
Ably::Rest::Client.new(client_options).auth.request_token
|
@@ -472,7 +472,7 @@ describe Ably::Auth do
|
|
472
472
|
end
|
473
473
|
|
474
474
|
let(:auth_callback) do
|
475
|
-
|
475
|
+
lambda do |token_params_arg|
|
476
476
|
@block_called = true
|
477
477
|
@block_params = token_params_arg
|
478
478
|
{
|
@@ -486,7 +486,7 @@ describe Ably::Auth do
|
|
486
486
|
end
|
487
487
|
end
|
488
488
|
|
489
|
-
it 'calls the
|
489
|
+
it 'calls the lambda when authenticating to obtain the request token' do
|
490
490
|
expect(@block_called).to eql(true)
|
491
491
|
expect(@block_params).to include(token_params)
|
492
492
|
end
|
@@ -517,7 +517,7 @@ describe Ably::Auth do
|
|
517
517
|
let(:client_id) { random_str }
|
518
518
|
|
519
519
|
let!(:token_details) do
|
520
|
-
auth.request_token({}, auth_callback:
|
520
|
+
auth.request_token({}, auth_callback: lambda do |token_params|
|
521
521
|
auth.create_token_request(client_id: client_id)
|
522
522
|
end)
|
523
523
|
end
|
@@ -533,7 +533,7 @@ describe Ably::Auth do
|
|
533
533
|
let(:token) { second_client.auth.request_token.token }
|
534
534
|
|
535
535
|
let!(:token_details) do
|
536
|
-
auth.request_token({}, auth_callback:
|
536
|
+
auth.request_token({}, auth_callback: lambda do |token_params|
|
537
537
|
token
|
538
538
|
end)
|
539
539
|
end
|
@@ -689,7 +689,7 @@ describe Ably::Auth do
|
|
689
689
|
|
690
690
|
context 'AuthOptions argument' do
|
691
691
|
let(:token_ttl) { 2 }
|
692
|
-
let(:auth_callback) {
|
692
|
+
let(:auth_callback) { lambda do |token_params|
|
693
693
|
auth.create_token_request(ttl: token_ttl)
|
694
694
|
end }
|
695
695
|
let(:default_auth_options) { { auth_callback: auth_callback } }
|
@@ -717,7 +717,7 @@ describe Ably::Auth do
|
|
717
717
|
end
|
718
718
|
|
719
719
|
it 'updates Auth#options attribute with an immutable hash' do
|
720
|
-
auth.authorize(nil, auth_callback:
|
720
|
+
auth.authorize(nil, auth_callback: lambda { |token_params| '1231232.12321:12321312' })
|
721
721
|
expect { auth.options['key_name'] = 'new_name' }.to raise_error RuntimeError, /can't modify frozen.*Hash/
|
722
722
|
end
|
723
723
|
|
@@ -763,17 +763,17 @@ describe Ably::Auth do
|
|
763
763
|
expect(auth.options[:authUrl]).to eql('http://foo.com')
|
764
764
|
end
|
765
765
|
|
766
|
-
context 'with a
|
766
|
+
context 'with a lambda for the :auth_callback option' do
|
767
767
|
let(:client_id) { random_str }
|
768
768
|
let!(:token) do
|
769
|
-
auth.authorize({}, auth_callback:
|
769
|
+
auth.authorize({}, auth_callback: lambda do |token_params|
|
770
770
|
@block_called ||= 0
|
771
771
|
@block_called += 1
|
772
772
|
auth.create_token_request(client_id: client_id)
|
773
773
|
end)
|
774
774
|
end
|
775
775
|
|
776
|
-
it 'calls the
|
776
|
+
it 'calls the lambda' do
|
777
777
|
expect(@block_called).to eql(1)
|
778
778
|
end
|
779
779
|
|
@@ -782,7 +782,7 @@ describe Ably::Auth do
|
|
782
782
|
end
|
783
783
|
|
784
784
|
context 'for every subsequent #request_token' do
|
785
|
-
context 'without a :auth_callback
|
785
|
+
context 'without a :auth_callback lambda' do
|
786
786
|
it 'calls the originally provided block' do
|
787
787
|
auth.request_token
|
788
788
|
expect(@block_called).to eql(2)
|
@@ -790,8 +790,8 @@ describe Ably::Auth do
|
|
790
790
|
end
|
791
791
|
|
792
792
|
context 'with a provided block' do
|
793
|
-
it 'does not call the originally provided
|
794
|
-
auth.request_token({}, auth_callback:
|
793
|
+
it 'does not call the originally provided lambda and calls the new #request_token :auth_callback lambda' do
|
794
|
+
auth.request_token({}, auth_callback: lambda { |token_params| @request_block_called = true; auth.create_token_request })
|
795
795
|
expect(@block_called).to eql(1)
|
796
796
|
expect(@request_block_called).to eql(true)
|
797
797
|
end
|
@@ -800,7 +800,7 @@ describe Ably::Auth do
|
|
800
800
|
end
|
801
801
|
|
802
802
|
context 'with an explicit token string that expires' do
|
803
|
-
context 'and a
|
803
|
+
context 'and a lambda for the :auth_callback option to provide a means to renew the token' do
|
804
804
|
before do
|
805
805
|
# Ensure a soon to expire token is not treated as expired
|
806
806
|
stub_const 'Ably::Models::TokenDetails::TOKEN_EXPIRY_BUFFER', 0
|
@@ -811,13 +811,13 @@ describe Ably::Auth do
|
|
811
811
|
|
812
812
|
let(:token_client) { Ably::Rest::Client.new(default_options.merge(key: api_key, default_token_params: { ttl: 3 })) }
|
813
813
|
let(:client_options) {
|
814
|
-
default_options.merge(token: token_client.auth.request_token.token, auth_callback:
|
814
|
+
default_options.merge(token: token_client.auth.request_token.token, auth_callback: lambda do |token_params|
|
815
815
|
@block_called += 1
|
816
816
|
token_client.auth.create_token_request
|
817
817
|
end)
|
818
818
|
}
|
819
819
|
|
820
|
-
it 'calls the
|
820
|
+
it 'calls the lambda once the token has expired and the new token is used' do
|
821
821
|
client.stats
|
822
822
|
expect(@block_called).to eql(0)
|
823
823
|
sleep 3.5
|
@@ -829,7 +829,7 @@ describe Ably::Auth do
|
|
829
829
|
|
830
830
|
context 'with an explicit ClientOptions client_id' do
|
831
831
|
let(:client_id) { random_str }
|
832
|
-
let(:client_options) { default_options.merge(auth_callback:
|
832
|
+
let(:client_options) { default_options.merge(auth_callback: lambda { |token_params| auth_token_object }, client_id: client_id) }
|
833
833
|
let(:auth_client) { Ably::Rest::Client.new(default_options.merge(key: api_key, client_id: 'invalid')) }
|
834
834
|
|
835
835
|
context 'and an incompatible client_id in a TokenDetails object passed to the auth callback' do
|
@@ -871,7 +871,7 @@ describe Ably::Auth do
|
|
871
871
|
end
|
872
872
|
|
873
873
|
it 'returns a TokenRequest that can be passed to a client that can use it for authentication without an API key' do
|
874
|
-
auth_callback =
|
874
|
+
auth_callback = proc { |token_params| subject }
|
875
875
|
client_without_api_key = Ably::Rest::Client.new(default_options.merge(auth_callback: auth_callback))
|
876
876
|
expect(client_without_api_key.auth).to be_using_token_auth
|
877
877
|
expect { client_without_api_key.auth.authorize }.to_not raise_error
|
@@ -932,7 +932,7 @@ describe Ably::Auth do
|
|
932
932
|
end
|
933
933
|
|
934
934
|
it 'uses these capabilities when Ably issues an actual token' do
|
935
|
-
auth_callback =
|
935
|
+
auth_callback = lambda { |token_params| subject }
|
936
936
|
client_without_api_key = Ably::Rest::Client.new(default_options.merge(auth_callback: auth_callback))
|
937
937
|
client_without_api_key.auth.authorize
|
938
938
|
expect(client_without_api_key.auth.current_token_details.capability).to eql(capability)
|
@@ -1041,7 +1041,7 @@ describe Ably::Auth do
|
|
1041
1041
|
end
|
1042
1042
|
|
1043
1043
|
it 'is valid when used for authentication' do
|
1044
|
-
auth_callback =
|
1044
|
+
auth_callback = lambda do |callback|
|
1045
1045
|
auth.create_token_request(token_attributes)
|
1046
1046
|
end
|
1047
1047
|
client = Ably::Rest::Client.new(auth_callback: auth_callback, environment: environment, protocol: protocol)
|
@@ -1324,36 +1324,9 @@ describe Ably::Auth do
|
|
1324
1324
|
end
|
1325
1325
|
end
|
1326
1326
|
|
1327
|
-
context 'deprecated #authorise' do
|
1327
|
+
context 'deprecated #authorise', :prevent_log_stubbing do
|
1328
1328
|
let(:client_options) { default_options.merge(key: api_key, logger: custom_logger_object, use_token_auth: true) }
|
1329
|
-
let(:
|
1330
|
-
Class.new do
|
1331
|
-
def initialize
|
1332
|
-
@messages = []
|
1333
|
-
end
|
1334
|
-
|
1335
|
-
[:fatal, :error, :warn, :info, :debug].each do |severity|
|
1336
|
-
define_method severity do |message, &block|
|
1337
|
-
message_val = [message]
|
1338
|
-
message_val << block.call if block
|
1339
|
-
|
1340
|
-
@messages << [severity, message_val.compact.join(' ')]
|
1341
|
-
end
|
1342
|
-
end
|
1343
|
-
|
1344
|
-
def logs
|
1345
|
-
@messages
|
1346
|
-
end
|
1347
|
-
|
1348
|
-
def level
|
1349
|
-
1
|
1350
|
-
end
|
1351
|
-
|
1352
|
-
def level=(new_level)
|
1353
|
-
end
|
1354
|
-
end
|
1355
|
-
end
|
1356
|
-
let(:custom_logger_object) { custom_logger.new }
|
1329
|
+
let(:custom_logger_object) { TestLogger.new }
|
1357
1330
|
|
1358
1331
|
it 'logs a deprecation warning (#RSA10l)' do
|
1359
1332
|
client.auth.authorise
|