spec/acceptance/realtime/auth_spec.rb in ably-1.0.5 vs spec/acceptance/realtime/auth_spec.rb in ably-1.0.6
- old
+ new
@@ -204,19 +204,19 @@
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
+ lambda do |token_params|
sleep pause
rest_auth_client.auth.request_token
end
end
it 'asynchronously authenticates' do
timers_called = 0
- block = Proc.new do
+ block = lambda do
timers_called += 1
EventMachine.add_timer(0.5, &block)
end
block.call
client.connect
@@ -228,11 +228,11 @@
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(:client_options) { default_options.merge(auth_callback: lambda { |token_params| 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')) }
context 'and an incompatible client_id in a TokenDetails object passed to the auth callback' do
let(:auth_token_object) { rest_auth_client.auth.request_token }
@@ -266,11 +266,11 @@
end
end
context 'when explicitly called, with an explicit ClientOptions client_id' do
let(:auth_proc) do
- Proc.new do
+ lambda do |token_params|
if !@requested
@requested = true
valid_auth_token
else
invalid_auth_token
@@ -302,22 +302,22 @@
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
+ let(:basic_token_cb) { lambda do |token_params|
rest_client.auth.create_token_request({ capability: basic_capability })
end }
let(:upgraded_capability) { JSON.dump({ "foo" => ["subscribe", "publish"] }) }
- let(:upgraded_token_cb) { Proc.new do
+ let(:upgraded_token_cb) { lambda do |token_params|
rest_client.auth.create_token_request({ capability: upgraded_capability })
end }
- let(:identified_token_cb) { Proc.new do
+ let(:identified_token_cb) { lambda do |token_params|
rest_client.auth.create_token_request({ client_id: 'bob' })
end }
let(:downgraded_capability) { JSON.dump({ "bar" => ["subscribe"] }) }
- let(:downgraded_token_cb) { Proc.new do
+ let(:downgraded_token_cb) { lambda do |token_params|
rest_client.auth.create_token_request({ capability: downgraded_capability })
end }
let(:client_options) { default_options.merge(auth_callback: basic_token_cb) }
let(:connection) { client.connection }
@@ -587,11 +587,11 @@
end
context 'when client is identified' do
let(:client_options) { default_options.merge(auth_callback: basic_token_cb, log_level: :none) }
- let(:basic_token_cb) { Proc.new do
+ let(:basic_token_cb) { lambda do |token_params|
rest_client.auth.create_token_request({ client_id: 'mike', capability: basic_capability })
end }
it 'transitions the connection state to FAILED if the client_id changes (#RSA15c, #RTC8a2)' do
client.connection.once(:connected) do
@@ -610,11 +610,11 @@
it 'transitions the connection state to the FAILED state (#RSA15c, #RTC8a2, #RTC8a3)' do
connection_failed = false
client.connection.once(:connected) do
- client.auth.authorize(nil, auth_callback: Proc.new { 'invalid.token:will.cause.failure' }).tap do |deferrable|
+ client.auth.authorize(nil, auth_callback: lambda { |token_params| 'invalid.token:will.cause.failure' }).tap do |deferrable|
deferrable.errback do |error|
EventMachine.add_timer(0.2) do
expect(connection_failed).to eql(true)
expect(error.message).to match(/Invalid accessToken/i)
expect(error.code).to eql(40005)
@@ -636,11 +636,11 @@
context 'when the authCallback fails' do
let(:client_options) { default_options.merge(auth_callback: basic_token_cb, log_level: :none) }
it 'calls the error callback of authorize and leaves the connection intact (#RSA4c3)' do
client.connection.once(:connected) do
- client.auth.authorize(nil, auth_callback: Proc.new { raise 'Exception raised' }).errback do |error|
+ client.auth.authorize(nil, auth_callback: lambda { |token_params| raise 'Exception raised' }).errback do |error|
EventMachine.add_timer(0.2) do
expect(connection).to be_connected
expect(error.message).to match(/Exception raised/i)
stop_reactor
end
@@ -1012,36 +1012,12 @@
end
end
end
end
- context 'deprecated #authorise' do
+ context 'deprecated #authorise', :prevent_log_stubbing do
let(:client_options) { default_options.merge(key: api_key, logger: custom_logger_object, use_token_auth: true) }
- 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 }
+ let(:custom_logger_object) { TestLogger.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