mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-23 08:34:13 -05:00
Fix 500 error when trying to migrate to an invalid address (#21462)
* Fix 500 error when trying to migrate to an invalid address * Add tests
This commit is contained in:
parent
21b208afcb
commit
b59fb28e90
@ -59,7 +59,7 @@ class AccountMigration < ApplicationRecord
|
||||
|
||||
def set_target_account
|
||||
self.target_account = ResolveAccountService.new.call(acct, skip_cache: true)
|
||||
rescue Webfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error
|
||||
rescue Webfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error, Addressable::URI::InvalidURIError
|
||||
# Validation will take care of it
|
||||
end
|
||||
|
||||
|
@ -32,7 +32,7 @@ class Form::Redirect
|
||||
|
||||
def set_target_account
|
||||
@target_account = ResolveAccountService.new.call(acct, skip_cache: true)
|
||||
rescue Webfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error
|
||||
rescue Webfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error, Addressable::URI::InvalidURIError
|
||||
# Validation will take care of it
|
||||
end
|
||||
|
||||
|
@ -1,5 +1,48 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountMigration, type: :model do
|
||||
describe 'validations' do
|
||||
let(:source_account) { Fabricate(:account) }
|
||||
let(:target_acct) { target_account.acct }
|
||||
|
||||
let(:subject) { AccountMigration.new(account: source_account, acct: target_acct) }
|
||||
|
||||
context 'with valid properties' do
|
||||
let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') }
|
||||
|
||||
before do
|
||||
target_account.aliases.create!(acct: source_account.acct)
|
||||
|
||||
service_double = double
|
||||
allow(ResolveAccountService).to receive(:new).and_return(service_double)
|
||||
allow(service_double).to receive(:call).with(target_acct, anything).and_return(target_account)
|
||||
end
|
||||
|
||||
it 'passes validations' do
|
||||
expect(subject).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'with unresolveable account' do
|
||||
let(:target_acct) { 'target@remote' }
|
||||
|
||||
before do
|
||||
service_double = double
|
||||
allow(ResolveAccountService).to receive(:new).and_return(service_double)
|
||||
allow(service_double).to receive(:call).with(target_acct, anything).and_return(nil)
|
||||
end
|
||||
|
||||
it 'has errors on acct field' do
|
||||
expect(subject).to model_have_error_on_field(:acct)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a space in the domain part' do
|
||||
let(:target_acct) { 'target@remote. org' }
|
||||
|
||||
it 'has errors on acct field' do
|
||||
expect(subject).to model_have_error_on_field(:acct)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user