about summary refs log tree commit diff
path: root/app/services/verify_salmon_service.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-05-03 17:02:18 +0200
committerGitHub <noreply@github.com>2017-05-03 17:02:18 +0200
commitbafd22ecf487774c252a271d668716b0e1c84c6c (patch)
treebda1f7d712b3d0094595b56261a36b38034d345b /app/services/verify_salmon_service.rb
parentdd9d57300ba3b6df91ef6398d8c369437cc2a9c7 (diff)
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 <email>, fall back
to <name> + <uri> (see also #2017, #2172)
Diffstat (limited to 'app/services/verify_salmon_service.rb')
-rw-r--r--app/services/verify_salmon_service.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/services/verify_salmon_service.rb b/app/services/verify_salmon_service.rb
new file mode 100644
index 000000000..cd674837d
--- /dev/null
+++ b/app/services/verify_salmon_service.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class VerifySalmonService < BaseService
+  include AuthorExtractor
+
+  def call(payload)
+    body = salmon.unpack(payload)
+
+    xml = Nokogiri::XML(body)
+    xml.encoding = 'utf-8'
+
+    account = author_from_xml(xml.at_xpath('/xmlns:entry', xmlns: TagManager::XMLNS))
+
+    if account.nil?
+      false
+    else
+      salmon.verify(payload, account.keypair)
+    end
+  end
+
+  private
+
+  def salmon
+    @salmon ||= OStatus2::Salmon.new
+  end
+end