Commit 380a73cc authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Add specs for workers

Add new workers to queues

Fix
parent 0b215f47
......@@ -564,7 +564,7 @@ class Group < Namespace
def update_two_factor_requirement
return unless saved_change_to_require_two_factor_authentication? || saved_change_to_two_factor_grace_period?
binding.pry
members_with_descendants.find_each(&:update_two_factor_requirement)
end
......
......@@ -22,7 +22,9 @@ module Groups
return false unless valid_path_change_with_npm_packages?
return false unless update_shared_runners
handle_changes
before_assignment_hook(group, params)
handle_namespace_settings
......@@ -101,7 +103,7 @@ module Groups
if settings.previous_changes.include?(:allow_mfa_for_subgroups)
# enque in batches members update
Disallow2FAWorker.perform_async(group.id)
DisallowTwoFaWorker.perform_async(group.id)
end
end
......
......@@ -1393,6 +1393,22 @@
:weight: 1
:idempotent:
:tags: []
- :name: disallow_two_fa
:feature_category: :subgroups
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:tags: []
- :name: disallow_two_fa_for_subgroups
:feature_category: :subgroups
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:tags: []
- :name: email_receiver
:feature_category: :issue_tracking
:has_external_dependencies:
......
# frozen_string_literal: true
class Disallow2FAForSubgroupsWorker # rubocop:disable Scalability/IdempotentWorker
class DisallowTwoFaForSubgroupsWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
include ExceptionBacktrace
......
# frozen_string_literal: true
class Disallow2FAWorker # rubocop:disable Scalability/IdempotentWorker
class DisallowTwoFaWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
include ExceptionBacktrace
......@@ -9,20 +9,21 @@ class Disallow2FAWorker # rubocop:disable Scalability/IdempotentWorker
feature_category :subgroups
def perform(group_id)
binding.pry
begin
group = Group.find(group_id)
rescue ActiveRecord::RecordNotFound
return
end
subgroups = group.descendants.where(require_two_factor_authentication: true)
subgroups.find_each(batch_size: 100).with_index do |subgroup, index| # rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
subgroups = group.descendants.where(require_two_factor_authentication: true) # rubocop: disable CodeReuse/ActiveRecord
subgroups.find_each(batch_size: 100).with_index do |subgroup, index|
delay = index * INTERVAL
with_context(namespace: subgroup) do
Disallow2FAForSubgroupsWorker.perform_in(delay, subgroup.id)
DisallowTwoFaForSubgroupsWorker.perform_in(delay, subgroup.id)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -84,6 +84,10 @@
- 1
- - detect_repository_languages
- 1
- - disallow_two_fa
- 1
- - disallow_two_fa_for_subgroups
- 1
- - elastic_commit_indexer
- 1
- - elastic_delete_project
......
......@@ -321,7 +321,7 @@ RSpec.describe Groups::UpdateService do
end
it 'enqueues update subgroups and its members' do
expect(Disallow2FAWorker).to receive(:perform_async).with(group.id)
expect(DisallowTwoFaWorker).to receive(:perform_async).with(group.id)
subject
end
......
......@@ -2,11 +2,9 @@
require 'spec_helper'
RSpec.describe Disallow2FAForSubgroupsWorker do
RSpec.describe DisallowTwoFaForSubgroupsWorker do
let_it_be(:group) { create(:group, require_two_factor_authentication: true) }
let_it_be(:subgroup) { create(:group, parent: group, require_two_factor_authentication: true) }
let_it_be(:user) { create(:user, :two_factor, require_two_factor_authentication_from_group: true) }
let_it_be(:user_for_subgroup) { create(:user, :two_factor, require_two_factor_authentication_from_group: true) }
let_it_be(:user) { create(:user, require_two_factor_authentication_from_group: true) }
it "updates group" do
described_class.new.perform(group.id)
......@@ -16,17 +14,9 @@ RSpec.describe Disallow2FAForSubgroupsWorker do
it "updates group members" do
group.add_user(user, GroupMember::DEVELOPER)
binding.pry
described_class.new.perform(group.id)
expect(user.reload.require_two_factor_authentication_from_group).to eq(false)
end
it "updates descendant members" do
subgroup.add_user(user_for_subgroup, GroupMember::DEVELOPER)
described_class.new.perform(group.id)
expect(user_for_subgroup.reload.require_two_factor_authentication_from_group).to eq(false)
expect(user.reload.require_two_factor_authentication_from_group).to eq(false)
end
end
......@@ -2,15 +2,15 @@
require 'spec_helper'
RSpec.describe Disallow2FAWorker do
RSpec.describe DisallowTwoFaWorker do
let_it_be(:group) { create(:group) }
let_it_be(:subgroup_with_2fa) { create(:group, parent: group, require_two_factor_authentication: true) }
let_it_be(:subgroup_without_2fa) { create(:group, parent: group, require_two_factor_authentication: false) }
let_it_be(:subsubgroup_with_2fa) { create(:group, parent: subgroup_with_2fa, require_two_factor_authentication: true) }
it "schedules updating subgroups" do
expect(Disallow2FAForSubgroupsWorker).to receive(:perform_in).with(0, subgroup_with_2fa.id)
expect(Disallow2FAForSubgroupsWorker).to receive(:perform_in).with(2, subsubgroup_with_2fa.id)
expect(DisallowTwoFaForSubgroupsWorker).to receive(:perform_in).with(0, subgroup_with_2fa.id)
expect(DisallowTwoFaForSubgroupsWorker).to receive(:perform_in).with(2, subsubgroup_with_2fa.id)
described_class.new.perform(group.id)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment