spec/acceptance/rest/base_spec.rb in ably-0.7.6 vs spec/acceptance/rest/base_spec.rb in ably-0.8.0

- old
+ new

@@ -107,22 +107,22 @@ end end end describe 'token authentication failures', :webmock do - let(:token_1) { { id: random_str } } - let(:token_2) { { id: random_str } } - let(:channel) { 'channelname' } + let(:token_1) { { token: random_str } } + let(:token_2) { { token: random_str } } + let(:channel) { random_str } before do @token_requests = 0 @publish_attempts = 0 - stub_request(:post, "#{client.endpoint}/keys/#{key_id}/requestToken").to_return do + stub_request(:post, "#{client.endpoint}/keys/#{key_name}/requestToken").to_return do @token_requests += 1 { - :body => { access_token: send("token_#{@token_requests}").merge(expires: Time.now.to_i + 3600) }.to_json, + :body => public_send("token_#{@token_requests}").merge(expires: (Time.now.to_i + 60) * 1000).to_json, :headers => { 'Content-Type' => 'application/json' } } end stub_request(:post, "#{client.endpoint}/channels/#{channel}/publish").to_return do @@ -141,18 +141,20 @@ end it 'should automatically reissue a token' do client.channel(channel).publish('evt', 'msg') expect(@publish_attempts).to eql(1) + expect(@token_requests).to eql(1) + # Triggers an authentication 401 failure which should automatically request a new token client.channel(channel).publish('evt', 'msg') expect(@publish_attempts).to eql(3) expect(@token_requests).to eql(2) end end context 'when NOT auth#token_renewable?' do - let(:client) { Ably::Rest::Client.new(token_id: 'token ID cannot be used to create a new token', environment: environment, protocol: protocol) } + let(:client) { Ably::Rest::Client.new(token: 'token ID cannot be used to create a new token', environment: environment, protocol: protocol) } it 'should raise an InvalidToken exception' do client.channel(channel).publish('evt', 'msg') expect(@publish_attempts).to eql(1) expect { client.channel(channel).publish('evt', 'msg') }.to raise_error Ably::Exceptions::InvalidToken