diff --git a/app/models/account.rb b/app/models/account.rb index 31a5deadc82..e5737909452 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -122,6 +122,7 @@ class Account < ApplicationRecord # Remote user validations validates :uri, presence: true, exclusion: { in: [''] }, uniqueness: true, unless: :local?, on: :create + validates :inbox_url, presence: true, if: -> { !local? && (new_record? || will_save_change_to_inbox_url?) } # Local user validations validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: USERNAME_LENGTH_LIMIT }, if: -> { local? && will_save_change_to_username? && !actor_type_application? } diff --git a/spec/fabricators/account_fabricator.rb b/spec/fabricators/account_fabricator.rb index 6a5218cee98..7e1e1b4349e 100644 --- a/spec/fabricators/account_fabricator.rb +++ b/spec/fabricators/account_fabricator.rb @@ -12,6 +12,7 @@ Fabricator(:account) do silenced_at { |attrs| attrs[:silenced] ? Time.now.utc : nil } requested_deletion_at { |attrs| attrs[:requested_deletion] ? Time.now.utc : nil } user { |attrs| attrs[:domain].nil? ? Fabricate.build(:user, account: nil) : nil } + inbox_url { |attrs| attrs[:domain].nil? ? '' : "https://#{attrs[:domain]}/users/#{attrs[:username]}/inbox" } uri { |attrs| attrs[:domain].nil? ? nil : "https://#{attrs[:domain]}/users/#{attrs[:username]}" } discoverable true indexable true diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 70d349d13ad..a1735af6c37 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -745,12 +745,12 @@ RSpec.describe Account do context 'when is remote' do it 'does not generate keys' do key = OpenSSL::PKey::RSA.new(1024).public_key - account = described_class.create!(domain: 'remote', uri: 'https://remote/actor', username: 'remote_user_with_public', public_key: key.to_pem) + account = described_class.create!(domain: 'remote', uri: 'https://remote/actor', inbox_url: 'https://remote/actor/inbox', username: 'remote_user_with_public', public_key: key.to_pem) expect(account.keypair.keypair.params).to eq key.params end it 'normalizes domain' do - account = described_class.create!(domain: 'にゃん', uri: 'https://xn--r9j5b5b/actor', username: 'remote_user_with_idn_domain') + account = described_class.create!(domain: 'にゃん', uri: 'https://xn--r9j5b5b/actor', inbox_url: 'https://xn--r9j5b5b/actor/inbox', username: 'remote_user_with_idn_domain') expect(account.domain).to eq 'xn--r9j5b5b' end end