Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-11 21:09:23 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-11 21:09:23 +0300
commit76e9fc7b29c1ce716c26932e9fbec0f3c99f53f4 (patch)
treeb5ca8e3a6b2cf93b67257b38ee71e2efee177700 /spec/support/shared_contexts
parenta210c43e0aca0311cc1d3d381763b25979ec72dc (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_contexts')
-rw-r--r--spec/support/shared_contexts/lib/gitlab/middleware/multipart_shared_contexts.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/support/shared_contexts/lib/gitlab/middleware/multipart_shared_contexts.rb b/spec/support/shared_contexts/lib/gitlab/middleware/multipart_shared_contexts.rb
new file mode 100644
index 00000000000..f1554ea8e9f
--- /dev/null
+++ b/spec/support/shared_contexts/lib/gitlab/middleware/multipart_shared_contexts.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+RSpec.shared_context 'multipart middleware context' do
+ let(:app) { double(:app) }
+ let(:middleware) { described_class.new(app) }
+ let(:original_filename) { 'filename' }
+
+ # Rails 5 doesn't combine the GET/POST parameters in
+ # ActionDispatch::HTTP::Parameters if action_dispatch.request.parameters is set:
+ # https://github.com/rails/rails/blob/aea6423f013ca48f7704c70deadf2cd6ac7d70a1/actionpack/lib/action_dispatch/http/parameters.rb#L41
+ def get_params(env)
+ req = ActionDispatch::Request.new(env)
+ req.GET.merge(req.POST)
+ end
+
+ def post_env(rewritten_fields, params, secret, issuer)
+ token = JWT.encode({ 'iss' => issuer, 'rewritten_fields' => rewritten_fields }, secret, 'HS256')
+ Rack::MockRequest.env_for(
+ '/',
+ method: 'post',
+ params: params,
+ described_class::RACK_ENV_KEY => token
+ )
+ end
+
+ def with_tmp_dir(uploads_sub_dir, storage_path = '')
+ Dir.mktmpdir do |dir|
+ upload_dir = File.join(dir, storage_path, uploads_sub_dir)
+ FileUtils.mkdir_p(upload_dir)
+
+ allow(Rails).to receive(:root).and_return(dir)
+ allow(Dir).to receive(:tmpdir).and_return(File.join(Dir.tmpdir, 'tmpsubdir'))
+ allow(GitlabUploader).to receive(:root).and_return(File.join(dir, storage_path))
+
+ Tempfile.open('top-level', upload_dir) do |tempfile|
+ env = post_env({ 'file' => tempfile.path }, { 'file.name' => original_filename, 'file.path' => tempfile.path }, Gitlab::Workhorse.secret, 'gitlab-workhorse')
+
+ yield dir, env
+ end
+ end
+ end
+end