From d0cf81c1cac63c28a0d67eb72e8d27679febd534 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 3 Feb 2022 11:28:34 +0000 Subject: Add latest changes from gitlab-org/security/gitlab@14-5-stable-ee --- app/finders/users_finder.rb | 2 +- app/models/user.rb | 19 +++- doc/api/members.md | 8 +- doc/api/users.md | 2 +- .../features/groups/members/manage_members_spec.rb | 4 +- spec/finders/users_finder_spec.rb | 12 +++ spec/models/user_spec.rb | 111 ++++++++++++++++++--- 7 files changed, 133 insertions(+), 25 deletions(-) diff --git a/app/finders/users_finder.rb b/app/finders/users_finder.rb index 8054ecbd502..2b4ce615090 100644 --- a/app/finders/users_finder.rb +++ b/app/finders/users_finder.rb @@ -74,7 +74,7 @@ class UsersFinder def by_search(users) return users unless params[:search].present? - users.search(params[:search]) + users.search(params[:search], with_private_emails: current_user&.admin?) end def by_blocked(users) diff --git a/app/models/user.rb b/app/models/user.rb index 3ab5b7ee364..618197e4bba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -655,6 +655,7 @@ class User < ApplicationRecord # This method uses ILIKE on PostgreSQL. # # query - The search query as a String + # with_private_emails - include private emails in search # # Returns an ActiveRecord::Relation. def search(query, **options) @@ -667,14 +668,16 @@ class User < ApplicationRecord CASE WHEN users.name = :query THEN 0 WHEN users.username = :query THEN 1 - WHEN users.email = :query THEN 2 + WHEN users.public_email = :query THEN 2 ELSE 3 END SQL sanitized_order_sql = Arel.sql(sanitize_sql_array([order, query: query])) - search_with_secondary_emails(query).reorder(sanitized_order_sql, :name) + scope = options[:with_private_emails] ? search_with_secondary_emails(query) : search_with_public_emails(query) + + scope.reorder(sanitized_order_sql, :name) end # Limits the result set to users _not_ in the given query/list of IDs. @@ -689,6 +692,18 @@ class User < ApplicationRecord reorder(:name) end + def search_with_public_emails(query) + return none if query.blank? + + query = query.downcase + + where( + fuzzy_arel_match(:name, query) + .or(fuzzy_arel_match(:username, query)) + .or(arel_table[:public_email].eq(query)) + ) + end + def search_without_secondary_emails(query) return none if query.blank? diff --git a/doc/api/members.md b/doc/api/members.md index ce276487f21..4eccd4f61de 100644 --- a/doc/api/members.md +++ b/doc/api/members.md @@ -254,11 +254,11 @@ respectively. GET /groups/:id/billable_members ``` -| Attribute | Type | Required | Description | -| --------- | ---- | -------- | ----------- | +| Attribute | Type | Required | Description | +| --------- | ---- | -------- |--------------------------------------------------------------------------------------------------------------| | `id` | integer/string | yes | The ID or [URL-encoded path of the group](index.md#namespaced-path-encoding) owned by the authenticated user | -| `search` | string | no | A query string to search for group members by name, username, or email. | -| `sort` | string | no | A query string containing parameters that specify the sort attribute and order. See supported values below.| +| `search` | string | no | A query string to search for group members by name, username, or public email. | +| `sort` | string | no | A query string containing parameters that specify the sort attribute and order. See supported values below. | The supported values for the `sort` attribute are: diff --git a/doc/api/users.md b/doc/api/users.md index d8effc4d38f..bb2c9cb2bad 100644 --- a/doc/api/users.md +++ b/doc/api/users.md @@ -39,7 +39,7 @@ GET /users ] ``` -You can also search for users by name, username, primary email, or secondary email, by using `?search=`. For example. `/users?search=John`. +You can also search for users by name, username or public email by using `?search=`. For example. `/users?search=John`. In addition, you can lookup users by username: diff --git a/spec/features/groups/members/manage_members_spec.rb b/spec/features/groups/members/manage_members_spec.rb index 38e829bafcc..36bd2b76214 100644 --- a/spec/features/groups/members/manage_members_spec.rb +++ b/spec/features/groups/members/manage_members_spec.rb @@ -129,7 +129,7 @@ RSpec.describe 'Groups > Members > Manage members' do find('[data-testid="members-token-select-input"]').set('undisclosed_email@gitlab.com') wait_for_requests - expect(page).to have_content("Jane 'invisible' Doe") + expect(page).to have_content('Invite "undisclosed_email@gitlab.com" by email') end context 'when Invite Members modal is disabled' do @@ -155,7 +155,7 @@ RSpec.describe 'Groups > Members > Manage members' do select_input.send_keys('undisclosed_email@gitlab.com') wait_for_requests - expect(page).to have_content("Jane 'invisible' Doe") + expect(page).to have_content('Invite "undisclosed_email@gitlab.com" by email') end end diff --git a/spec/finders/users_finder_spec.rb b/spec/finders/users_finder_spec.rb index b0f8b803141..fab48cf3178 100644 --- a/spec/finders/users_finder_spec.rb +++ b/spec/finders/users_finder_spec.rb @@ -39,6 +39,12 @@ RSpec.describe UsersFinder do expect(users).to contain_exactly(blocked_user) end + it 'does not filter by private emails search' do + users = described_class.new(user, search: normal_user.email).execute + + expect(users).to be_empty + end + it 'filters by blocked users' do users = described_class.new(user, blocked: true).execute @@ -135,6 +141,12 @@ RSpec.describe UsersFinder do expect(users).to contain_exactly(normal_user) end + + it 'filters by private emails search' do + users = described_class.new(admin, search: normal_user.email).execute + + expect(users).to contain_exactly(normal_user) + end end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b5d4614d206..7423e2bd4f3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2267,6 +2267,12 @@ RSpec.describe User do describe '.search' do let_it_be(:user) { create(:user, name: 'user', username: 'usern', email: 'email@example.com') } + let_it_be(:public_email) do + create(:email, :confirmed, user: user, email: 'publicemail@example.com').tap do |email| + user.update!(public_email: email.email) + end + end + let_it_be(:user2) { create(:user, name: 'user name', username: 'username', email: 'someemail@example.com') } let_it_be(:user3) { create(:user, name: 'us', username: 'se', email: 'foo@example.com') } let_it_be(:email) { create(:email, user: user, email: 'alias@example.com') } @@ -2294,30 +2300,31 @@ RSpec.describe User do end describe 'email matching' do - it 'returns users with a matching Email' do - expect(described_class.search(user.email)).to eq([user]) + it 'returns users with a matching public email' do + expect(described_class.search(user.public_email)).to match_array([user]) end - it 'does not return users with a partially matching Email' do - expect(described_class.search(user.email[1...-1])).to be_empty + it 'does not return users with a partially matching public email' do + expect(described_class.search(user.public_email[1...-1])).to be_empty end - it 'returns users with a matching Email regardless of the casing' do - expect(described_class.search(user2.email.upcase)).to eq([user2]) + it 'returns users with a matching public email regardless of the casing' do + expect(described_class.search(user.public_email.upcase)).to match_array([user]) end - end - describe 'secondary email matching' do - it 'returns users with a matching secondary email' do - expect(described_class.search(email.email)).to include(email.user) + it 'does not return users with a matching private email' do + expect(described_class.search(user.email)).to be_empty + expect(described_class.search(email.email)).to be_empty end - it 'does not return users with a matching part of secondary email' do - expect(described_class.search(email.email[1...-1])).to be_empty - end + context 'with private emails search' do + it 'returns users with matching private email' do + expect(described_class.search(user.email, with_private_emails: true)).to match_array([user]) + end - it 'returns users with a matching secondary email regardless of the casing' do - expect(described_class.search(email.email.upcase)).to include(email.user) + it 'returns users with matching private secondary email' do + expect(described_class.search(email.email, with_private_emails: true)).to match_array([user]) + end end end @@ -2418,6 +2425,80 @@ RSpec.describe User do end end + describe '.search_with_public_emails' do + let_it_be(:user) { create(:user, name: 'John Doe', username: 'john.doe', email: 'someone.1@example.com' ) } + let_it_be(:another_user) { create(:user, name: 'Albert Smith', username: 'albert.smith', email: 'another.2@example.com' ) } + let_it_be(:public_email) do + create(:email, :confirmed, user: another_user, email: 'alias@example.com').tap do |email| + another_user.update!(public_email: email.email) + end + end + + let_it_be(:secondary_email) do + create(:email, :confirmed, user: another_user, email: 'secondary@example.com') + end + + it 'returns users with a matching name' do + expect(described_class.search_with_public_emails(user.name)).to match_array([user]) + end + + it 'returns users with a partially matching name' do + expect(described_class.search_with_public_emails(user.name[0..2])).to match_array([user]) + end + + it 'returns users with a matching name regardless of the casing' do + expect(described_class.search_with_public_emails(user.name.upcase)).to match_array([user]) + end + + it 'returns users with a matching public email' do + expect(described_class.search_with_public_emails(another_user.public_email)).to match_array([another_user]) + end + + it 'does not return users with a partially matching email' do + expect(described_class.search_with_public_emails(another_user.public_email[1...-1])).to be_empty + end + + it 'returns users with a matching email regardless of the casing' do + expect(described_class.search_with_public_emails(another_user.public_email.upcase)).to match_array([another_user]) + end + + it 'returns users with a matching username' do + expect(described_class.search_with_public_emails(user.username)).to match_array([user]) + end + + it 'returns users with a partially matching username' do + expect(described_class.search_with_public_emails(user.username[0..2])).to match_array([user]) + end + + it 'returns users with a matching username regardless of the casing' do + expect(described_class.search_with_public_emails(user.username.upcase)).to match_array([user]) + end + + it 'does not return users with a matching whole private email' do + expect(described_class.search_with_public_emails(user.email)).not_to include(user) + end + + it 'does not return users with a matching whole private email' do + expect(described_class.search_with_public_emails(secondary_email.email)).to be_empty + end + + it 'does not return users with a matching part of secondary email' do + expect(described_class.search_with_public_emails(secondary_email.email[1...-1])).to be_empty + end + + it 'does not return users with a matching part of private email' do + expect(described_class.search_with_public_emails(user.email[1...-1])).to be_empty + end + + it 'returns no matches for an empty string' do + expect(described_class.search_with_public_emails('')).to be_empty + end + + it 'returns no matches for nil' do + expect(described_class.search_with_public_emails(nil)).to be_empty + end + end + describe '.search_with_secondary_emails' do let_it_be(:user) { create(:user, name: 'John Doe', username: 'john.doe', email: 'someone.1@example.com' ) } let_it_be(:another_user) { create(:user, name: 'Albert Smith', username: 'albert.smith', email: 'another.2@example.com' ) } -- cgit v1.2.1 From 62e70e991a7763959537080123f6cfb45d91170a Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 3 Feb 2022 11:34:56 +0000 Subject: Add latest changes from gitlab-org/security/gitlab@14-5-stable-ee --- Gemfile | 2 +- Gemfile.lock | 4 +- app/assets/javascripts/create_item_dropdown.js | 7 +-- .../package_registry/components/details/app.vue | 2 +- .../components/functional/delete_package.vue | 9 ++- app/controllers/jira_connect/users_controller.rb | 10 +++ app/graphql/mutations/packages/destroy.rb | 1 + app/graphql/types/project_type.rb | 6 ++ app/models/application_setting.rb | 4 ++ .../integrations/enable_ssl_verification.rb | 32 ++++++++++ app/models/concerns/integrations/has_web_hook.rb | 6 +- app/models/integrations/bamboo.rb | 3 +- app/models/integrations/buildkite.rb | 2 +- app/models/integrations/drone_ci.rb | 26 +++++--- app/models/integrations/jenkins.rb | 1 + app/models/integrations/jira.rb | 10 ++- app/models/integrations/mock_ci.rb | 23 ++++--- app/models/integrations/teamcity.rb | 18 +++++- app/models/system_note_metadata.rb | 2 +- app/services/packages/destroy_package_service.rb | 12 ++++ app/services/protected_branches/base_service.rb | 18 ------ app/services/protected_branches/create_service.rb | 2 +- app/services/protected_branches/update_service.rb | 2 +- app/services/protected_tags/create_service.rb | 2 +- app/services/protected_tags/update_service.rb | 2 +- ..._package_files_limit_to_application_settings.rb | 7 +++ ...ion_settings_package_files_limit_constraints.rb | 15 +++++ db/schema_migrations/20220113135449 | 1 + db/schema_migrations/20220113135924 | 1 + db/structure.sql | 2 + doc/api/graphql/reference/index.md | 2 + doc/api/integrations.md | 6 +- doc/api/packages.md | 14 +++++ lib/api/helpers/integrations_helpers.rb | 20 +++++- lib/api/project_packages.rb | 6 +- locale/gitlab.pot | 9 +++ spec/features/issues/notes_on_issues_spec.rb | 58 +++++++++++++++++ spec/features/projects/packages_spec.rb | 16 +++++ spec/features/protected_branches_spec.rb | 11 ++++ spec/frontend/create_item_dropdown_spec.js | 11 +++- .../components/details/app_spec.js | 4 +- .../components/functional/delete_package_spec.js | 13 ++-- spec/graphql/types/project_type_spec.rb | 41 ++++++++++++ spec/models/application_setting_spec.rb | 3 + .../integrations/enable_ssl_verification_spec.rb | 23 +++++++ spec/models/integrations/bamboo_spec.rb | 2 + spec/models/integrations/drone_ci_spec.rb | 48 ++++++++++++++ spec/models/integrations/jenkins_spec.rb | 4 ++ spec/models/integrations/jira_spec.rb | 17 +++++ spec/models/integrations/mock_ci_spec.rb | 73 ++++++++++++++++++++++ spec/models/integrations/teamcity_spec.rb | 60 +++++++++++++++--- .../api/graphql/mutations/packages/destroy_spec.rb | 14 +++++ spec/requests/api/project_packages_spec.rb | 17 +++++ .../requests/jira_connect/users_controller_spec.rb | 35 +++++++++++ .../packages/destroy_package_service_spec.rb | 18 ++++++ .../protected_branches/create_service_spec.rb | 36 ++--------- .../protected_branches/update_service_spec.rb | 33 ++-------- .../services/protected_tags/create_service_spec.rb | 14 ++++- .../services/protected_tags/update_service_spec.rb | 14 ++++- .../enable_ssl_verification_shared_context.rb | 47 ++++++++++++++ .../integrations/has_web_hook_shared_examples.rb | 10 +++ 61 files changed, 775 insertions(+), 136 deletions(-) create mode 100644 app/models/concerns/integrations/enable_ssl_verification.rb create mode 100644 db/migrate/20220113135449_add_package_files_limit_to_application_settings.rb create mode 100644 db/migrate/20220113135924_add_application_settings_package_files_limit_constraints.rb create mode 100644 db/schema_migrations/20220113135449 create mode 100644 db/schema_migrations/20220113135924 create mode 100644 spec/models/concerns/integrations/enable_ssl_verification_spec.rb create mode 100644 spec/models/integrations/mock_ci_spec.rb create mode 100644 spec/requests/jira_connect/users_controller_spec.rb create mode 100644 spec/support/shared_contexts/models/concerns/integrations/enable_ssl_verification_shared_context.rb diff --git a/Gemfile b/Gemfile index 7fa615319c4..5c4ea52e21a 100644 --- a/Gemfile +++ b/Gemfile @@ -166,7 +166,7 @@ gem 'asciidoctor', '~> 2.0.10' gem 'asciidoctor-include-ext', '~> 0.3.1', require: false gem 'asciidoctor-plantuml', '~> 0.0.12' gem 'asciidoctor-kroki', '~> 0.5.0', require: false -gem 'rouge', '~> 3.26.1' +gem 'rouge', '~> 3.27.0' gem 'truncato', '~> 0.7.11' gem 'bootstrap_form', '~> 4.2.0' gem 'nokogiri', '~> 1.11.4' diff --git a/Gemfile.lock b/Gemfile.lock index b54874e9d80..4519c375466 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1053,7 +1053,7 @@ GEM rexml (3.2.5) rinku (2.0.0) rotp (6.2.0) - rouge (3.26.1) + rouge (3.27.0) rqrcode (0.7.0) chunky_png rqrcode-rails3 (0.1.7) @@ -1597,7 +1597,7 @@ DEPENDENCIES responders (~> 3.0) retriable (~> 3.1.2) rexml (~> 3.2.5) - rouge (~> 3.26.1) + rouge (~> 3.27.0) rqrcode-rails3 (~> 0.1.7) rspec-parameterized rspec-rails (~> 5.0.1) diff --git a/app/assets/javascripts/create_item_dropdown.js b/app/assets/javascripts/create_item_dropdown.js index 1472adf458b..b39720c6094 100644 --- a/app/assets/javascripts/create_item_dropdown.js +++ b/app/assets/javascripts/create_item_dropdown.js @@ -1,4 +1,3 @@ -import { escape } from 'lodash'; import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown'; export default class CreateItemDropdown { @@ -37,14 +36,14 @@ export default class CreateItemDropdown { }, selectable: true, toggleLabel(selected) { - return selected && 'id' in selected ? escape(selected.title) : this.defaultToggleLabel; + return selected && 'id' in selected ? selected.title : this.defaultToggleLabel; }, fieldName: this.fieldName, text(item) { - return escape(item.text); + return item.text; }, id(item) { - return escape(item.id); + return item.id; }, onFilter: this.toggleCreateNewButton.bind(this), clicked: (options) => { diff --git a/app/assets/javascripts/packages_and_registries/package_registry/components/details/app.vue b/app/assets/javascripts/packages_and_registries/package_registry/components/details/app.vue index bcbeec72961..4c5ce8134ee 100644 --- a/app/assets/javascripts/packages_and_registries/package_registry/components/details/app.vue +++ b/app/assets/javascripts/packages_and_registries/package_registry/components/details/app.vue @@ -299,7 +299,7 @@ export default {