diff options
Diffstat (limited to 'spec/support/helpers/workhorse_helpers.rb')
-rw-r--r-- | spec/support/helpers/workhorse_helpers.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/spec/support/helpers/workhorse_helpers.rb b/spec/support/helpers/workhorse_helpers.rb index f16b6c1e910..7e95f49aea2 100644 --- a/spec/support/helpers/workhorse_helpers.rb +++ b/spec/support/helpers/workhorse_helpers.rb @@ -3,6 +3,8 @@ module WorkhorseHelpers extend self + UPLOAD_PARAM_NAMES = %w[name size path remote_id sha256 type].freeze + def workhorse_send_data @_workhorse_send_data ||= begin header = response.headers[Gitlab::Workhorse::SEND_DATA_HEADER] @@ -59,6 +61,7 @@ module WorkhorseHelpers file = workhorse_params.delete(key) rewritten_fields[key] = file.path if file workhorse_params = workhorse_disk_accelerated_file_params(key, file).merge(workhorse_params) + workhorse_params = workhorse_params.merge(jwt_file_upload_param(key: key, params: workhorse_params)) end headers = if send_rewritten_field @@ -74,8 +77,19 @@ module WorkhorseHelpers private - def jwt_token(data = {}) - JWT.encode({ 'iss' => 'gitlab-workhorse' }.merge(data), Gitlab::Workhorse.secret, 'HS256') + def jwt_file_upload_param(key:, params:) + upload_params = UPLOAD_PARAM_NAMES.map do |file_upload_param| + [file_upload_param, params["#{key}.#{file_upload_param}"]] + end + upload_params = upload_params.to_h.compact + + return {} if upload_params.empty? + + { "#{key}.gitlab-workhorse-upload" => jwt_token('upload' => upload_params) } + end + + def jwt_token(data = {}, issuer: 'gitlab-workhorse', secret: Gitlab::Workhorse.secret, algorithm: 'HS256') + JWT.encode({ 'iss' => issuer }.merge(data), secret, algorithm) end def workhorse_rewritten_fields_header(fields) |