Resolve merge conflict
[arvados.git] / spec / google / api_client_spec.rb
index ca92e7d014997cee746b49250c8c38acc94707e9..eb9a59af7b8f79b39a96a9d592a443f3510ff1f9 100644 (file)
@@ -200,7 +200,7 @@ RSpec.describe Google::APIClient do
       )
     end
 
-    it 'should refresh tokens on 401 tokens' do
+    it 'should refresh tokens on 401 errors' do
       client.authorization.access_token = '12345'
       expect(client.authorization).to receive(:fetch_access_token!)
 
@@ -290,4 +290,63 @@ RSpec.describe Google::APIClient do
     end
 
   end
+
+  describe 'when retries disabled and expired_auth_retry on (default)' do
+    before do
+      client.retries = 0
+    end
+
+    after do
+      @connection.verify
+    end
+
+    it 'should refresh tokens on 401 errors' do
+      client.authorization.access_token = '12345'
+      expect(client.authorization).to receive(:fetch_access_token!)
+
+      @connection = stub_connection do |stub|
+        stub.get('/foo') do |env|
+          [401, {}, '{}']
+        end
+        stub.get('/foo') do |env|
+          [200, {}, '{}']
+        end
+      end
+
+      client.execute(
+        :uri => 'https://www.gogole.com/foo',
+        :connection => @connection
+      )
+    end
+
+  end
+
+  describe 'when retries disabled and expired_auth_retry off' do
+    before do
+      client.retries = 0
+      client.expired_auth_retry = false
+    end
+
+    it 'should not refresh tokens on 401 errors' do
+      client.authorization.access_token = '12345'
+      expect(client.authorization).not_to receive(:fetch_access_token!)
+
+      @connection = stub_connection do |stub|
+        stub.get('/foo') do |env|
+          [401, {}, '{}']
+        end
+        stub.get('/foo') do |env|
+          [200, {}, '{}']
+        end
+      end
+
+      resp = client.execute(
+        :uri => 'https://www.gogole.com/foo',
+        :connection => @connection
+      )
+
+      expect(resp.response.status).to be == 401
+    end
+
+  end
 end