Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2022-08-05 09:12:06 +00:00
parent acda833a93
commit 0c5dab41b6
45 changed files with 201 additions and 409 deletions

View File

@ -20,7 +20,7 @@ gem 'default_value_for', '~> 3.4.0'
gem 'pg', '~> 1.4.0'
gem 'rugged', '~> 1.2'
gem 'grape-path-helpers', '~> 1.7.0'
gem 'grape-path-helpers', '~> 1.7.1'
gem 'faraday', '~> 1.0'
gem 'marginalia', '~> 1.10.0'

View File

@ -601,7 +601,7 @@ GEM
grape-entity (0.10.0)
activesupport (>= 3.0.0)
multi_json (>= 1.3.2)
grape-path-helpers (1.7.0)
grape-path-helpers (1.7.1)
activesupport
grape (~> 1.3)
rake (> 12)
@ -1591,7 +1591,7 @@ DEPENDENCIES
gpgme (~> 2.0.19)
grape (~> 1.5.2)
grape-entity (~> 0.10.0)
grape-path-helpers (~> 1.7.0)
grape-path-helpers (~> 1.7.1)
grape_logging (~> 1.8)
graphiql-rails (~> 1.8)
graphlient (~> 0.5.0)

View File

@ -66,7 +66,7 @@ export default {
<template>
<div v-if="isFetchingMergeRequests || (!isFetchingMergeRequests && totalCount)">
<div class="card card-slim gl-mt-5">
<div class="card-header">
<div class="card-header gl-bg-gray-10">
<div
class="card-title gl-relative gl-display-flex gl-align-items-center gl-line-height-20 gl-font-weight-bold gl-m-0"
>

View File

@ -17,6 +17,7 @@ const mountPipelineChartsApp = (el) => {
coverageChartPath,
defaultBranch,
testRunsEmptyStateImagePath,
projectQualitySummaryFeedbackImagePath,
} = el.dataset;
const shouldRenderDoraCharts = parseBoolean(el.dataset.shouldRenderDoraCharts);
@ -37,6 +38,7 @@ const mountPipelineChartsApp = (el) => {
coverageChartPath,
defaultBranch,
testRunsEmptyStateImagePath,
projectQualitySummaryFeedbackImagePath,
},
render: (createElement) => createElement(ProjectPipelinesCharts, {}),
});

View File

@ -149,7 +149,7 @@ export default {
<div class="card card-slim gl-overflow-hidden">
<div
:class="{ 'panel-empty-heading border-bottom-0': !hasBody }"
class="card-header gl-display-flex gl-justify-content-space-between"
class="card-header gl-display-flex gl-justify-content-space-between gl-bg-gray-10"
>
<h3
class="card-title h5 position-relative gl-my-0 gl-display-flex gl-align-items-center gl-h-7"
@ -192,7 +192,7 @@ export default {
<slot name="header-actions"></slot>
</div>
<div
class="linked-issues-card-body bg-gray-light"
class="linked-issues-card-body gl-bg-gray-10"
:class="{
'gl-p-5': isFormVisible || shouldShowTokenBody,
}"

View File

@ -1,6 +1,4 @@
.sortable-container {
background-color: $gray-light;
.flex-list {
padding: 5px;
margin-bottom: 0;

View File

@ -9,7 +9,7 @@ class Admin::RunnerProjectsController < Admin::ApplicationController
def create
@runner = Ci::Runner.find(params[:runner_project][:runner_id])
if ::Ci::Runners::AssignRunnerService.new(@runner, @project, current_user).execute
if ::Ci::Runners::AssignRunnerService.new(@runner, @project, current_user).execute.success?
redirect_to edit_admin_runner_url(@runner), notice: s_('Runners|Runner assigned to project.')
else
redirect_to edit_admin_runner_url(@runner), alert: 'Failed adding runner to project'

View File

@ -15,7 +15,7 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
path = project_runners_path(project)
if ::Ci::Runners::AssignRunnerService.new(@runner, @project, current_user).execute
if ::Ci::Runners::AssignRunnerService.new(@runner, @project, current_user).execute.success?
redirect_to path, notice: s_('Runners|Runner assigned to project.')
else
assign_to_messages = @runner.errors.messages[:assign_to]

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true
module FaviconHelper
def favicon_extension_whitelist
FaviconUploader::EXTENSION_WHITELIST
def favicon_extension_allowlist
FaviconUploader::EXTENSION_ALLOWLIST
.map { |extension| "'.#{extension}'"}
.to_sentence
end

View File

@ -60,7 +60,8 @@ module Users
namespace_storage_limit_banner_info_threshold: 55, # EE-only
namespace_storage_limit_banner_warning_threshold: 56, # EE-only
namespace_storage_limit_banner_alert_threshold: 57, # EE-only
namespace_storage_limit_banner_error_threshold: 58 # EE-only
namespace_storage_limit_banner_error_threshold: 58, # EE-only
project_quality_summary_feedback: 59 # EE-only
}
validates :feature_name,

View File

@ -55,12 +55,17 @@ module BulkImports
bytes_downloaded = 0
http_client.stream(relative_url) do |chunk|
next if bytes_downloaded == 0 && [301, 302, 303, 307, 308].include?(chunk.code)
bytes_downloaded += chunk.size
validate_size!(bytes_downloaded)
raise(ServiceError, "File download error #{chunk.code}") unless chunk.code == 200
file.write(chunk)
if chunk.code == 200
file.write(chunk)
else
raise(ServiceError, "File download error #{chunk.code}")
end
end
end
rescue StandardError => e

View File

@ -13,9 +13,15 @@ module Ci
end
def execute
return false unless @user.present? && @user.can?(:assign_runner, @runner)
unless @user.present? && @user.can?(:assign_runner, @runner)
return ServiceResponse.error(message: 'user not allowed to assign runner')
end
@runner.assign_to(@project, @user)
if @runner.assign_to(@project, @user)
ServiceResponse.success
else
ServiceResponse.error(message: 'failed to assign runner')
end
end
private

View File

@ -43,7 +43,7 @@ module DesignManagement
end
# Skip attempting to process images that would be rejected by CarrierWave.
return unless DesignManagement::DesignV432x230Uploader::MIME_TYPE_WHITELIST.include?(raw_file.content_type)
return unless DesignManagement::DesignV432x230Uploader::MIME_TYPE_ALLOWLIST.include?(raw_file.content_type)
# Store and process the file
action.image_v432x230.store!(raw_file)

View File

@ -6,7 +6,7 @@ class AvatarUploader < GitlabUploader
include ObjectStorage::Concern
prepend ObjectStorage::Extension::RecordsUploads
MIME_WHITELIST = %w[image/png image/jpeg image/gif image/bmp image/tiff image/vnd.microsoft.icon].freeze
MIME_ALLOWLIST = %w[image/png image/jpeg image/gif image/bmp image/tiff image/vnd.microsoft.icon].freeze
def exists?
model.avatar.file && model.avatar.file.present?
@ -29,7 +29,7 @@ class AvatarUploader < GitlabUploader
end
def content_type_whitelist
MIME_WHITELIST
MIME_ALLOWLIST
end
private

View File

@ -20,13 +20,13 @@ module DesignManagement
#
# We currently choose not to resize `image/svg+xml` for security reasons.
# See https://gitlab.com/gitlab-org/gitlab/issues/207740#note_302766171
MIME_TYPE_WHITELIST = %w(image/png image/jpeg image/bmp image/gif).freeze
MIME_TYPE_ALLOWLIST = %w(image/png image/jpeg image/bmp image/gif).freeze
process resize_to_fit: [432, 230]
# Allow CarrierWave to reject files without correct mimetypes.
def content_type_whitelist
MIME_TYPE_WHITELIST
MIME_TYPE_ALLOWLIST
end
# Override `GitlabUploader` and always return false, otherwise local

View File

@ -1,15 +1,15 @@
# frozen_string_literal: true
class FaviconUploader < AttachmentUploader
EXTENSION_WHITELIST = %w[png ico].freeze
MIME_WHITELIST = %w[image/png image/vnd.microsoft.icon].freeze
EXTENSION_ALLOWLIST = %w[png ico].freeze
MIME_ALLOWLIST = %w[image/png image/vnd.microsoft.icon].freeze
def extension_whitelist
EXTENSION_WHITELIST
EXTENSION_ALLOWLIST
end
def content_type_whitelist
MIME_WHITELIST
MIME_ALLOWLIST
end
private

View File

@ -40,7 +40,7 @@
= f.hidden_field :favicon_cache
= f.file_field :favicon, class: '', accept: 'image/*'
.form-text.text-muted
= _("Maximum file size is 1 MB. Image size must be 32 x 32 pixels. Allowed image formats are %{favicon_extension_whitelist}.") % { favicon_extension_whitelist: favicon_extension_whitelist }
= _("Maximum file size is 1 MB. Image size must be 32 x 32 pixels. Allowed image formats are %{favicon_extension_allowlist}.") % { favicon_extension_allowlist: favicon_extension_allowlist }
%br
= _("Images with incorrect dimensions are not resized automatically, and may result in unexpected behavior.")

View File

@ -6,4 +6,5 @@
failed_pipelines_link: project_pipelines_path(@project, page: '1', scope: 'all', status: 'failed'),
coverage_chart_path: charts_project_graph_path(@project, @project.default_branch),
test_runs_empty_state_image_path: image_path('illustrations/pipeline.svg'),
project_quality_summary_feedback_image_path: image_path('illustrations/chat-bubble-sm.svg'),
default_branch: @project.default_branch } }

View File

@ -1148,6 +1148,27 @@ On a Geo primary site this error can be ignored.
This happens because GitLab is attempting to display registries from the [Geo tracking database](../../../administration/geo/index.md#geo-tracking-database) which doesn't exist on the primary site (only the original projects exist on the primary; no replicated projects are present, therefore no tracking database exists).
### Secondary site returns 400 error "Request header or cookie too large"
This error can happen when the internal URL of the primary site is incorrect.
For example, when you use a unified URL and the primary site's internal URL is also equal to the external URL. This causes a loop when a secondary site proxies requests to the primary site's internal URL.
To fix this issue, set the primary site's internal URL to a URL that is:
- Unique to the primary site.
- Accessible from all secondary sites.
1. Enter the [Rails console](../../operations/rails_console.md) on the primary site.
1. Run the following, replacing `https://unique.url.for.primary.site` with your specific internal URL.
For example, depending on your network configuration, you could use an IP address, like
`http://1.2.3.4`.
```ruby
GeoNode.where(primary: true).first.update!(internal_url: "https://unique.url.for.primary.site")
```
## Fixing client errors
### Authorization errors from LFS HTTP(S) client requests

View File

@ -20608,6 +20608,7 @@ Name of the feature that the callout is for.
| <a id="usercalloutfeaturenameenumpipeline_needs_hover_tip"></a>`PIPELINE_NEEDS_HOVER_TIP` | Callout feature name for pipeline_needs_hover_tip. |
| <a id="usercalloutfeaturenameenumpreview_user_over_limit_free_plan_alert"></a>`PREVIEW_USER_OVER_LIMIT_FREE_PLAN_ALERT` | Callout feature name for preview_user_over_limit_free_plan_alert. |
| <a id="usercalloutfeaturenameenumprofile_personal_access_token_expiry"></a>`PROFILE_PERSONAL_ACCESS_TOKEN_EXPIRY` | Callout feature name for profile_personal_access_token_expiry. |
| <a id="usercalloutfeaturenameenumproject_quality_summary_feedback"></a>`PROJECT_QUALITY_SUMMARY_FEEDBACK` | Callout feature name for project_quality_summary_feedback. |
| <a id="usercalloutfeaturenameenumregistration_enabled_callout"></a>`REGISTRATION_ENABLED_CALLOUT` | Callout feature name for registration_enabled_callout. |
| <a id="usercalloutfeaturenameenumsecurity_configuration_devops_alert"></a>`SECURITY_CONFIGURATION_DEVOPS_ALERT` | Callout feature name for security_configuration_devops_alert. |
| <a id="usercalloutfeaturenameenumsecurity_configuration_upgrade_banner"></a>`SECURITY_CONFIGURATION_UPGRADE_BANNER` | Callout feature name for security_configuration_upgrade_banner. |

View File

@ -299,22 +299,22 @@ Use this regex for commonly used test tools.
<!-- vale gitlab.Spelling = NO -->
- Simplecov (Ruby). Example: `\(\d+.\d+\%\) covered`.
- pytest-cov (Python). Example: `(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$`.
- Scoverage (Scala). Example: `Statement coverage[A-Za-z\.*]\s*:\s*([^%]+)`.
- `phpunit --coverage-text --colors=never` (PHP). Example: `^\s*Lines:\s*\d+.\d+\%`.
- gcovr (C/C++). Example: `^TOTAL.*\s+(\d+\%)$`.
- `tap --coverage-report=text-summary` (NodeJS). Example: `^Statements\s*:\s*([^%]+)`.
- `nyc npm test` (NodeJS). Example: `All files[^|]*\|[^|]*\s+([\d\.]+)`.
- `jest --ci --coverage` (NodeJS). Example: `All files[^|]*\|[^|]*\s+([\d\.]+)`.
- excoveralls (Elixir). Example: `\[TOTAL\]\s+(\d+\.\d+)%`.
- `mix test --cover` (Elixir). Example: `\d+.\d+\%\s+\|\s+Total`.
- JaCoCo (Java/Kotlin). Example: `Total.*?([0-9]{1,3})%`.
- `go test -cover` (Go). Example: `coverage: \d+.\d+% of statements`.
- .NET (OpenCover). Example: `(Visited Points).*\((.*)\)`.
- .NET (`dotnet test` line coverage). Example: `Total\s*\|\s*(\d+(?:\.\d+)?)`.
- tarpaulin (Rust). Example: `^\d+.\d+% coverage`.
- Pester (PowerShell). Example: `Covered (\d+\.\d+%)`.
- Simplecov (Ruby). Example: `/\(\d+.\d+\%\) covered/`.
- pytest-cov (Python). Example: `/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/`.
- Scoverage (Scala). Example: `/Statement coverage[A-Za-z\.*]\s*:\s*([^%]+)/`.
- `phpunit --coverage-text --colors=never` (PHP). Example: `/^\s*Lines:\s*\d+.\d+\%/`.
- gcovr (C/C++). Example: `/^TOTAL.*\s+(\d+\%)$/`.
- `tap --coverage-report=text-summary` (NodeJS). Example: `/^Statements\s*:\s*([^%]+)/`.
- `nyc npm test` (NodeJS). Example: `/All files[^|]*\|[^|]*\s+([\d\.]+)/`.
- `jest --ci --coverage` (NodeJS). Example: `/All files[^|]*\|[^|]*\s+([\d\.]+)/`.
- excoveralls (Elixir). Example: `/\[TOTAL\]\s+(\d+\.\d+)%/`.
- `mix test --cover` (Elixir). Example: `/\d+.\d+\%\s+\|\s+Total/`.
- JaCoCo (Java/Kotlin). Example: `/Total.*?([0-9]{1,3})%/`.
- `go test -cover` (Go). Example: `/coverage: \d+.\d+% of statements/`.
- .NET (OpenCover). Example: `/(Visited Points).*\((.*)\)/`.
- .NET (`dotnet test` line coverage). Example: `/Total\s*\|\s*(\d+(?:\.\d+)?)/`.
- tarpaulin (Rust). Example: `/^\d+.\d+% coverage/`.
- Pester (PowerShell). Example: `/Covered (\d+\.\d+%)/`.
<!-- vale gitlab.Spelling = YES -->

View File

@ -188,7 +188,7 @@ module API
runner = get_runner(params[:runner_id])
authenticate_enable_runner!(runner)
if ::Ci::Runners::AssignRunnerService.new(runner, user_project, current_user).execute
if ::Ci::Runners::AssignRunnerService.new(runner, user_project, current_user).execute.success?
present runner, with: Entities::Ci::Runner
else
render_validation_error!(runner)

View File

@ -101,22 +101,19 @@ module BulkImports
def default_options
{
headers: request_headers,
follow_redirects: false
headers: { 'Content-Type' => 'application/json' },
query: request_query,
follow_redirects: true,
resend_on_redirect: false,
limit: 2
}
end
def request_query
{
page: @page,
per_page: @per_page
}
end
def request_headers
{
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{@token}"
per_page: @per_page,
private_token: @token
}
end

View File

@ -24256,7 +24256,7 @@ msgstr ""
msgid "Maximum file size indexed (KiB)"
msgstr ""
msgid "Maximum file size is 1 MB. Image size must be 32 x 32 pixels. Allowed image formats are %{favicon_extension_whitelist}."
msgid "Maximum file size is 1 MB. Image size must be 32 x 32 pixels. Allowed image formats are %{favicon_extension_allowlist}."
msgstr ""
msgid "Maximum file size is 1MB. Pages are optimized for a 24px tall header logo"
@ -30484,6 +30484,9 @@ msgstr ""
msgid "ProjectQualitySummary|Get insight into the overall percentage of tests in your project that succeed, fail and are skipped."
msgstr ""
msgid "ProjectQualitySummary|Help us improve this page"
msgstr ""
msgid "ProjectQualitySummary|Latest pipeline results"
msgstr ""
@ -30496,6 +30499,9 @@ msgstr ""
msgid "ProjectQualitySummary|Measure of how much of your code is covered by tests."
msgstr ""
msgid "ProjectQualitySummary|Provide feedback"
msgstr ""
msgid "ProjectQualitySummary|See full report"
msgstr ""
@ -30523,6 +30529,9 @@ msgstr ""
msgid "ProjectQualitySummary|The percentage of tests that succeed, fail, or are skipped."
msgstr ""
msgid "ProjectQualitySummary|This page helps you understand the code testing trends for your project. Let us know how we can improve it!"
msgstr ""
msgid "ProjectSelect| or group"
msgstr ""

View File

@ -3,7 +3,7 @@
require 'airborne'
module QA
RSpec.describe 'Package', only: { subdomain: %i[staging pre] } do
RSpec.describe 'Package', :reliable, only: { subdomain: %i[staging pre] } do
include Support::API
include Support::Helpers::MaskToken

View File

@ -20,7 +20,7 @@ module RuboCop
being scheduled, please disable this cop with a comment explaing which
context will be applied.
Read more about it https://docs.gitlab.com/ee/development/sidekiq_style_guide.html#worker-context
Read more about it https://docs.gitlab.com/ee/development/sidekiq/logging.html#worker-context
MSG
BACKGROUND_MIGRATION_WORKER_NAMES = %w[BackgroundMigrationWorker CiDatabaseWorker].freeze

View File

@ -1,27 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::PipelineCreatedEvent do
using RSpec::Parameterized::TableSyntax
where(:data, :valid) do
{ pipeline_id: 1 } | true
{ pipeline_id: nil } | false
{ pipeline_id: "test" } | false
{} | false
{ job_id: 1 } | false
end
with_them do
let(:event) { described_class.new(data: data) }
it 'validates the data according to the schema' do
if valid
expect { event }.not_to raise_error
else
expect { event }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end

View File

@ -1,35 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Pages::PageDeletedEvent do
where(:data, :valid) do
[
[{ project_id: 1, namespace_id: 2 }, true],
[{ project_id: 1, namespace_id: 2, root_namespace_id: 3 }, true],
[{ project_id: 1 }, false],
[{ namespace_id: 1 }, false],
[{ project_id: 'foo', namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: 'foo' }, false],
[{ project_id: [], namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: [] }, false],
[{ project_id: {}, namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: {} }, false],
['foo', false],
[123, false],
[[], false]
]
end
with_them do
it 'validates data' do
constructor = -> { described_class.new(data: data) }
if valid
expect { constructor.call }.not_to raise_error
else
expect { constructor.call }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end

View File

@ -1,34 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Pages::PageDeployedEvent do
where(:data, :valid) do
[
[{ project_id: 1, namespace_id: 2, root_namespace_id: 3 }, true],
[{ project_id: 1 }, false],
[{ namespace_id: 1 }, false],
[{ project_id: 'foo', namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: 'foo' }, false],
[{ project_id: [], namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: [] }, false],
[{ project_id: {}, namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: {} }, false],
['foo', false],
[123, false],
[[], false]
]
end
with_them do
it 'validates data' do
constructor = -> { described_class.new(data: data) }
if valid
expect { constructor.call }.not_to raise_error
else
expect { constructor.call }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end

View File

@ -1,44 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ProjectArchivedEvent do
subject(:constructor) { described_class.new(data: data) }
where(:data, :valid) do
valid_event = {
project_id: 1,
namespace_id: 2,
root_namespace_id: 3
}
# All combinations of missing keys
with_missing_keys = 0.upto(valid_event.size - 1)
.flat_map { |size| valid_event.keys.combination(size).to_a }
.map { |keys| [valid_event.slice(*keys), false] }
[
[valid_event, true],
*with_missing_keys,
[{ project_id: 'foo', namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: 'foo' }, false],
[{ project_id: [], namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: [] }, false],
[{ project_id: {}, namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: {} }, false],
['foo', false],
[123, false],
[[], false]
]
end
with_them do
it 'validates data' do
if valid
expect { constructor }.not_to raise_error
else
expect { constructor }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end

View File

@ -1,34 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ProjectCreatedEvent do
where(:data, :valid) do
[
[{ project_id: 1, namespace_id: 2, root_namespace_id: 3 }, true],
[{ project_id: 1 }, false],
[{ namespace_id: 1 }, false],
[{ project_id: 'foo', namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: 'foo' }, false],
[{ project_id: [], namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: [] }, false],
[{ project_id: {}, namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: {} }, false],
['foo', false],
[123, false],
[[], false]
]
end
with_them do
it 'validates data' do
constructor = -> { described_class.new(data: data) }
if valid
expect { constructor.call }.not_to raise_error
else
expect { constructor.call }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end

View File

@ -1,35 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ProjectDeletedEvent do
where(:data, :valid) do
[
[{ project_id: 1, namespace_id: 2 }, true],
[{ project_id: 1, namespace_id: 2, root_namespace_id: 3 }, true],
[{ project_id: 1 }, false],
[{ namespace_id: 1 }, false],
[{ project_id: 'foo', namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: 'foo' }, false],
[{ project_id: [], namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: [] }, false],
[{ project_id: {}, namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: {} }, false],
['foo', false],
[123, false],
[[], false]
]
end
with_them do
it 'validates data' do
constructor = -> { described_class.new(data: data) }
if valid
expect { constructor.call }.not_to raise_error
else
expect { constructor.call }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end

View File

@ -1,46 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ProjectPathChangedEvent do
where(:data, :valid) do
valid_event = {
project_id: 1,
namespace_id: 2,
root_namespace_id: 3,
old_path: 'old',
new_path: 'new'
}
# All combinations of missing keys
with_missing_keys = 0.upto(valid_event.size - 1)
.flat_map { |size| valid_event.keys.combination(size).to_a }
.map { |keys| [valid_event.slice(*keys), false] }
[
[valid_event, true],
*with_missing_keys,
[{ project_id: 'foo', namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: 'foo' }, false],
[{ project_id: [], namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: [] }, false],
[{ project_id: {}, namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: {} }, false],
['foo', false],
[123, false],
[[], false]
]
end
with_them do
it 'validates data' do
constructor = -> { described_class.new(data: data) }
if valid
expect { constructor.call }.not_to raise_error
else
expect { constructor.call }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end

View File

@ -1,46 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ProjectTransferedEvent do
where(:data, :valid) do
valid_event = {
project_id: 1,
old_namespace_id: 2,
old_root_namespace_id: 3,
new_namespace_id: 4,
new_root_namespace_id: 5
}
# All combinations of missing keys
with_missing_keys = 0.upto(valid_event.size - 1)
.flat_map { |size| valid_event.keys.combination(size).to_a }
.map { |keys| [valid_event.slice(*keys), false] }
[
[valid_event, true],
*with_missing_keys,
[{ project_id: 'foo', namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: 'foo' }, false],
[{ project_id: [], namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: [] }, false],
[{ project_id: {}, namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: {} }, false],
['foo', false],
[123, false],
[[], false]
]
end
with_them do
it 'validates data' do
constructor = -> { described_class.new(data: data) }
if valid
expect { constructor.call }.not_to raise_error
else
expect { constructor.call }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end

View File

@ -56,15 +56,17 @@ RSpec.describe BulkImports::Clients::HTTP do
[
'http://gitlab.example/api/v4/resource',
hash_including(
follow_redirects: false,
query: {
page: described_class::DEFAULT_PAGE,
per_page: described_class::DEFAULT_PER_PAGE
per_page: described_class::DEFAULT_PER_PAGE,
private_token: token
},
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{token}"
}
'Content-Type' => 'application/json'
},
follow_redirects: true,
resend_on_redirect: false,
limit: 2
)
]
end
@ -106,12 +108,13 @@ RSpec.describe BulkImports::Clients::HTTP do
def stub_http_get(path, query, response)
uri = "http://gitlab.example/api/v4/#{path}"
params = {
follow_redirects: false,
headers: {
"Authorization" => "Bearer token",
"Content-Type" => "application/json"
}
}.merge(query: query)
headers: { "Content-Type" => "application/json" },
query: { private_token: token },
follow_redirects: true,
resend_on_redirect: false,
limit: 2
}
params[:query] = params[:query].merge(query)
allow(Gitlab::HTTP).to receive(:get).with(uri, params).and_return(response)
end
@ -127,11 +130,17 @@ RSpec.describe BulkImports::Clients::HTTP do
'http://gitlab.example/api/v4/resource',
hash_including(
body: {},
follow_redirects: false,
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{token}"
}
'Content-Type' => 'application/json'
},
query: {
page: described_class::DEFAULT_PAGE,
per_page: described_class::DEFAULT_PER_PAGE,
private_token: token
},
follow_redirects: true,
resend_on_redirect: false,
limit: 2
)
]
end
@ -146,11 +155,17 @@ RSpec.describe BulkImports::Clients::HTTP do
[
'http://gitlab.example/api/v4/resource',
hash_including(
follow_redirects: false,
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{token}"
}
'Content-Type' => 'application/json'
},
query: {
page: described_class::DEFAULT_PAGE,
per_page: described_class::DEFAULT_PER_PAGE,
private_token: token
},
follow_redirects: true,
resend_on_redirect: false,
limit: 2
)
]
end
@ -164,9 +179,16 @@ RSpec.describe BulkImports::Clients::HTTP do
hash_including(
stream_body: true,
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{token}"
}
'Content-Type' => 'application/json'
},
query: {
page: described_class::DEFAULT_PAGE,
per_page: described_class::DEFAULT_PER_PAGE,
private_token: token
},
follow_redirects: true,
resend_on_redirect: false,
limit: 2
)
]

View File

@ -136,14 +136,45 @@ RSpec.describe BulkImports::FileDownloadService do
end
context 'when chunk code is not 200' do
let(:chunk_double) { double('chunk', size: 1000, code: 307) }
let(:chunk_double) { double('chunk', size: 1000, code: 500) }
it 'raises an error' do
expect { subject.execute }.to raise_error(
described_class::ServiceError,
'File download error 307'
'File download error 500'
)
end
context 'when chunk code is redirection' do
let(:chunk_double) { double('redirection', size: 1000, code: 303) }
it 'does not write a redirection chunk' do
expect { subject.execute }.not_to raise_error
expect(File.read(filepath)).not_to include('redirection')
end
context 'when redirection chunk appears at a later stage of the download' do
it 'raises an error' do
another_chunk_double = double('another redirection', size: 1000, code: 303)
data_chunk = double('data chunk', size: 1000, code: 200)
allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
allow(client).to receive(:head).and_return(response_double)
allow(client)
.to receive(:stream)
.and_yield(chunk_double)
.and_yield(data_chunk)
.and_yield(another_chunk_double)
end
expect { subject.execute }.to raise_error(
described_class::ServiceError,
'File download error 303'
)
end
end
end
end
context 'when file is a symlink' do

View File

@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe ::Ci::Runners::AssignRunnerService, '#execute' do
subject { described_class.new(runner, project, user).execute }
subject(:execute) { described_class.new(runner, project, user).execute }
let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) }
let_it_be(:project) { create(:project) }
@ -11,30 +11,32 @@ RSpec.describe ::Ci::Runners::AssignRunnerService, '#execute' do
context 'without user' do
let(:user) { nil }
it 'does not call assign_to on runner and returns false' do
it 'does not call assign_to on runner and returns error response', :aggregate_failures do
expect(runner).not_to receive(:assign_to)
is_expected.to eq(false)
is_expected.to be_error
expect(execute.message).to eq('user not allowed to assign runner')
end
end
context 'with unauthorized user' do
let(:user) { build(:user) }
it 'does not call assign_to on runner and returns false' do
it 'does not call assign_to on runner and returns error message' do
expect(runner).not_to receive(:assign_to)
is_expected.to eq(false)
is_expected.to be_error
expect(execute.message).to eq('user not allowed to assign runner')
end
end
context 'with admin user', :enable_admin_mode do
let(:user) { create_default(:user, :admin) }
it 'calls assign_to on runner and returns value unchanged' do
expect(runner).to receive(:assign_to).with(project, user).once.and_return('assign_to return value')
it 'calls assign_to on runner and returns success response' do
expect(runner).to receive(:assign_to).with(project, user).once.and_call_original
is_expected.to eq('assign_to return value')
is_expected.to be_success
end
end
end

View File

@ -16,7 +16,7 @@ RSpec.describe DesignManagement::GenerateImageVersionsService do
end
it 'skips generating image versions if the mime type is not whitelisted' do
stub_const('DesignManagement::DesignV432x230Uploader::MIME_TYPE_WHITELIST', [])
stub_const('DesignManagement::DesignV432x230Uploader::MIME_TYPE_ALLOWLIST', [])
described_class.new(version).execute

View File

@ -12,17 +12,17 @@ RSpec.shared_context 'bulk imports requests context' do |url|
}
end
let(:request_headers) { { 'Authorization' => 'Bearer demo-pat', 'Content-Type' => 'application/json' } }
let(:request_headers) { { 'Content-Type' => 'application/json' } }
before do
stub_request(:get, "#{url}/api/v4/version")
stub_request(:get, "#{url}/api/v4/version?page=1&per_page=20&private_token=demo-pat")
.with(headers: request_headers)
.to_return(
status: 200,
body: { version: ::BulkImport.min_gl_version_for_project_migration.to_s }.to_json,
headers: { 'Content-Type' => 'application/json' })
stub_request(:get, "https://gitlab.example.com/api/v4/groups?min_access_level=50&page=1&per_page=20&search=test&top_level_only=true")
stub_request(:get, "https://gitlab.example.com/api/v4/groups?min_access_level=50&page=1&per_page=20&private_token=demo-pat&search=test&top_level_only=true")
.with(headers: request_headers)
.to_return(status: 200,
body: [{
@ -33,10 +33,9 @@ RSpec.shared_context 'bulk imports requests context' do |url|
full_name: 'Test',
full_path: 'stub-test-group'
}].to_json,
headers: page_response_headers
)
headers: page_response_headers)
stub_request(:get, "%{url}/api/v4/groups?page=1&per_page=20&top_level_only=true&min_access_level=50&search=" % { url: url })
stub_request(:get, "%{url}/api/v4/groups?min_access_level=50&page=1&per_page=20&private_token=demo-pat&search=&top_level_only=true" % { url: url })
.to_return(
body: [{
id: 2595438,
@ -46,7 +45,6 @@ RSpec.shared_context 'bulk imports requests context' do |url|
full_name: 'Stub',
full_path: 'stub-group'
}].to_json,
headers: page_response_headers
)
headers: page_response_headers)
end
end

View File

@ -3,7 +3,7 @@
# Construct an `uploader` variable that is configured to `check_upload_type`
# with `mime_types` and `extensions`.
# @param uploader [CarrierWave::Uploader::Base] uploader with extension_whitelist method.
RSpec.shared_context 'ignore extension whitelist check' do
RSpec.shared_context 'ignore extension allowlist check' do
before do
allow(uploader).to receive(:extension_whitelist).and_return(nil)
end

View File

@ -46,7 +46,7 @@ RSpec.describe Quality::TestLevel do
context 'when level is unit' do
it 'returns a pattern' do
expect(subject.pattern(:unit))
.to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,events,factories,finders,frontend,graphql,haml_lint,helpers,initializers,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling,components}{,/**/}*_spec.rb")
.to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,factories,finders,frontend,graphql,haml_lint,helpers,initializers,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling,components}{,/**/}*_spec.rb")
end
end
@ -121,7 +121,7 @@ RSpec.describe Quality::TestLevel do
context 'when level is unit' do
it 'returns a regexp' do
expect(subject.regexp(:unit))
.to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|events|factories|finders|frontend|graphql|haml_lint|helpers|initializers|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling|components)/})
.to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|factories|finders|frontend|graphql|haml_lint|helpers|initializers|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling|components)/})
end
end

View File

@ -52,7 +52,7 @@ RSpec.describe AvatarUploader do
# in a stub below so we can set any path.
let_it_be(:path) { File.join('spec', 'fixtures', 'video_sample.mp4') }
where(:mime_type) { described_class::MIME_WHITELIST }
where(:mime_type) { described_class::MIME_ALLOWLIST }
with_them do
include_context 'force content type detection to mime_type'

View File

@ -63,7 +63,7 @@ RSpec.describe DesignManagement::DesignV432x230Uploader do
# in a stub below so we can set any path.
let_it_be(:path) { File.join('spec', 'fixtures', 'dk.png') }
where(:mime_type) { described_class::MIME_TYPE_WHITELIST }
where(:mime_type) { described_class::MIME_TYPE_ALLOWLIST }
with_them do
include_context 'force content type detection to mime_type'

View File

@ -7,13 +7,13 @@ RSpec.describe FaviconUploader do
let_it_be(:uploader) { described_class.new(model, :favicon) }
context 'accept whitelist file content type' do
include_context 'ignore extension whitelist check'
include_context 'ignore extension allowlist check'
# We need to feed through a valid path, but we force the parsed mime type
# in a stub below so we can set any path.
let_it_be(:path) { File.join('spec', 'fixtures', 'video_sample.mp4') }
where(:mime_type) { described_class::MIME_WHITELIST }
where(:mime_type) { described_class::MIME_ALLOWLIST }
with_them do
include_context 'force content type detection to mime_type'
@ -23,7 +23,7 @@ RSpec.describe FaviconUploader do
end
context 'upload non-whitelisted file content type' do
include_context 'ignore extension whitelist check'
include_context 'ignore extension allowlist check'
let_it_be(:path) { File.join('spec', 'fixtures', 'sanitized.svg') }
@ -31,7 +31,7 @@ RSpec.describe FaviconUploader do
end
context 'upload misnamed non-whitelisted file content type' do
include_context 'ignore extension whitelist check'
include_context 'ignore extension allowlist check'
let_it_be(:path) { File.join('spec', 'fixtures', 'not_a_png.png') }

View File

@ -24,7 +24,6 @@ module Quality
elastic
elastic_integration
experiments
events
factories
finders
frontend