From bafd22ecf487774c252a271d668716b0e1c84c6c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 3 May 2017 17:02:18 +0200 Subject: Fix #2706 - Always respond with 200 to PuSH payloads (#2733) Fix #2196 - Respond with 201 when Salmon accepted, 400 when unverified Fix #2629 - Correctly handle confirm_domain? for local accounts Unify rules for extracting author acct from XML, prefer , fall back to + (see also #2017, #2172) --- app/services/process_interaction_service.rb | 31 ++++------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) (limited to 'app/services/process_interaction_service.rb') diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index 410e805d3..1f15a265d 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ProcessInteractionService < BaseService + include AuthorExtractor + # Record locally the remote interaction with our user # @param [String] envelope Salmon envelope # @param [Account] target_account Account the Salmon was addressed to @@ -10,18 +12,9 @@ class ProcessInteractionService < BaseService xml = Nokogiri::XML(body) xml.encoding = 'utf-8' - return unless contains_author?(xml) - - username = xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:name', xmlns: TagManager::XMLNS).content - url = xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:uri', xmlns: TagManager::XMLNS).content - domain = Addressable::URI.parse(url).normalize.host - account = Account.find_by(username: username, domain: domain) - - if account.nil? - account = follow_remote_account_service.call("#{username}@#{domain}") - end + account = author_from_xml(xml.at_xpath('/xmlns:entry', xmlns: TagManager::XMLNS)) - return if account.suspended? + return if account.nil? || account.suspended? if salmon.verify(envelope, account.keypair) RemoteProfileUpdateWorker.perform_async(account.id, body.force_encoding('UTF-8'), true) @@ -59,10 +52,6 @@ class ProcessInteractionService < BaseService private - def contains_author?(xml) - !(xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:name', xmlns: TagManager::XMLNS).nil? || xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:uri', xmlns: TagManager::XMLNS).nil?) - end - def mentions_account?(xml, account) xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each { |mention_link| return true if [TagManager.instance.uri_for(account), TagManager.instance.url_for(account)].include?(mention_link.attribute('href').value) } false @@ -144,16 +133,4 @@ class ProcessInteractionService < BaseService def salmon @salmon ||= OStatus2::Salmon.new end - - def follow_remote_account_service - @follow_remote_account_service ||= FollowRemoteAccountService.new - end - - def process_feed_service - @process_feed_service ||= ProcessFeedService.new - end - - def remove_status_service - @remove_status_service ||= RemoveStatusService.new - end end -- cgit