Merge commit from fork
This commit is contained in:
		@@ -46,6 +46,8 @@ class DeliveryFailureTracker
 | 
				
			|||||||
      urls.reject do |url|
 | 
					      urls.reject do |url|
 | 
				
			||||||
        host = Addressable::URI.parse(url).normalized_host
 | 
					        host = Addressable::URI.parse(url).normalized_host
 | 
				
			||||||
        unavailable_domains_map[host]
 | 
					        unavailable_domains_map[host]
 | 
				
			||||||
 | 
					      rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
 | 
				
			||||||
 | 
					        true
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,8 @@ class ActivityPub::ProcessAccountService < BaseService
 | 
				
			|||||||
  SUBDOMAINS_RATELIMIT = 10
 | 
					  SUBDOMAINS_RATELIMIT = 10
 | 
				
			||||||
  DISCOVERIES_PER_REQUEST = 400
 | 
					  DISCOVERIES_PER_REQUEST = 400
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  VALID_URI_SCHEMES = %w(http https).freeze
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Should be called with confirmed valid JSON
 | 
					  # Should be called with confirmed valid JSON
 | 
				
			||||||
  # and WebFinger-resolved username and domain
 | 
					  # and WebFinger-resolved username and domain
 | 
				
			||||||
  def call(username, domain, json, options = {})
 | 
					  def call(username, domain, json, options = {})
 | 
				
			||||||
@@ -96,16 +98,28 @@ class ActivityPub::ProcessAccountService < BaseService
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def set_immediate_protocol_attributes!
 | 
					  def set_immediate_protocol_attributes!
 | 
				
			||||||
    @account.inbox_url               = @json['inbox'] || ''
 | 
					    @account.inbox_url               = valid_collection_uri(@json['inbox'])
 | 
				
			||||||
    @account.outbox_url              = @json['outbox'] || ''
 | 
					    @account.outbox_url              = valid_collection_uri(@json['outbox'])
 | 
				
			||||||
    @account.shared_inbox_url        = (@json['endpoints'].is_a?(Hash) ? @json['endpoints']['sharedInbox'] : @json['sharedInbox']) || ''
 | 
					    @account.shared_inbox_url        = valid_collection_uri(@json['endpoints'].is_a?(Hash) ? @json['endpoints']['sharedInbox'] : @json['sharedInbox'])
 | 
				
			||||||
    @account.followers_url           = @json['followers'] || ''
 | 
					    @account.followers_url           = valid_collection_uri(@json['followers'])
 | 
				
			||||||
    @account.url                     = url || @uri
 | 
					    @account.url                     = url || @uri
 | 
				
			||||||
    @account.uri                     = @uri
 | 
					    @account.uri                     = @uri
 | 
				
			||||||
    @account.actor_type              = actor_type
 | 
					    @account.actor_type              = actor_type
 | 
				
			||||||
    @account.created_at              = @json['published'] if @json['published'].present?
 | 
					    @account.created_at              = @json['published'] if @json['published'].present?
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def valid_collection_uri(uri)
 | 
				
			||||||
 | 
					    uri = uri.first if uri.is_a?(Array)
 | 
				
			||||||
 | 
					    uri = uri['id'] if uri.is_a?(Hash)
 | 
				
			||||||
 | 
					    return '' unless uri.is_a?(String)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    parsed_uri = Addressable::URI.parse(uri)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    VALID_URI_SCHEMES.include?(parsed_uri.scheme) && parsed_uri.host.present? ? parsed_uri : ''
 | 
				
			||||||
 | 
					  rescue Addressable::URI::InvalidURIError
 | 
				
			||||||
 | 
					    ''
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def set_immediate_attributes!
 | 
					  def set_immediate_attributes!
 | 
				
			||||||
    @account.featured_collection_url = @json['featured'] || ''
 | 
					    @account.featured_collection_url = @json['featured'] || ''
 | 
				
			||||||
    @account.display_name            = @json['name'] || ''
 | 
					    @account.display_name            = @json['name'] || ''
 | 
				
			||||||
@@ -268,10 +282,11 @@ class ActivityPub::ProcessAccountService < BaseService
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def collection_info(type)
 | 
					  def collection_info(type)
 | 
				
			||||||
    return [nil, nil] if @json[type].blank?
 | 
					    collection_uri = valid_collection_uri(@json[type])
 | 
				
			||||||
 | 
					    return [nil, nil] if collection_uri.blank?
 | 
				
			||||||
    return @collections[type] if @collections.key?(type)
 | 
					    return @collections[type] if @collections.key?(type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    collection = fetch_resource_without_id_validation(@json[type])
 | 
					    collection = fetch_resource_without_id_validation(collection_uri)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    total_items = collection.is_a?(Hash) && collection['totalItems'].present? && collection['totalItems'].is_a?(Numeric) ? collection['totalItems'] : nil
 | 
					    total_items = collection.is_a?(Hash) && collection['totalItems'].present? && collection['totalItems'].is_a?(Numeric) ? collection['totalItems'] : nil
 | 
				
			||||||
    has_first_page = collection.is_a?(Hash) && collection['first'].present?
 | 
					    has_first_page = collection.is_a?(Hash) && collection['first'].present?
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,8 +42,8 @@ RSpec.describe DeliveryFailureTracker do
 | 
				
			|||||||
      Fabricate(:unavailable_domain, domain: 'foo.bar')
 | 
					      Fabricate(:unavailable_domain, domain: 'foo.bar')
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it 'removes URLs that are unavailable' do
 | 
					    it 'removes URLs that are bogus or unavailable' do
 | 
				
			||||||
      results = described_class.without_unavailable(['http://example.com/good/inbox', 'http://foo.bar/unavailable/inbox'])
 | 
					      results = described_class.without_unavailable(['http://example.com/good/inbox', 'http://foo.bar/unavailable/inbox', '{foo:'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(results).to include('http://example.com/good/inbox')
 | 
					      expect(results).to include('http://example.com/good/inbox')
 | 
				
			||||||
      expect(results).to_not include('http://foo.bar/unavailable/inbox')
 | 
					      expect(results).to_not include('http://foo.bar/unavailable/inbox')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user