Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 500 error when trying to migrate to an invalid address #21462

Merged
merged 2 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/account_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def acct=(val)

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

Expand Down
2 changes: 1 addition & 1 deletion app/models/form/redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def acct=(val)

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

Expand Down
43 changes: 43 additions & 0 deletions spec/models/account_migration_spec.rb
Original file line number Diff line number Diff line change
@@ -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