lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb in ably-rest-0.8.6 vs lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb in ably-rest-0.8.9
- old
+ new
@@ -16,11 +16,11 @@
:ttl,
:capability,
:client_id,
:timestamp,
:nonce
- ].map { |key| "#{token_request.hash[key]}\n" }.join("")
+ ].map { |key| "#{token_request.attributes[key]}\n" }.join("")
encode64(
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, secret, text)
)
end
@@ -687,24 +687,24 @@
before do
# Ensure a soon to expire token is not treated as expired
stub_const 'Ably::Models::TokenDetails::TOKEN_EXPIRY_BUFFER', 0
old_token_defaults = Ably::Auth::TOKEN_DEFAULTS
stub_const 'Ably::Auth::TOKEN_DEFAULTS', old_token_defaults.merge(renew_token_buffer: 0)
+ @block_called = 0
end
let(:token_client) { Ably::Rest::Client.new(default_options.merge(key: api_key, token_params: { ttl: 3 })) }
let(:client_options) {
default_options.merge(token: token_client.auth.request_token.token, auth_callback: Proc.new do
- @block_called ||= 0
@block_called += 1
token_client.auth.create_token_request
end)
}
it 'calls the Proc once the token has expired and the new token is used' do
client.stats
- expect(@block_called).to be_nil
+ expect(@block_called).to eql(0)
sleep 3.5
expect { client.stats }.to change { client.auth.current_token_details }
expect(@block_called).to eql(1)
end
end
@@ -822,13 +822,13 @@
end
context 'with additional invalid attributes' do
let(:token_params) { { nonce: 'valid', is_not_used_by_token_request: 'invalid' } }
specify 'are ignored' do
- expect(subject.hash.keys).to_not include(:is_not_used_by_token_request)
- expect(subject.hash.keys).to_not include(convert_to_mixed_case(:is_not_used_by_token_request))
- expect(subject.hash.keys).to include(:nonce)
+ expect(subject.attributes.keys).to_not include(:is_not_used_by_token_request)
+ expect(subject.attributes.keys).to_not include(convert_to_mixed_case(:is_not_used_by_token_request))
+ expect(subject.attributes.keys).to include(:nonce)
expect(subject.nonce).to eql('valid')
end
end
context 'when required fields are missing' do
@@ -888,11 +888,11 @@
let(:token_request_attributes) do
token_attributes.merge(timestamp: token_attributes[:timestamp] * 1000, ttl: token_attributes[:ttl] * 1000)
end
it 'generates a valid HMAC' do
- hmac = hmac_for(Ably::Models::TokenRequest(token_request_attributes).hash, key_secret)
+ hmac = hmac_for(Ably::Models::TokenRequest(token_request_attributes).attributes, key_secret)
expect(subject['mac']).to eql(hmac)
end
end
end
@@ -916,18 +916,18 @@
expect(token_auth_client.channel('foo').publish('event', 'data')).to be_truthy
end
it 'disallows publishing on unspecified capability channels' do
expect { token_auth_client.channel('bar').publish('event', 'data') }.to raise_error do |error|
- expect(error).to be_a(Ably::Exceptions::InvalidRequest)
+ expect(error).to be_a(Ably::Exceptions::UnauthorizedRequest)
expect(error.status).to eql(401)
expect(error.code).to eql(40160)
end
end
it 'fails if timestamp is invalid' do
expect { auth.request_token(timestamp: Time.now - 180) }.to raise_error do |error|
- expect(error).to be_a(Ably::Exceptions::InvalidRequest)
+ expect(error).to be_a(Ably::Exceptions::UnauthorizedRequest)
expect(error.status).to eql(401)
expect(error.code).to eql(40101)
end
end