diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-27 12:10:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-27 12:10:57 +0300 |
commit | 8588e8b9316538f27f45a6e380bd0663bb509d66 (patch) | |
tree | bc21491da572a50168362fa9ea4bf25be0bc97a0 /spec | |
parent | e75ebe6f6e08c3137a330e579dbd96dceb0561f9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
34 files changed, 216 insertions, 109 deletions
diff --git a/spec/controllers/passwords_controller_spec.rb b/spec/controllers/passwords_controller_spec.rb index e4be2fbef3c..9494f55c631 100644 --- a/spec/controllers/passwords_controller_spec.rb +++ b/spec/controllers/passwords_controller_spec.rb @@ -78,6 +78,22 @@ RSpec.describe PasswordsController do end end + context 'password is weak' do + let(:password) { "password" } + + it 'tracks the event' do + subject + + expect(response.body).to have_content("must not contain commonly used combinations of words and letters") + expect_snowplow_event( + category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', + action: 'track_weak_password_error', + controller: 'PasswordsController', + method: 'create' + ) + end + end + it 'sets the username and caller_id in the context' do expect(controller).to receive(:update).and_wrap_original do |m, *args| m.call(*args) diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index ceb00660658..119a7be25ef 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -492,6 +492,16 @@ RSpec.describe RegistrationsController do expect(response).to render_template(:new) expect(response.body).to include(_('Password must not contain commonly used combinations of words and letters')) end + + it 'tracks the error' do + subject + expect_snowplow_event( + category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', + action: 'track_weak_password_error', + controller: 'RegistrationsController', + method: 'create' + ) + end end context 'when block_weak_passwords is disabled' do @@ -504,6 +514,16 @@ RSpec.describe RegistrationsController do end end end + + context 'when the password is not weak' do + it 'does not track a weak password error' do + subject + expect_no_snowplow_event( + category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', + action: 'track_weak_password_error' + ) + end + end end describe '#destroy' do diff --git a/spec/features/profiles/password_spec.rb b/spec/features/profiles/password_spec.rb index 6c860740354..8887ff1746d 100644 --- a/spec/features/profiles/password_spec.rb +++ b/spec/features/profiles/password_spec.rb @@ -152,6 +152,33 @@ RSpec.describe 'Profile > Password' do it_behaves_like 'user enters an incorrect current password' end + context 'when the password is too weak' do + let(:new_password) { 'password' } + + subject do + page.within '.update-password' do + fill_in "user_password", with: user.password + fill_passwords(new_password, new_password) + end + end + + it 'tracks the error and does not change the password', :aggregate_failures do + expect { subject }.not_to change { user.reload.valid_password?(new_password) } + expect(user.failed_attempts).to eq(0) + + page.within '.gl-alert-danger' do + expect(page).to have_content('must not contain commonly used combinations of words and letters') + end + + expect_snowplow_event( + category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', + action: 'track_weak_password_error', + controller: 'Profiles::PasswordsController', + method: 'update' + ) + end + end + context 'when the password reset is successful' do subject do page.within '.update-password' do @@ -195,6 +222,23 @@ RSpec.describe 'Profile > Password' do expect(page).to have_current_path new_user_session_path, ignore_query: true end + it 'tracks weak password error' do + visit edit_profile_password_path + + expect(page).to have_current_path new_profile_password_path, ignore_query: true + + fill_in :user_password, with: user.password + fill_in :user_new_password, with: "password" + fill_in :user_password_confirmation, with: "password" + click_button 'Set new password' + expect_snowplow_event( + category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', + action: 'track_weak_password_error', + controller: 'Profiles::PasswordsController', + method: 'create' + ) + end + context 'when global require_two_factor_authentication is enabled' do it 'needs change user password' do stub_application_setting(require_two_factor_authentication: true) diff --git a/spec/frontend/ci_variable_list/components/ci_variable_popover_spec.js b/spec/frontend/ci_variable_list/components/ci_variable_popover_spec.js deleted file mode 100644 index 4d0c378d10e..00000000000 --- a/spec/frontend/ci_variable_list/components/ci_variable_popover_spec.js +++ /dev/null @@ -1,48 +0,0 @@ -import { GlButton } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; -import CiVariablePopover from '~/ci_variable_list/components/ci_variable_popover.vue'; -import mockData from '../services/mock_data'; - -describe('Ci Variable Popover', () => { - let wrapper; - - const defaultProps = { - target: 'ci-variable-value-22', - value: mockData.mockPemCert, - tooltipText: 'Copy value', - }; - - const createComponent = (props = defaultProps) => { - wrapper = shallowMount(CiVariablePopover, { - propsData: { ...props }, - }); - }; - - const findButton = () => wrapper.findComponent(GlButton); - - beforeEach(() => { - createComponent(); - }); - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - it('displays max count plus ... when character count is over 95', () => { - expect(wrapper.text()).toHaveLength(98); - }); - - it('copies full value to clipboard', () => { - expect(findButton().attributes('data-clipboard-text')).toEqual(mockData.mockPemCert); - }); - - it('displays full value when count is less than max count', () => { - createComponent({ - target: 'ci-variable-value-22', - value: 'test_variable_value', - tooltipText: 'Copy value', - }); - expect(wrapper.text()).toEqual('test_variable_value'); - }); -}); diff --git a/spec/lib/gitlab/tracking/helpers/weak_password_error_event_spec.rb b/spec/lib/gitlab/tracking/helpers/weak_password_error_event_spec.rb new file mode 100644 index 00000000000..3df10f79e98 --- /dev/null +++ b/spec/lib/gitlab/tracking/helpers/weak_password_error_event_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Tracking::Helpers::WeakPasswordErrorEvent do + let(:user) { build(:user) } + + subject(:helper) { Class.new.include(described_class).new } + + context "when user has a weak password error" do + before do + user.password = "password" + user.valid? + end + + it "tracks the event" do + helper.track_weak_password_error(user, 'A', 'B') + expect_snowplow_event( + category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', + action: 'track_weak_password_error', + controller: 'A', + method: 'B' + ) + end + end + + context "when user does not have a weak password error" do + before do + user.password = "short" + user.valid? + end + + it "does not track the event" do + helper.track_weak_password_error(user, 'A', 'B') + expect_no_snowplow_event + end + end + + context "when user does not have any errors" do + it "does not track the event" do + helper.track_weak_password_error(user, 'A', 'B') + expect_no_snowplow_event + end + end +end diff --git a/spec/models/ci/bridge_spec.rb b/spec/models/ci/bridge_spec.rb index 44a6bec0130..7fbf0ede75b 100644 --- a/spec/models/ci/bridge_spec.rb +++ b/spec/models/ci/bridge_spec.rb @@ -309,7 +309,7 @@ RSpec.describe Ci::Bridge do end context 'when the pipeline runs from a pipeline schedule' do - let(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project ) } + let(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project) } let(:pipeline) { create(:ci_pipeline, pipeline_schedule: pipeline_schedule) } let(:options) do diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index d9fb225e8c0..9c83c1df10c 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1763,7 +1763,7 @@ RSpec.describe Ci::Build do context 'and start action is defined' do before do - build.update!(options: { environment: { action: 'start' } } ) + build.update!(options: { environment: { action: 'start' } }) end it { is_expected.to be_truthy } @@ -1793,7 +1793,7 @@ RSpec.describe Ci::Build do context 'and stop action is defined' do before do - build.update!(options: { environment: { action: 'stop' } } ) + build.update!(options: { environment: { action: 'stop' } }) end it { is_expected.to be_truthy } diff --git a/spec/models/ci/build_trace_spec.rb b/spec/models/ci/build_trace_spec.rb index f2df4874b84..907b49dc180 100644 --- a/spec/models/ci/build_trace_spec.rb +++ b/spec/models/ci/build_trace_spec.rb @@ -38,9 +38,9 @@ RSpec.describe Ci::BuildTrace do let(:data) { StringIO.new("UTF-8 dashes here: āāā\nš¤š¤š¤š¤\xF0\x9F\x90\n") } it 'returns valid UTF-8 data', :aggregate_failures do - expect(subject.lines[0]).to eq({ offset: 0, content: [{ text: 'UTF-8 dashes here: āāā' }] } ) + expect(subject.lines[0]).to eq({ offset: 0, content: [{ text: 'UTF-8 dashes here: āāā' }] }) # Each of the dashes is 3 bytes, so we get 19 + 9 + 1 = 29 - expect(subject.lines[1]).to eq({ offset: 29, content: [{ text: 'š¤š¤š¤š¤ļæ½' }] } ) + expect(subject.lines[1]).to eq({ offset: 29, content: [{ text: 'š¤š¤š¤š¤ļæ½' }] }) end end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index b98772df47f..68dfcdbd85a 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -4173,7 +4173,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do let(:pipeline) { create(:ci_pipeline) } let!(:old_job) { create(:ci_build, name: 'rspec', retried: true, pipeline: pipeline) } let!(:job_without_artifacts) { create(:ci_build, name: 'rspec', pipeline: pipeline) } - let!(:expected_job) { create(:ci_build, :artifacts, name: 'rspec', pipeline: pipeline ) } + let!(:expected_job) { create(:ci_build, :artifacts, name: 'rspec', pipeline: pipeline) } let!(:different_job) { create(:ci_build, name: 'deploy', pipeline: pipeline) } subject { pipeline.find_job_with_archive_artifacts('rspec') } diff --git a/spec/models/ci/secure_file_spec.rb b/spec/models/ci/secure_file_spec.rb index 20f64d40865..2445babb5f2 100644 --- a/spec/models/ci/secure_file_spec.rb +++ b/spec/models/ci/secure_file_spec.rb @@ -131,7 +131,7 @@ RSpec.describe Ci::SecureFile do describe '#update_metadata!' do it 'assigns the expected metadata when a parsable file is supplied' do file = create(:ci_secure_file, name: 'file1.cer', - file: CarrierWaveStringFile.new(fixture_file('ci_secure_files/sample.cer') )) + file: CarrierWaveStringFile.new(fixture_file('ci_secure_files/sample.cer'))) file.update_metadata! expect(file.expires_at).to eq(DateTime.parse('2022-04-26 19:20:40')) diff --git a/spec/models/ci/trigger_request_spec.rb b/spec/models/ci/trigger_request_spec.rb index 0d462741089..a6e8e8496ac 100644 --- a/spec/models/ci/trigger_request_spec.rb +++ b/spec/models/ci/trigger_request_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Ci::TriggerRequest do describe 'validation' do it 'be invalid if saving a variable' do - trigger = build(:ci_trigger_request, variables: { TRIGGER_KEY_1: 'TRIGGER_VALUE_1' } ) + trigger = build(:ci_trigger_request, variables: { TRIGGER_KEY_1: 'TRIGGER_VALUE_1' }) expect(trigger).not_to be_valid end diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index 549a273e2d7..b60c5ec114d 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -130,7 +130,7 @@ RSpec.describe Clusters::Applications::Prometheus do end context 'with knative installed' do - let(:knative) { create(:clusters_applications_knative, :updated ) } + let(:knative) { create(:clusters_applications_knative, :updated) } let(:prometheus) { create(:clusters_applications_prometheus, cluster: knative.cluster) } subject { prometheus.install_command } @@ -161,7 +161,7 @@ RSpec.describe Clusters::Applications::Prometheus do end describe '#predelete' do - let(:knative) { create(:clusters_applications_knative, :updated ) } + let(:knative) { create(:clusters_applications_knative, :updated) } let(:prometheus) { create(:clusters_applications_prometheus, cluster: knative.cluster) } subject { prometheus.uninstall_command.predelete } diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb index 635326eeadc..04763accc42 100644 --- a/spec/models/deploy_token_spec.rb +++ b/spec/models/deploy_token_spec.rb @@ -427,7 +427,7 @@ RSpec.describe DeployToken do end describe '.gitlab_deploy_token' do - let(:project) { create(:project ) } + let(:project) { create(:project) } subject { project.deploy_tokens.gitlab_deploy_token } diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index a442856d993..8a3d43f58e0 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -884,8 +884,8 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do describe '#actions_for' do let(:deployment) { create(:deployment, :success, environment: environment) } let(:pipeline) { deployment.deployable.pipeline } - let!(:review_action) { create(:ci_build, :manual, name: 'review-apps', pipeline: pipeline, environment: 'review/$CI_COMMIT_REF_NAME' ) } - let!(:production_action) { create(:ci_build, :manual, name: 'production', pipeline: pipeline, environment: 'production' ) } + let!(:review_action) { create(:ci_build, :manual, name: 'review-apps', pipeline: pipeline, environment: 'review/$CI_COMMIT_REF_NAME') } + let!(:production_action) { create(:ci_build, :manual, name: 'production', pipeline: pipeline, environment: 'production') } it 'returns a list of actions with matching environment' do expect(environment.actions_for('review/master')).to contain_exactly(review_action) diff --git a/spec/models/environment_status_spec.rb b/spec/models/environment_status_spec.rb index a9aa5698ebb..2f1edf9ab94 100644 --- a/spec/models/environment_status_spec.rb +++ b/spec/models/environment_status_spec.rb @@ -37,7 +37,7 @@ RSpec.describe EnvironmentStatus do context 'multiple deployments' do it { - new_deployment = create(:deployment, :succeed, environment: deployment.environment, sha: deployment.sha ) + new_deployment = create(:deployment, :succeed, environment: deployment.environment, sha: deployment.sha) is_expected.to eq(new_deployment) } end diff --git a/spec/models/experiment_spec.rb b/spec/models/experiment_spec.rb index 0f9d5bf3c2d..dc740ce8b0f 100644 --- a/spec/models/experiment_spec.rb +++ b/spec/models/experiment_spec.rb @@ -54,7 +54,7 @@ RSpec.describe Experiment do end context 'with an existing context' do - let(:experiment_subject) { create(:experiment_subject, experiment: experiment, user: user, converted_at: 2.days.ago, context: { b: 1 } ) } + let(:experiment_subject) { create(:experiment_subject, experiment: experiment, user: user, converted_at: 2.days.ago, context: { b: 1 }) } it 'merges the context' do expect { record_conversion }.to change { experiment_subject.reload.context }.to('a' => 42, 'b' => 1) diff --git a/spec/models/exported_protected_branch_spec.rb b/spec/models/exported_protected_branch_spec.rb index 7886a522741..9f862de6ff8 100644 --- a/spec/models/exported_protected_branch_spec.rb +++ b/spec/models/exported_protected_branch_spec.rb @@ -11,7 +11,7 @@ RSpec.describe ExportedProtectedBranch do it 'returns the correct push access levels' do exported_branch = create(:exported_protected_branch, :developers_can_push) deploy_key = create(:deploy_key) - create(:deploy_keys_project, :write_access, project: exported_branch.project, deploy_key: deploy_key ) + create(:deploy_keys_project, :write_access, project: exported_branch.project, deploy_key: deploy_key) create(:protected_branch_push_access_level, protected_branch: exported_branch, deploy_key: deploy_key) dev_push_access_level = exported_branch.push_access_levels.first diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index eb9ef8a21e9..928f9d6d057 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -2556,7 +2556,7 @@ RSpec.describe Group do end context 'when parent does not allow' do - let_it_be(:parent, reload: true) { create(:group, :shared_runners_disabled, allow_descendants_override_disabled_shared_runners: false ) } + let_it_be(:parent, reload: true) { create(:group, :shared_runners_disabled, allow_descendants_override_disabled_shared_runners: false) } let_it_be(:group, reload: true) { create(:group, :shared_runners_disabled, allow_descendants_override_disabled_shared_runners: false, parent: parent) } it 'raises exception' do diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index 4c8c19cb3e5..819dad9d46d 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -26,7 +26,7 @@ RSpec.describe Integrations::Jira do end before do - WebMock.stub_request(:get, /serverInfo/).to_return(body: server_info_results.to_json ) + WebMock.stub_request(:get, /serverInfo/).to_return(body: server_info_results.to_json) end it_behaves_like Integrations::ResetSecretFields do diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index e7b2212ebff..08c05b614f6 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -654,7 +654,7 @@ RSpec.describe Issue do let_it_be(:authorized_issue_a) { create(:issue, project: authorized_project) } let_it_be(:authorized_issue_b) { create(:issue, project: authorized_project) } let_it_be(:authorized_issue_c) { create(:issue, project: authorized_project2) } - let_it_be(:authorized_incident_a) { create(:incident, project: authorized_project ) } + let_it_be(:authorized_incident_a) { create(:incident, project: authorized_project) } let_it_be(:unauthorized_issue) { create(:issue, project: unauthorized_project) } diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 04df8ecc882..c70f0144fe6 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -213,7 +213,7 @@ RSpec.describe Member do describe 'Scopes & finders' do let_it_be(:project) { create(:project, :public) } let_it_be(:group) { create(:group) } - let_it_be(:blocked_pending_approval_user) { create(:user, :blocked_pending_approval ) } + let_it_be(:blocked_pending_approval_user) { create(:user, :blocked_pending_approval) } let_it_be(:blocked_pending_approval_project_member) { create(:project_member, :invited, :developer, project: project, invite_email: blocked_pending_approval_user.email) } let_it_be(:awaiting_group_member) { create(:group_member, :awaiting, group: group) } let_it_be(:awaiting_project_member) { create(:project_member, :awaiting, project: project) } diff --git a/spec/models/metrics/dashboard/annotation_spec.rb b/spec/models/metrics/dashboard/annotation_spec.rb index 4b7492016f3..9b8601e4052 100644 --- a/spec/models/metrics/dashboard/annotation_spec.rb +++ b/spec/models/metrics/dashboard/annotation_spec.rb @@ -63,7 +63,7 @@ RSpec.describe Metrics::Dashboard::Annotation do end context 'annotation with shared ownership' do - subject { build(:metrics_dashboard_annotation, :with_cluster, environment: build(:environment) ) } + subject { build(:metrics_dashboard_annotation, :with_cluster, environment: build(:environment)) } it 'reports error about both shared ownership' do subject.valid? diff --git a/spec/models/namespace_setting_spec.rb b/spec/models/namespace_setting_spec.rb index a4446bfedd1..17c49e13c85 100644 --- a/spec/models/namespace_setting_spec.rb +++ b/spec/models/namespace_setting_spec.rb @@ -106,7 +106,7 @@ RSpec.describe NamespaceSetting, type: :model do describe '#prevent_sharing_groups_outside_hierarchy' do let(:settings) { create(:namespace_settings, prevent_sharing_groups_outside_hierarchy: true) } - let!(:group) { create(:group, parent: parent, namespace_settings: settings ) } + let!(:group) { create(:group, parent: parent, namespace_settings: settings) } subject(:group_sharing_setting) { settings.prevent_sharing_groups_outside_hierarchy } @@ -133,7 +133,7 @@ RSpec.describe NamespaceSetting, type: :model do context 'when :show_diff_preview_in_email is false' do it 'returns false' do settings = create(:namespace_settings, show_diff_preview_in_email: false) - group = create(:group, namespace_settings: settings ) + group = create(:group, namespace_settings: settings) expect(group.show_diff_preview_in_email?).to be_falsey end @@ -142,7 +142,7 @@ RSpec.describe NamespaceSetting, type: :model do context 'when :show_diff_preview_in_email is true' do it 'returns true' do settings = create(:namespace_settings, show_diff_preview_in_email: true) - group = create(:group, namespace_settings: settings ) + group = create(:group, namespace_settings: settings) expect(group.show_diff_preview_in_email?).to be_truthy end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 838e5d700c1..4fc752a6a66 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -1623,7 +1623,7 @@ RSpec.describe Namespace do describe '#share_with_group_lock with subgroups' do context 'when creating a subgroup' do - let(:subgroup) { create(:group, parent: root_group ) } + let(:subgroup) { create(:group, parent: root_group) } context 'under a parent with "Share with group lock" enabled' do let(:root_group) { create(:group, share_with_group_lock: true) } @@ -1644,7 +1644,7 @@ RSpec.describe Namespace do context 'when enabling the parent group "Share with group lock"' do let(:root_group) { create(:group) } - let!(:subgroup) { create(:group, parent: root_group ) } + let!(:subgroup) { create(:group, parent: root_group) } it 'the subgroup "Share with group lock" becomes enabled' do root_group.update!(share_with_group_lock: true) @@ -1657,7 +1657,7 @@ RSpec.describe Namespace do let(:root_group) { create(:group, share_with_group_lock: true) } context 'and the subgroup "Share with group lock" is enabled' do - let(:subgroup) { create(:group, parent: root_group, share_with_group_lock: true ) } + let(:subgroup) { create(:group, parent: root_group, share_with_group_lock: true) } it 'the subgroup "Share with group lock" does not change' do root_group.update!(share_with_group_lock: false) @@ -1667,7 +1667,7 @@ RSpec.describe Namespace do end context 'but the subgroup "Share with group lock" is disabled' do - let(:subgroup) { create(:group, parent: root_group ) } + let(:subgroup) { create(:group, parent: root_group) } it 'the subgroup "Share with group lock" does not change' do root_group.update!(share_with_group_lock: false) @@ -1682,7 +1682,7 @@ RSpec.describe Namespace do let(:root_group) { create(:group, share_with_group_lock: true) } context 'when the subgroup "Share with group lock" is enabled' do - let(:subgroup) { create(:group, share_with_group_lock: true ) } + let(:subgroup) { create(:group, share_with_group_lock: true) } it 'the subgroup "Share with group lock" does not change' do subgroup.parent = root_group @@ -1708,7 +1708,7 @@ RSpec.describe Namespace do let(:root_group) { create(:group) } context 'when the subgroup "Share with group lock" is enabled' do - let(:subgroup) { create(:group, share_with_group_lock: true ) } + let(:subgroup) { create(:group, share_with_group_lock: true) } it 'the subgroup "Share with group lock" does not change' do subgroup.parent = root_group diff --git a/spec/models/network/graph_spec.rb b/spec/models/network/graph_spec.rb index a393aace39c..5274526e81c 100644 --- a/spec/models/network/graph_spec.rb +++ b/spec/models/network/graph_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Network::Graph do it '#initialize' do graph = described_class.new(project, 'refs/heads/master', project.repository.commit, nil) - expect(graph.notes).to eq( { note_on_commit.commit_id => 1 } ) + expect(graph.notes).to eq({ note_on_commit.commit_id => 1 }) end describe '#commits' do @@ -19,7 +19,7 @@ RSpec.describe Network::Graph do commits = graph.commits expect(commits).not_to be_empty - expect(commits).to all( be_kind_of(Network::Commit) ) + expect(commits).to all(be_kind_of(Network::Commit)) end it 'sorts commits by commit date (descending)' do @@ -42,7 +42,7 @@ RSpec.describe Network::Graph do parent_indexes = commit.parent_ids.map { |parent_id| commit_ids.find_index(parent_id) }.compact # All parents of the current commit should appear after it - expect(parent_indexes).to all( be > index ) + expect(parent_indexes).to all(be > index) end end end diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb index 0edb04224a3..241c585099c 100644 --- a/spec/models/packages/package_spec.rb +++ b/spec/models/packages/package_spec.rb @@ -969,12 +969,12 @@ RSpec.describe Packages::Package, type: :model do end context 'sorting' do - let_it_be(:project) { create(:project, name: 'aaa' ) } - let_it_be(:project2) { create(:project, name: 'bbb' ) } - let_it_be(:package1) { create(:package, project: project ) } - let_it_be(:package2) { create(:package, project: project2 ) } - let_it_be(:package3) { create(:package, project: project2 ) } - let_it_be(:package4) { create(:package, project: project ) } + let_it_be(:project) { create(:project, name: 'aaa') } + let_it_be(:project2) { create(:project, name: 'bbb') } + let_it_be(:package1) { create(:package, project: project) } + let_it_be(:package2) { create(:package, project: project2) } + let_it_be(:package3) { create(:package, project: project2) } + let_it_be(:package4) { create(:package, project: project) } it 'orders packages by their projects name ascending' do expect(Packages::Package.order_project_name).to eq([package1, package4, package2, package3]) diff --git a/spec/models/personal_access_token_spec.rb b/spec/models/personal_access_token_spec.rb index 73ec51ea801..9d4c53f8d55 100644 --- a/spec/models/personal_access_token_spec.rb +++ b/spec/models/personal_access_token_spec.rb @@ -108,7 +108,7 @@ RSpec.describe PersonalAccessToken do describe '.last_used_before' do context 'last_used_*' do let_it_be(:date) { DateTime.new(2022, 01, 01) } - let_it_be(:token) { create(:personal_access_token, last_used_at: date ) } + let_it_be(:token) { create(:personal_access_token, last_used_at: date) } # This token should never occur in the following tests and indicates that filtering was done correctly with it let_it_be(:never_used_token) { create(:personal_access_token) } diff --git a/spec/models/project_setting_spec.rb b/spec/models/project_setting_spec.rb index 5730ca58e9e..eb0292c7005 100644 --- a/spec/models/project_setting_spec.rb +++ b/spec/models/project_setting_spec.rb @@ -70,7 +70,7 @@ RSpec.describe ProjectSetting, type: :model do describe '#show_diff_preview_in_email?' do context 'when a project is a top-level namespace' do - let(:project_settings ) { create(:project_setting, show_diff_preview_in_email: false) } + let(:project_settings) { create(:project_setting, show_diff_preview_in_email: false) } let(:project) { create(:project, project_setting: project_settings) } context 'when show_diff_preview_in_email is disabled' do @@ -80,7 +80,7 @@ RSpec.describe ProjectSetting, type: :model do end context 'when show_diff_preview_in_email is enabled' do - let(:project_settings ) { create(:project_setting, show_diff_preview_in_email: true) } + let(:project_settings) { create(:project_setting, show_diff_preview_in_email: true) } it 'returns true' do settings = create(:project_setting, show_diff_preview_in_email: true) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 88d96a812e0..359fc4db01f 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -4508,7 +4508,7 @@ RSpec.describe Project, factory_default: :keep do project_2 = create(:project, :public, :merge_requests_disabled) project_3 = create(:project, :public, :issues_disabled) project_4 = create(:project, :public) - project_4.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE, merge_requests_access_level: ProjectFeature::PRIVATE ) + project_4.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE, merge_requests_access_level: ProjectFeature::PRIVATE) project_ids = described_class.ids_with_issuables_available_for(user).pluck(:id) @@ -7125,7 +7125,7 @@ RSpec.describe Project, factory_default: :keep do describe '#export_in_progress?' do let(:project) { build(:project) } - let!(:project_export_job ) { create(:project_export_job, project: project) } + let!(:project_export_job) { create(:project_export_job, project: project) } context 'when project export is enqueued' do it { expect(project.export_in_progress?).to be false } @@ -7150,7 +7150,7 @@ RSpec.describe Project, factory_default: :keep do describe '#export_status' do let(:project) { build(:project) } - let!(:project_export_job ) { create(:project_export_job, project: project) } + let!(:project_export_job) { create(:project_export_job, project: project) } context 'when project export is enqueued' do it { expect(project.export_status).to eq :queued } @@ -7174,7 +7174,7 @@ RSpec.describe Project, factory_default: :keep do end context 'when project export is being regenerated' do - let!(:new_project_export_job ) { create(:project_export_job, project: project) } + let!(:new_project_export_job) { create(:project_export_job, project: project) } before do finish_job(project_export_job) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 6fbf69ec23a..adebacec352 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -463,7 +463,7 @@ RSpec.describe Repository do repository.delete_branch(branch) expect(subject).not_to be_empty - expect(subject).to all( be_a(::Commit) ) + expect(subject).to all(be_a(::Commit)) expect(subject.size).to eq(1) end end @@ -482,7 +482,7 @@ RSpec.describe Repository do end it 'returns only Commit instances' do - expect(subject).to all( be_a(Commit) ) + expect(subject).to all(be_a(Commit)) end context 'when some commits are not found ' do @@ -2978,7 +2978,7 @@ RSpec.describe Repository do it 'returns false for invalid commit IDs' do expect(repository.ancestor?(commit.id, Gitlab::Git::BLANK_SHA)).to eq(false) - expect(repository.ancestor?( Gitlab::Git::BLANK_SHA, commit.id)).to eq(false) + expect(repository.ancestor?(Gitlab::Git::BLANK_SHA, commit.id)).to eq(false) end end diff --git a/spec/models/todo_spec.rb b/spec/models/todo_spec.rb index 18b0cb36cc6..23ba0be2fbc 100644 --- a/spec/models/todo_spec.rb +++ b/spec/models/todo_spec.rb @@ -498,7 +498,7 @@ RSpec.describe Todo do describe '.for_internal_notes' do it 'returns todos created from internal notes' do - internal_note = create(:note, confidential: true ) + internal_note = create(:note, confidential: true) todo = create(:todo, note: internal_note) create(:todo) diff --git a/spec/models/users/calloutable_spec.rb b/spec/models/users/calloutable_spec.rb index 791fe1c1bc4..7e186445c1b 100644 --- a/spec/models/users/calloutable_spec.rb +++ b/spec/models/users/calloutable_spec.rb @@ -15,8 +15,8 @@ RSpec.describe Users::Calloutable do describe '#dismissed_after?' do let(:some_feature_name) { Users::Callout.feature_names.keys.second } - let(:callout_dismissed_month_ago) { create(:callout, feature_name: some_feature_name, dismissed_at: 1.month.ago ) } - let(:callout_dismissed_day_ago) { create(:callout, feature_name: some_feature_name, dismissed_at: 1.day.ago ) } + let(:callout_dismissed_month_ago) { create(:callout, feature_name: some_feature_name, dismissed_at: 1.month.ago) } + let(:callout_dismissed_day_ago) { create(:callout, feature_name: some_feature_name, dismissed_at: 1.day.ago) } it 'returns whether a callout dismissed after specified date' do expect(callout_dismissed_month_ago.dismissed_after?(15.days.ago)).to eq(false) diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index fb8706ab4c3..28ee557c996 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -1291,6 +1291,20 @@ RSpec.describe API::Users do .to eq([Gitlab::PathRegex.namespace_format_message]) end + it 'tracks weak password errors' do + attributes = attributes_for(:user).merge({ password: "password" }) + post api('/users', admin), params: attributes + + expect(json_response['message']['password']) + .to eq(['must not contain commonly used combinations of words and letters']) + expect_snowplow_event( + category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', + action: 'track_weak_password_error', + controller: 'API::Users', + method: 'create' + ) + end + it "is not available for non admin users" do post api("/users", user), params: attributes_for(:user) expect(response).to have_gitlab_http_status(:forbidden) @@ -1492,6 +1506,21 @@ RSpec.describe API::Users do .not_to have_enqueued_mail(DeviseMailer, :password_change) end end + + context 'with a weak password' do + it 'tracks weak password errors' do + update_password(user, admin, "password") + + expect(json_response['message']['password']) + .to eq(['must not contain commonly used combinations of words and letters']) + expect_snowplow_event( + category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', + action: 'track_weak_password_error', + controller: 'API::Users', + method: 'update' + ) + end + end end it "updates user with new bio" do diff --git a/spec/support/shared_examples/features/variable_list_shared_examples.rb b/spec/support/shared_examples/features/variable_list_shared_examples.rb index d1e5046a39e..f0b72cfaee3 100644 --- a/spec/support/shared_examples/features/variable_list_shared_examples.rb +++ b/spec/support/shared_examples/features/variable_list_shared_examples.rb @@ -31,8 +31,8 @@ RSpec.shared_examples 'variable list' do |is_admin| wait_for_requests page.within('[data-testid="ci-variable-table"]') do - expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key') - expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Protected"] svg[data-testid="mobile-issue-close-icon"]')).to be_present + expect(find(".js-ci-variable-row:nth-child(1) td[data-label='#{s_('CiVariables|Key')}']").text).to eq('key') + expect(find(".js-ci-variable-row:nth-child(1) td[data-label='#{s_('CiVariables|Options')}']")).to have_content(s_('CiVariables|Protected')) end end @@ -46,26 +46,26 @@ RSpec.shared_examples 'variable list' do |is_admin| wait_for_requests page.within('[data-testid="ci-variable-table"]') do - expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key') - expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="close-icon"]')).to be_present + expect(find(".js-ci-variable-row:nth-child(1) td[data-label='#{s_('CiVariables|Key')}']").text).to eq('key') + expect(find(".js-ci-variable-row:nth-child(1) td[data-label='#{s_('CiVariables|Options')}']")).not_to have_content(s_('CiVariables|Masked')) end end it 'reveals and hides variables' do page.within('[data-testid="ci-variable-table"]') do expect(first('.js-ci-variable-row td[data-label="Key"]').text).to eq(variable.key) - expect(page).to have_content('*' * 17) + expect(page).to have_content('*' * 5) click_button('Reveal value') expect(first('.js-ci-variable-row td[data-label="Key"]').text).to eq(variable.key) expect(first('.js-ci-variable-row td[data-label="Value"]').text).to eq(variable.value) - expect(page).not_to have_content('*' * 17) + expect(page).not_to have_content('*' * 5) click_button('Hide value') expect(first('.js-ci-variable-row td[data-label="Key"]').text).to eq(variable.key) - expect(page).to have_content('*' * 17) + expect(page).to have_content('*' * 5) end end @@ -116,7 +116,8 @@ RSpec.shared_examples 'variable list' do |is_admin| wait_for_requests page.within('[data-testid="ci-variable-table"]') do - expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="close-icon"]')).to be_present + expect(find(".js-ci-variable-row:nth-child(1) td[data-label='#{s_('CiVariables|Options')}']")).to have_content(s_('CiVariables|Protected')) + expect(find(".js-ci-variable-row:nth-child(1) td[data-label='#{s_('CiVariables|Options')}']")).not_to have_content(s_('CiVariables|Masked')) end end @@ -144,7 +145,7 @@ RSpec.shared_examples 'variable list' do |is_admin| end page.within('[data-testid="ci-variable-table"]') do - expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="mobile-issue-close-icon"]')).to be_present + expect(find(".js-ci-variable-row:nth-child(1) td[data-label='#{s_('CiVariables|Options')}']")).to have_content(s_('CiVariables|Masked')) end end |