Fix instance actor being incorrectly created when running migrations (#18109)
* Add migration test about instance actor key * Fix old migration * Work around incorrect database statepull/1752/head^2
parent
f47a9ddc9f
commit
33cd80d69c
|
@ -559,6 +559,12 @@ class Account < ApplicationRecord
|
|||
before_validation :prepare_username, on: :create
|
||||
before_destroy :clean_feed_manager
|
||||
|
||||
def ensure_keys!
|
||||
return unless local? && private_key.blank? && public_key.blank?
|
||||
generate_keys
|
||||
save!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_contents
|
||||
|
|
|
@ -13,7 +13,7 @@ module AccountFinderConcern
|
|||
end
|
||||
|
||||
def representative
|
||||
Account.find(-99)
|
||||
Account.find(-99).tap(&:ensure_keys!)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
Account.create!(id: -99, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain)
|
||||
end
|
||||
|
|
|
@ -2,6 +2,14 @@ class AddInstanceActor < ActiveRecord::Migration[5.2]
|
|||
class Account < ApplicationRecord
|
||||
# Dummy class, to make migration possible across version changes
|
||||
validates :username, uniqueness: { scope: :domain, case_sensitive: false }
|
||||
|
||||
before_create :generate_keys
|
||||
|
||||
def generate_keys
|
||||
keypair = OpenSSL::PKey::RSA.new(2048)
|
||||
self.private_key = keypair.to_pem
|
||||
self.public_key = keypair.public_key.to_pem
|
||||
end
|
||||
end
|
||||
|
||||
def up
|
||||
|
|
|
@ -33,6 +33,11 @@ namespace :tests do
|
|||
puts 'AccountConversation records not created as expected'
|
||||
exit(1)
|
||||
end
|
||||
|
||||
if Account.find(-99).private_key.blank?
|
||||
puts 'Instance actor does not have a private key'
|
||||
exit(1)
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Populate the database with test data for 2.4.0'
|
||||
|
|
Loading…
Reference in New Issue