lib/submodules/ably-ruby/spec/acceptance/realtime/auth_spec.rb in ably-rest-0.8.15 vs lib/submodules/ably-ruby/spec/acceptance/realtime/auth_spec.rb in ably-rest-0.9.0
- old
+ new
@@ -71,11 +71,11 @@
end
context '#current_token_details' do
it 'contains the current token after auth' do
expect(auth.current_token_details).to be_nil
- auth.authorise do
+ auth.authorize do
expect(auth.current_token_details).to be_a(Ably::Models::TokenDetails)
stop_reactor
end
end
end
@@ -91,40 +91,40 @@
let(:auth_url) { "https://echo.ably.io/?type=text" }
let(:auth_params) { { :body => random_str } }
let(:client_options) { default_options.merge(auto_connect: false) }
it 'contains the configured auth options' do
- auth.authorise({}, auth_url: auth_url, auth_params: auth_params) do
+ auth.authorize({}, auth_url: auth_url, auth_params: auth_params) do
expect(auth.options[:auth_url]).to eql(auth_url)
stop_reactor
end
end
end
context '#token_params' do
let(:custom_ttl) { 33 }
it 'contains the configured auth options' do
- auth.authorise(ttl: custom_ttl) do
+ auth.authorize(ttl: custom_ttl) do
expect(auth.token_params[:ttl]).to eql(custom_ttl)
stop_reactor
end
end
end
context '#using_basic_auth?' do
it 'is false when using Token Auth' do
- auth.authorise do
+ auth.authorize do
expect(auth).to_not be_using_basic_auth
stop_reactor
end
end
end
context '#using_token_auth?' do
it 'is true when using Token Auth' do
- auth.authorise do
+ auth.authorize do
expect(auth).to be_using_token_auth
stop_reactor
end
end
end
@@ -174,49 +174,20 @@
stop_reactor
end
end
end
- context '#authorise' do
+ context '#authorize' do
it 'returns a token asynchronously' do
- auth.authorise(ttl: custom_ttl, client_id: custom_client_id) do |token_details|
+ auth.authorize(ttl: custom_ttl, client_id: custom_client_id) do |token_details|
expect(token_details).to be_a(Ably::Models::TokenDetails)
expect(token_details.expires.to_i).to be_within(3).of(Time.now.to_i + custom_ttl)
expect(token_details.client_id).to eql(custom_client_id)
stop_reactor
end
end
- context 'with auth_callback blocking' do
- let(:rest_auth_client) { Ably::Rest::Client.new(default_options.merge(key: api_key)) }
- let(:client_options) { default_options.merge(auth_callback: auth_callback) }
- let(:pause) { 5 }
-
- context 'with a slow auth callback response' do
- let(:auth_callback) do
- Proc.new do
- sleep pause
- rest_auth_client.auth.request_token
- end
- end
-
- it 'asynchronously authenticates' do
- timers_called = 0
- block = Proc.new do
- timers_called += 1
- EventMachine.add_timer(0.5, &block)
- end
- block.call
- client.connect
- client.connection.on(:connected) do
- expect(timers_called).to be >= (pause-1) / 0.5
- stop_reactor
- end
- end
- end
- end
-
context 'when implicitly called, with an explicit ClientOptions client_id' do
let(:client_id) { random_str }
let(:client_options) { default_options.merge(auth_callback: Proc.new { auth_token_object }, client_id: client_id, log_level: :none) }
let(:rest_auth_client) { Ably::Rest::Client.new(default_options.merge(key: api_key, client_id: 'invalid')) }
@@ -269,11 +240,11 @@
let(:invalid_auth_token) { Ably::Rest::Client.new(default_options.merge(key: api_key, client_id: 'invalid')).auth.request_token }
context 'and an incompatible client_id in a TokenDetails object passed to the auth callback' do
it 'rejects a TokenDetails object with an incompatible client_id and raises an exception' do
client.connection.once(:connected) do
- client.auth.authorise({}, force: true)
+ client.auth.authorize({})
client.connection.on(:error) do |error|
expect(error).to be_a(Ably::Exceptions::IncompatibleClientId)
EventMachine.add_timer(0.1) do
expect(client.connection).to be_failed
stop_reactor
@@ -282,11 +253,11 @@
end
end
end
end
- context 'with force: true to trigger an authentication upgrade' do
+ context 'when already authenticated with a valid token' do
let(:rest_client) { Ably::Rest::Client.new(default_options) }
let(:client_publisher) { auto_close Ably::Realtime::Client.new(default_options) }
let(:basic_capability) { JSON.dump("foo" => ["subscribe"]) }
let(:basic_token_cb) { Proc.new do
rest_client.auth.create_token_request({ capability: basic_capability })
@@ -306,11 +277,11 @@
let(:client_options) { default_options.merge(auth_callback: basic_token_cb) }
it 'forces the connection to disconnect and reconnect with a new token when in the CONNECTED state' do
client.connection.once(:connected) do
existing_token = client.auth.current_token_details
- client.auth.authorise(nil, force: true)
+ client.auth.authorize(nil)
client.connection.once(:disconnected) do
client.connection.once(:connected) do
expect(existing_token).to_not eql(client.auth.current_token_details)
stop_reactor
end
@@ -319,11 +290,11 @@
end
it 'forces the connection to disconnect and reconnect with a new token when in the CONNECTING state' do
client.connection.once(:connecting) do
existing_token = client.auth.current_token_details
- client.auth.authorise(nil, force: true)
+ client.auth.authorize(nil)
client.connection.once(:disconnected) do
client.connection.once(:connected) do
expect(existing_token).to_not eql(client.auth.current_token_details)
stop_reactor
end
@@ -338,11 +309,11 @@
rest_client.auth.create_token_request({ client_id: 'mike', capability: basic_capability })
end }
it 'transisitions the connection state to FAILED if the client_id changes' do
client.connection.once(:connected) do
- client.auth.authorise(nil, auth_callback: identified_token_cb, force: true)
+ client.auth.authorize(nil, auth_callback: identified_token_cb)
client.connection.once(:failed) do
expect(client.connection.error_reason.message).to match(/incompatible.*client ID/)
stop_reactor
end
end
@@ -356,11 +327,11 @@
client.connection.once(:connected) do
channel = client.channels.get('foo')
channel.publish('not-allowed').errback do |error|
expect(error.code).to eql(40160)
expect(error.message).to match(/permission denied/)
- client.auth.authorise(nil, auth_callback: upgraded_token_cb, force: true)
+ client.auth.authorize(nil, auth_callback: upgraded_token_cb)
client.connection.once(:connected) do
expect(client.connection.error_reason).to be_nil
channel.subscribe('allowed') do |message|
stop_reactor
end
@@ -376,11 +347,11 @@
it 'is allowed and channels are detached' do
client.connection.once(:connected) do
channel = client.channels.get('foo')
channel.attach do
- client.auth.authorise(nil, auth_callback: downgraded_token_cb, force: true)
+ client.auth.authorize(nil, auth_callback: downgraded_token_cb)
channel.once(:failed) do
expect(channel.error_reason.code).to eql(40160)
expect(channel.error_reason.message).to match(/Channel denied access/)
stop_reactor
end
@@ -399,11 +370,11 @@
end
publisher_channel.attach do
publisher_channel.publish('foo') do
EventMachine.add_timer(2) do
expect(received_messages.length).to eql(1)
- client.auth.authorise(nil, force: true)
+ client.auth.authorize(nil)
client.connection.once(:disconnected) do
publisher_channel.publish('bar') do
expect(received_messages.length).to eql(1)
end
end
@@ -420,13 +391,13 @@
end
it 'does not change the connection state if current connection state is closing' do
client.connection.once(:connected) do
client.connection.once(:closing) do
- client.auth.authorise(nil, force: true)
+ client.auth.authorize(nil)
client.connection.once(:connected) do
- raise "Should not reconnect following auth force: true"
+ raise "Should not reconnect following #authorize"
end
EventMachine.add_timer(4) do
expect(client.connection).to be_closed
stop_reactor
end
@@ -436,13 +407,13 @@
end
it 'does not change the connection state if current connection state is closed' do
client.connection.once(:connected) do
client.connection.once(:closed) do
- client.auth.authorise(nil, force: true)
+ client.auth.authorize(nil)
client.connection.once(:connected) do
- raise "Should not reconnect following auth force: true"
+ raise "Should not reconnect following #authorize"
end
EventMachine.add_timer(4) do
expect(client.connection).to be_closed
stop_reactor
end
@@ -455,13 +426,13 @@
let(:client_options) { default_options.merge(auth_callback: basic_token_cb, log_level: :none) }
it 'does not change the connection state' do
client.connection.once(:connected) do
client.connection.once(:failed) do
- client.auth.authorise(nil, force: true)
+ client.auth.authorize(nil)
client.connection.once(:connected) do
- raise "Should not reconnect following auth force: true"
+ raise "Should not reconnect following #authorize"
end
EventMachine.add_timer(4) do
expect(client.connection).to be_failed
stop_reactor
end
@@ -472,14 +443,14 @@
end
end
end
end
- context '#authorise_async' do
+ context '#authorize_async' do
it 'returns a token synchronously' do
- auth.authorise_sync(ttl: custom_ttl, client_id: custom_client_id).tap do |token_details|
- expect(auth.authorise_sync).to be_a(Ably::Models::TokenDetails)
+ auth.authorize_sync(ttl: custom_ttl, client_id: custom_client_id).tap do |token_details|
+ expect(auth.authorize_sync).to be_a(Ably::Models::TokenDetails)
expect(token_details.expires.to_i).to be_within(3).of(Time.now.to_i + custom_ttl)
expect(token_details.client_id).to eql(custom_client_id)
stop_reactor
end
end
@@ -691,9 +662,51 @@
client.channel('test').publish('a') do
expect(client.auth).to be_client_id_validated
stop_reactor
end
end
+ end
+ end
+ end
+
+ context 'deprecated #authorise' do
+ let(:client_options) { default_options.merge(key: api_key, logger: custom_logger_object) }
+ let(:custom_logger) do
+ Class.new do
+ def initialize
+ @messages = []
+ end
+
+ [:fatal, :error, :warn, :info, :debug].each do |severity|
+ define_method severity do |message|
+ @messages << [severity, message]
+ end
+ end
+
+ def logs
+ @messages
+ end
+
+ def level
+ 1
+ end
+
+ def level=(new_level)
+ end
+ end
+ end
+ let(:custom_logger_object) { custom_logger.new }
+
+ it 'logs a deprecation warning (#RSA10l)' do
+ client.auth.authorise
+ expect(custom_logger_object.logs.find { |severity, message| message.match(/authorise.*deprecated/i)} ).to_not be_nil
+ stop_reactor
+ end
+
+ it 'returns a valid token (#RSA10l)' do
+ client.auth.authorise do |response|
+ expect(response).to be_a(Ably::Models::TokenDetails)
+ stop_reactor
end
end
end
end
end