summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-29 14:09:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-29 14:09:54 +0000
commit37823295027da50ff5bc14df482b8cba09bf41b4 (patch)
treeb2a9e1deb265b777cb20cb6b4c512be955153a3b /spec/lib/gitlab
parent6bea43795252f980eeee7ce67413ef440da88a31 (diff)
downloadgitlab-ce-37823295027da50ff5bc14df482b8cba09bf41b4.tar.gz
Add latest changes from gitlab-org/security/gitlab@15-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/buffered_io_spec.rb64
1 files changed, 30 insertions, 34 deletions
diff --git a/spec/lib/gitlab/buffered_io_spec.rb b/spec/lib/gitlab/buffered_io_spec.rb
index f8896abd46e..c6939b819e2 100644
--- a/spec/lib/gitlab/buffered_io_spec.rb
+++ b/spec/lib/gitlab/buffered_io_spec.rb
@@ -1,54 +1,50 @@
-# rubocop:disable Style/FrozenStringLiteralComment
+# frozen_string_literal: true
+
require 'spec_helper'
RSpec.describe Gitlab::BufferedIo do
describe '#readuntil' do
- let(:never_ending_tcp_socket) do
- Class.new do
- def initialize(*_)
- @read_counter = 0
- end
+ let(:mock_io) { StringIO.new('a') }
+ let(:start_time) { Process.clock_gettime(Process::CLOCK_MONOTONIC) }
- def setsockopt(*_); end
+ before do
+ stub_const('Gitlab::BufferedIo::HEADER_READ_TIMEOUT', 0.1)
+ end
- def closed?
- false
- end
+ subject(:readuntil) do
+ Gitlab::BufferedIo.new(mock_io).readuntil('a', false, start_time)
+ end
- def close
- true
- end
+ it 'does not raise a timeout error' do
+ expect { readuntil }.not_to raise_error
+ end
- def to_io
- StringIO.new('Hello World!')
- end
+ context 'when the response contains infinitely long headers' do
+ before do
+ read_counter = 0
- def write_nonblock(data, *_)
- data.size
- end
+ allow(mock_io).to receive(:read_nonblock) do |buffer_size, *_|
+ read_counter += 1
+ raise 'Test did not raise HeaderReadTimeout' if read_counter > 10
- def read_nonblock(buffer_size, *_)
sleep 0.01
- @read_counter += 1
-
- raise 'Test did not raise HeaderReadTimeout' if @read_counter > 10
-
'H' * buffer_size
end
end
- end
- before do
- stub_const('Gitlab::BufferedIo::HEADER_READ_TIMEOUT', 0.1)
- end
+ it 'raises a timeout error' do
+ expect { readuntil }.to raise_error(Gitlab::HTTP::HeaderReadTimeout, /Request timed out after reading headers for 0\.[0-9]+ seconds/)
+ end
- subject(:readuntil) do
- Gitlab::BufferedIo.new(never_ending_tcp_socket.new).readuntil('a')
- end
+ context 'when not passing start_time' do
+ subject(:readuntil) do
+ Gitlab::BufferedIo.new(mock_io).readuntil('a', false)
+ end
- it 'raises a timeout error' do
- expect { readuntil }.to raise_error(Gitlab::HTTP::HeaderReadTimeout, /Request timed out after reading headers for 0\.[0-9]+ seconds/)
+ it 'raises a timeout error' do
+ expect { readuntil }.to raise_error(Gitlab::HTTP::HeaderReadTimeout, /Request timed out after reading headers for 0\.[0-9]+ seconds/)
+ end
+ end
end
end
end
-# rubocop:enable Style/FrozenStringLiteralComment