From 961d65aba6432d83e70a5e8ee720034b87064d02 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 20 Dec 2023 03:54:04 -0500 Subject: [PATCH] Add coverage to CLI Maintenance for duplicate users on `confirmation_token` and `reset_password_token` values (#28434) --- spec/lib/mastodon/cli/maintenance_spec.rb | 60 ++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/spec/lib/mastodon/cli/maintenance_spec.rb b/spec/lib/mastodon/cli/maintenance_spec.rb index 61331e6dba5..353bf08b68f 100644 --- a/spec/lib/mastodon/cli/maintenance_spec.rb +++ b/spec/lib/mastodon/cli/maintenance_spec.rb @@ -89,7 +89,7 @@ describe Mastodon::CLI::Maintenance do end end - context 'with duplicate users' do + context 'with duplicate users on email' do before do prepare_duplicate_data end @@ -117,6 +117,64 @@ describe Mastodon::CLI::Maintenance do end end + context 'with duplicate users on confirmation_token' do + before do + prepare_duplicate_data + end + + let(:duplicate_confirmation_token) { '123ABC' } + + it 'runs the deduplication process' do + expect { subject } + .to output_results( + 'Deduplicating user records', + 'Unsetting confirmation token', + 'Restoring users indexes', + 'Finished!' + ) + .and change(duplicate_users, :count).from(2).to(1) + end + + def duplicate_users + User.where(confirmation_token: duplicate_confirmation_token) + end + + def prepare_duplicate_data + ActiveRecord::Base.connection.remove_index :users, :confirmation_token + Fabricate(:user, confirmation_token: duplicate_confirmation_token) + Fabricate.build(:user, confirmation_token: duplicate_confirmation_token).save(validate: false) + end + end + + context 'with duplicate users on reset_password_token' do + before do + prepare_duplicate_data + end + + let(:duplicate_reset_password_token) { '123ABC' } + + it 'runs the deduplication process' do + expect { subject } + .to output_results( + 'Deduplicating user records', + 'Unsetting password reset token', + 'Restoring users indexes', + 'Finished!' + ) + .and change(duplicate_users, :count).from(2).to(1) + end + + def duplicate_users + User.where(reset_password_token: duplicate_reset_password_token) + end + + def prepare_duplicate_data + ActiveRecord::Base.connection.remove_index :users, :reset_password_token + Fabricate(:user, reset_password_token: duplicate_reset_password_token) + Fabricate.build(:user, reset_password_token: duplicate_reset_password_token).save(validate: false) + end + end + def agree_to_backup_warning allow(cli.shell) .to receive(:yes?)