Merge pull request #8368 from SuperTux88/upgrade-diaspora-federation

Upgrade diaspora federation (and some preparations for ruby 3)
This commit is contained in:
Benjamin Neff 2022-07-21 02:18:12 +02:00
commit d6436f4d03
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
24 changed files with 110 additions and 98 deletions

View file

@ -16,7 +16,6 @@ jobs:
matrix: matrix:
ruby: ruby:
- 2.7 - 2.7
- 2.6
db: db:
- mysql - mysql
- postgresql - postgresql

View file

@ -1,7 +1,7 @@
require: rubocop-rails require: rubocop-rails
AllCops: AllCops:
TargetRubyVersion: 2.6 TargetRubyVersion: 2.7
NewCops: enable NewCops: enable
Exclude: Exclude:
- "bin/**/*" - "bin/**/*"

View file

@ -26,9 +26,10 @@ We use yarn to install the frontend dependencies now, so you need to have that i
* Enable Content-Security-Policy header by default [#7781](https://github.com/diaspora/diaspora/pull/7781) * Enable Content-Security-Policy header by default [#7781](https://github.com/diaspora/diaspora/pull/7781)
* Do not show getting started after account import [#8036](https://github.com/diaspora/diaspora/pull/8036) * Do not show getting started after account import [#8036](https://github.com/diaspora/diaspora/pull/8036)
* Remove the JSXC/Prosody integration [#8069](https://github.com/diaspora/diaspora/pull/8069) [#8341](https://github.com/diaspora/diaspora/pull/8341) * Remove the JSXC/Prosody integration [#8069](https://github.com/diaspora/diaspora/pull/8069) [#8341](https://github.com/diaspora/diaspora/pull/8341)
* Replace factory\_girl with factory\_bot [#8218](https://github.com/diaspora/diaspora/pull/8218) * Replace `factory_girl` with `factory_bot` [#8218](https://github.com/diaspora/diaspora/pull/8218)
* Drop relay support [#8243](https://github.com/diaspora/diaspora/pull/8243) * Drop relay support [#8243](https://github.com/diaspora/diaspora/pull/8243)
* Use yarn to manage the frontend dependencies [#8364](https://github.com/diaspora/diaspora/pull/8364) * Use yarn to manage the frontend dependencies [#8364](https://github.com/diaspora/diaspora/pull/8364)
* Upgrade to latest `diaspora_federation`, remove support for old federation protocol [#8368](https://github.com/diaspora/diaspora/pull/8368)
## Bug fixes ## Bug fixes
* Fix multiple photos upload progress bar [#7655](https://github.com/diaspora/diaspora/pull/7655) * Fix multiple photos upload progress bar [#7655](https://github.com/diaspora/diaspora/pull/7655)

12
Gemfile
View file

@ -15,8 +15,8 @@ gem "unicorn-worker-killer", "0.4.5"
# Federation # Federation
gem "diaspora_federation-json_schema", "0.2.8" gem "diaspora_federation-json_schema", "1.0.0"
gem "diaspora_federation-rails", "0.2.8" gem "diaspora_federation-rails", "1.0.0"
# API and JSON # API and JSON
@ -143,9 +143,9 @@ gem "acts-as-taggable-on", "9.0.1"
# URIs and HTTP # URIs and HTTP
gem "addressable", "2.8.0", require: "addressable/uri" gem "addressable", "2.8.0", require: "addressable/uri"
gem "faraday", "0.17.5" gem "faraday", "1.10.0"
gem "faraday-cookie_jar", "0.0.7" gem "faraday-cookie_jar", "0.0.7"
gem "faraday_middleware", "0.14.0" gem "faraday-follow_redirects", "0.3.0"
gem "typhoeus", "1.4.0" gem "typhoeus", "1.4.0"
# Views # Views
@ -240,12 +240,12 @@ group :test do
# General helpers # General helpers
gem "factory_bot_rails", "6.1.0" gem "factory_bot_rails", "6.2.0"
gem "shoulda-matchers", "4.5.1" gem "shoulda-matchers", "4.5.1"
gem "timecop", "0.9.5" gem "timecop", "0.9.5"
gem "webmock", "3.14.0", require: false gem "webmock", "3.14.0", require: false
gem "diaspora_federation-test", "0.2.8" gem "diaspora_federation-test", "1.0.0"
end end
group :development, :test do group :development, :test do

View file

@ -209,19 +209,19 @@ GEM
devise_lastseenable (0.0.6) devise_lastseenable (0.0.6)
devise devise
rails (>= 3.0.4) rails (>= 3.0.4)
diaspora_federation (0.2.8) diaspora_federation (1.0.0)
faraday (>= 0.9.0, < 1.0) faraday (>= 1.0, < 3)
faraday_middleware (>= 0.10.0, < 1.0) faraday-follow_redirects (~> 0.3)
nokogiri (~> 1.6, >= 1.6.8) nokogiri (~> 1.6, >= 1.6.8)
typhoeus (~> 1.0) typhoeus (~> 1.0)
valid (~> 1.0) valid (~> 1.0)
diaspora_federation-json_schema (0.2.8) diaspora_federation-json_schema (1.0.0)
diaspora_federation-rails (0.2.8) diaspora_federation-rails (1.0.0)
actionpack (>= 4.2, < 7) actionpack (>= 5.2, < 8)
diaspora_federation (= 0.2.8) diaspora_federation (= 1.0.0)
diaspora_federation-test (0.2.8) diaspora_federation-test (1.0.0)
diaspora_federation (= 0.2.8) diaspora_federation (= 1.0.0)
fabrication (~> 2.16) fabrication (~> 2.29)
uuid (~> 2.3, >= 2.3.8) uuid (~> 2.3, >= 2.3.8)
diff-lcs (1.5.0) diff-lcs (1.5.0)
docile (1.4.0) docile (1.4.0)
@ -246,19 +246,40 @@ GEM
kostya-sigar (~> 2.0.0) kostya-sigar (~> 2.0.0)
state_machines state_machines
thor thor
fabrication (2.22.0) fabrication (2.29.0)
factory_bot (6.1.0) factory_bot (6.2.1)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
factory_bot_rails (6.1.0) factory_bot_rails (6.2.0)
factory_bot (~> 6.1.0) factory_bot (~> 6.2.0)
railties (>= 5.0.0) railties (>= 5.0.0)
faraday (0.17.5) faraday (1.10.0)
multipart-post (>= 1.2, < 3) faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-cookie_jar (0.0.7) faraday-cookie_jar (0.0.7)
faraday (>= 0.8.0) faraday (>= 0.8.0)
http-cookie (~> 1.0.0) http-cookie (~> 1.0.0)
faraday_middleware (0.14.0) faraday-em_http (1.0.0)
faraday (>= 0.7.4, < 1.0) faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
ffi (1.15.5) ffi (1.15.5)
ffi-compiler (1.0.1) ffi-compiler (1.0.1)
ffi (>= 1.0.0) ffi (>= 1.0.0)
@ -618,6 +639,7 @@ GEM
ruby-progressbar (1.11.0) ruby-progressbar (1.11.0)
ruby-vips (2.1.4) ruby-vips (2.1.4)
ffi (~> 1.12) ffi (~> 1.12)
ruby2_keywords (0.0.5)
rubyzip (2.3.2) rubyzip (2.3.2)
rugged (1.0.1) rugged (1.0.1)
sass (3.4.25) sass (3.4.25)
@ -707,7 +729,7 @@ GEM
unf (~> 0.1.0) unf (~> 0.1.0)
typhoeus (1.4.0) typhoeus (1.4.0)
ethon (>= 0.9.0) ethon (>= 0.9.0)
tzinfo (2.0.4) tzinfo (2.0.5)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
@ -778,14 +800,14 @@ DEPENDENCIES
devise (= 4.8.1) devise (= 4.8.1)
devise-two-factor (= 4.0.2) devise-two-factor (= 4.0.2)
devise_lastseenable (= 0.0.6) devise_lastseenable (= 0.0.6)
diaspora_federation-json_schema (= 0.2.8) diaspora_federation-json_schema (= 1.0.0)
diaspora_federation-rails (= 0.2.8) diaspora_federation-rails (= 1.0.0)
diaspora_federation-test (= 0.2.8) diaspora_federation-test (= 1.0.0)
eye (= 0.10.0) eye (= 0.10.0)
factory_bot_rails (= 6.1.0) factory_bot_rails (= 6.2.0)
faraday (= 0.17.5) faraday (= 1.10.0)
faraday-cookie_jar (= 0.0.7) faraday-cookie_jar (= 0.0.7)
faraday_middleware (= 0.14.0) faraday-follow_redirects (= 0.3.0)
fixture_builder (= 0.5.2) fixture_builder (= 0.5.2)
fog-aws (= 3.14.0) fog-aws (= 3.14.0)
fuubar (= 2.5.1) fuubar (= 2.5.1)

View file

@ -20,11 +20,11 @@ module NotificationsHelper
opts.merge!(opts_for_birthday(note)) opts.merge!(opts_for_birthday(note))
end end
end end
translation(target_type, opts) translation(target_type, **opts)
end end
def translation(target_type, opts = {}) def translation(target_type, **kwargs)
t("#{target_type}", opts).html_safe t(target_type, **kwargs).html_safe # rubocop:disable Rails/OutputSafety
end end
def opts_for_post(post) def opts_for_post(post)

View file

@ -26,7 +26,7 @@ class ReportMailer < ApplicationMailer
private private
def format(resource) def format(resource)
body = I18n.t("notifier.report_email.body", resource) body = I18n.t("notifier.report_email.body", **resource)
mail(to: resource[:email], subject: I18n.t("notifier.report_email.subject", type: resource[:type])) do |format| mail(to: resource[:email], subject: I18n.t("notifier.report_email.subject", type: resource[:type])) do |format|
format.html { render "notifier/plain_markdown_email", locals: {body: body} } format.html { render "notifier/plain_markdown_email", locals: {body: body} }
format.text { render "notifier/plain_markdown_email", locals: {body: body} } format.text { render "notifier/plain_markdown_email", locals: {body: body} }

View file

@ -20,8 +20,12 @@ class BasePresenter
@current_user = curr_user @current_user = curr_user
end end
def method_missing(method, *args) def respond_to_missing?(method, include_private=false)
@presentable.public_send(method, *args) @presentable.respond_to?(method) || super
end
def method_missing(method, *args, **kwargs) # rubocop:disable Lint/MissingSuper
@presentable.public_send(method, *args, **kwargs)
end end
class NilPresenter class NilPresenter

View file

@ -26,12 +26,7 @@ module Workers
DiasporaFederation::Salmon::InvalidEncoding, DiasporaFederation::Salmon::InvalidEncoding,
Diaspora::Federation::AuthorIgnored, Diaspora::Federation::AuthorIgnored,
Diaspora::Federation::InvalidAuthor, Diaspora::Federation::InvalidAuthor,
Diaspora::Federation::RecipientClosed, Diaspora::Federation::RecipientClosed => e
# TODO: deprecated
DiasporaFederation::Salmon::MissingMagicEnvelope,
DiasporaFederation::Salmon::MissingAuthor,
DiasporaFederation::Salmon::MissingHeader,
DiasporaFederation::Salmon::InvalidHeader => e
logger.warn "don't retry for error: #{e.class}" logger.warn "don't retry for error: #{e.class}"
end end
end end

View file

@ -6,11 +6,11 @@
module Workers module Workers
class ReceivePrivate < ReceiveBase class ReceivePrivate < ReceiveBase
def perform(user_id, data, legacy) def perform(user_id, data)
filter_errors_for_retry do filter_errors_for_retry do
user_private_key = User.where(id: user_id).pluck(:serialized_private_key).first user_private_key = User.where(id: user_id).pluck(:serialized_private_key).first
rsa_key = OpenSSL::PKey::RSA.new(user_private_key) rsa_key = OpenSSL::PKey::RSA.new(user_private_key)
DiasporaFederation::Federation::Receiver.receive_private(data, rsa_key, user_id, legacy) DiasporaFederation::Federation::Receiver.receive_private(data, rsa_key, user_id)
end end
end end
end end

View file

@ -6,9 +6,9 @@
module Workers module Workers
class ReceivePublic < ReceiveBase class ReceivePublic < ReceiveBase
def perform(data, legacy=false) def perform(data)
filter_errors_for_retry do filter_errors_for_retry do
DiasporaFederation::Federation::Receiver.receive_public(data, legacy) DiasporaFederation::Federation::Receiver.receive_public(data)
end end
end end
end end

View file

@ -44,7 +44,6 @@ DiasporaFederation.configure do |config|
guid: person.guid, guid: person.guid,
nickname: person.username, nickname: person.username,
full_name: "#{person.profile.first_name} #{person.profile.last_name}".strip, full_name: "#{person.profile.first_name} #{person.profile.last_name}".strip,
url: AppConfig.pod_uri,
photo_large_url: person.image_url, photo_large_url: person.image_url,
photo_medium_url: person.image_url(size: :thumb_medium), photo_medium_url: person.image_url(size: :thumb_medium),
photo_small_url: person.image_url(size: :thumb_small), photo_small_url: person.image_url(size: :thumb_small),
@ -90,15 +89,15 @@ DiasporaFederation.configure do |config|
Diaspora::Federation::Entities.related_entity(entity) if entity Diaspora::Federation::Entities.related_entity(entity) if entity
end end
on :queue_public_receive do |xml, legacy=false| on :queue_public_receive do |xml|
Workers::ReceivePublic.perform_async(xml, legacy) Workers::ReceivePublic.perform_async(xml)
end end
on :queue_private_receive do |guid, xml, legacy=false| on :queue_private_receive do |guid, xml|
person = Person.find_by_guid(guid) person = Person.find_by_guid(guid)
(person.present? && person.owner_id.present?).tap do |user_found| (person.present? && person.owner_id.present?).tap do |user_found|
Workers::ReceivePrivate.perform_async(person.owner.id, xml, legacy) if user_found Workers::ReceivePrivate.perform_async(person.owner.id, xml) if user_found
end end
end end

View file

@ -20,7 +20,7 @@ options = {
} }
Faraday.default_connection = Faraday::Connection.new(options) do |b| Faraday.default_connection = Faraday::Connection.new(options) do |b|
b.use FaradayMiddleware::FollowRedirects, limit: 8 b.use Faraday::FollowRedirects::Middleware, limit: 8
b.use :cookie_jar b.use :cookie_jar
b.adapter Faraday.default_adapter b.adapter Faraday.default_adapter
end end

View file

@ -20,7 +20,7 @@ module ApplicationCukeHelpers
def flash_message(opts={}) def flash_message(opts={})
selector = opts.delete(:selector) selector = opts.delete(:selector)
selector &&= ".alert-#{selector}" selector &&= ".alert-#{selector}"
find(selector || ".flash-message", {match: :first}.merge(opts)) find(selector || ".flash-message", **{match: :first}.merge(opts))
end end
def confirm_form_validation_error(element) def confirm_form_validation_error(element)

View file

@ -63,7 +63,7 @@ module NavigationHelpers
if path.is_a?(Hash) if path.is_a?(Hash)
visit(path[:path]) visit(path[:path])
await_elem = path[:special_elem] await_elem = path[:special_elem]
find(await_elem.delete(:selector), await_elem) find(await_elem.delete(:selector), **await_elem)
else else
visit(path) visit(path)
end end

View file

@ -114,7 +114,7 @@ class ConnectionTester
raise NetFailure, e.message raise NetFailure, e.message
rescue Faraday::SSLError => e rescue Faraday::SSLError => e
raise SSLFailure, e.message raise SSLFailure, e.message
rescue ArgumentError, FaradayMiddleware::RedirectLimitReached, Faraday::ClientError => e rescue ArgumentError, Faraday::FollowRedirects::RedirectLimitReached, Faraday::ClientError => e
raise HTTPFailure, e.message raise HTTPFailure, e.message
rescue StandardError => e rescue StandardError => e
unexpected_error(e) unexpected_error(e)
@ -146,7 +146,7 @@ class ConnectionTester
def with_http_connection def with_http_connection
@http ||= Faraday.new(@url) do |c| @http ||= Faraday.new(@url) do |c|
c.use Faraday::Response::RaiseError c.use Faraday::Response::RaiseError
c.use FaradayMiddleware::FollowRedirects, limit: 3 c.use Faraday::FollowRedirects::Middleware, limit: 3
c.adapter(Faraday.default_adapter) c.adapter(Faraday.default_adapter)
c.headers[:user_agent] = "diaspora-connection-tester" c.headers[:user_agent] = "diaspora-connection-tester"
c.options.timeout = 12 c.options.timeout = 12

View file

@ -14,7 +14,7 @@ class Pubsubhubbub
conn = Faraday.new do |c| conn = Faraday.new do |c|
c.use Faraday::Request::UrlEncoded # encode request params as "www-form-urlencoded" c.use Faraday::Request::UrlEncoded # encode request params as "www-form-urlencoded"
c.use Faraday::Adapter::NetHttp # perform requests with Net::HTTP c.adapter Faraday::Adapter::NetHttp # perform requests with Net::HTTP
end end
conn.post @hub, {'hub.url' => feed, 'hub.mode' => 'publish'} conn.post @hub, {'hub.url' => feed, 'hub.mode' => 'publish'}
end end

View file

@ -50,7 +50,6 @@ describe "diaspora federation callbacks" do
expect(hcard.guid).to eq(person.guid) expect(hcard.guid).to eq(person.guid)
expect(hcard.nickname).to eq(person.username) expect(hcard.nickname).to eq(person.username)
expect(hcard.full_name).to eq("#{person.profile.first_name} #{person.profile.last_name}") expect(hcard.full_name).to eq("#{person.profile.first_name} #{person.profile.last_name}")
expect(hcard.url).to eq(AppConfig.pod_uri)
expect(hcard.photo_large_url).to eq(person.image_url) expect(hcard.photo_large_url).to eq(person.image_url)
expect(hcard.photo_medium_url).to eq(person.image_url(size: :thumb_medium)) expect(hcard.photo_medium_url).to eq(person.image_url(size: :thumb_medium))
expect(hcard.photo_small_url).to eq(person.image_url(size: :thumb_small)) expect(hcard.photo_small_url).to eq(person.image_url(size: :thumb_small))
@ -310,9 +309,9 @@ describe "diaspora federation callbacks" do
describe ":queue_public_receive" do describe ":queue_public_receive" do
it "enqueues a ReceivePublic job" do it "enqueues a ReceivePublic job" do
data = "<diaspora/>" data = "<diaspora/>"
expect(Workers::ReceivePublic).to receive(:perform_async).with(data, true) expect(Workers::ReceivePublic).to receive(:perform_async).with(data)
DiasporaFederation.callbacks.trigger(:queue_public_receive, data, true) DiasporaFederation.callbacks.trigger(:queue_public_receive, data)
end end
end end
@ -325,19 +324,19 @@ describe "diaspora federation callbacks" do
end end
it "enqueues a ReceivePrivate job" do it "enqueues a ReceivePrivate job" do
expect(Workers::ReceivePrivate).to receive(:perform_async).with(alice.id, data, true) expect(Workers::ReceivePrivate).to receive(:perform_async).with(alice.id, data)
DiasporaFederation.callbacks.trigger(:queue_private_receive, alice.person.guid, data, true) DiasporaFederation.callbacks.trigger(:queue_private_receive, alice.person.guid, data)
end end
it "returns false if the no user is found" do it "returns false if the no user is found" do
person = FactoryBot.create(:person) person = FactoryBot.create(:person)
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, person.guid, data, true) result = DiasporaFederation.callbacks.trigger(:queue_private_receive, person.guid, data)
expect(result).to be_falsey expect(result).to be_falsey
end end
it "returns false if the no person is found" do it "returns false if the no person is found" do
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, "2398rq3948yftn", data, true) result = DiasporaFederation.callbacks.trigger(:queue_private_receive, "2398rq3948yftn", data)
expect(result).to be_falsey expect(result).to be_falsey
end end
end end

View file

@ -55,10 +55,6 @@ def allow_callbacks(callbacks)
end end
def create_relayable_entity(entity_name, parent, diaspora_id) def create_relayable_entity(entity_name, parent, diaspora_id)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key, alice.diaspora_handle
).at_least(1).times.and_return(nil) if parent == local_parent
Fabricate( Fabricate(
entity_name, entity_name,
parent_guid: parent.guid, parent_guid: parent.guid,

View file

@ -71,7 +71,7 @@ describe Retraction do
expect(Workers::DeferredRetraction).to receive(:perform_async).with( expect(Workers::DeferredRetraction).to receive(:perform_async).with(
local_luke.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [remote_raphael.id], local_luke.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [remote_raphael.id],
"service_types" => [] {"service_types" => []}
) )
retraction.defer_dispatch(local_luke) retraction.defer_dispatch(local_luke)
@ -87,7 +87,7 @@ describe Retraction do
expect(Workers::DeferredRetraction).to receive(:perform_async).with( expect(Workers::DeferredRetraction).to receive(:perform_async).with(
alice.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [], alice.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [],
"service_types" => ["Services::Twitter"], "tweet_id" => "123" {"service_types" => ["Services::Twitter"], "tweet_id" => "123"}
) )
retraction.defer_dispatch(alice) retraction.defer_dispatch(alice)
@ -98,7 +98,7 @@ describe Retraction do
federation_retraction = Diaspora::Federation::Entities.retraction(retraction) federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
expect(Workers::DeferredRetraction).to receive(:perform_async).with( expect(Workers::DeferredRetraction).to receive(:perform_async).with(
alice.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [], "service_types" => [] alice.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [], {"service_types" => []}
) )
retraction.defer_dispatch(alice) retraction.defer_dispatch(alice)

View file

@ -181,7 +181,7 @@ describe User::Connecting, type: :model do
it "delivers profile for remote persons" do it "delivers profile for remote persons" do
allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
expect(Diaspora::Federation::Dispatcher) expect(Diaspora::Federation::Dispatcher)
.to receive(:defer_dispatch).with(alice, alice.profile, subscriber_ids: [remote_raphael.id]) .to receive(:defer_dispatch).with(alice, alice.profile, {subscriber_ids: [remote_raphael.id]})
alice.share_with(remote_raphael, alice.aspects.first) alice.share_with(remote_raphael, alice.aspects.first)
end end

View file

@ -6,8 +6,7 @@ describe Workers::Mail::InviteEmail do
let(:email_inviter) { double('EmailInviter') } let(:email_inviter) { double('EmailInviter') }
it 'creates a new email inviter' do it 'creates a new email inviter' do
expect(EmailInviter).to receive(:new).with(emails, alice, message: message) expect(EmailInviter).to receive(:new).with(emails, alice, {message: message}).and_return(email_inviter)
.and_return(email_inviter)
expect(email_inviter).to receive(:send!) expect(email_inviter).to receive(:send!)
Workers::Mail::InviteEmail.new.perform(emails, alice.id, message: message) Workers::Mail::InviteEmail.new.perform(emails, alice.id, message: message)
end end

View file

@ -7,9 +7,9 @@ describe Workers::ReceivePrivate do
rsa_key = double rsa_key = double
expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key) expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key)
expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with(data, rsa_key, alice.id, true) expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with(data, rsa_key, alice.id)
Workers::ReceivePrivate.new.perform(alice.id, data, true) Workers::ReceivePrivate.new.perform(alice.id, data)
end end
it "filters errors that would also fail on second try" do it "filters errors that would also fail on second try" do
@ -17,11 +17,11 @@ describe Workers::ReceivePrivate do
expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key) expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key)
expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with( expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with(
data, rsa_key, alice.id, false data, rsa_key, alice.id
).and_raise(DiasporaFederation::Salmon::InvalidSignature) ).and_raise(DiasporaFederation::Salmon::InvalidSignature)
expect { expect {
Workers::ReceivePrivate.new.perform(alice.id, data, false) Workers::ReceivePrivate.new.perform(alice.id, data)
}.not_to raise_error }.not_to raise_error
end end
@ -30,11 +30,11 @@ describe Workers::ReceivePrivate do
expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key) expect(OpenSSL::PKey::RSA).to receive(:new).with(alice.serialized_private_key).and_return(rsa_key)
expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with( expect(DiasporaFederation::Federation::Receiver).to receive(:receive_private).with(
data, rsa_key, alice.id, false data, rsa_key, alice.id
).and_raise(DiasporaFederation::Federation::Fetcher::NotFetchable) ).and_raise(DiasporaFederation::Federation::Fetcher::NotFetchable)
expect { expect {
Workers::ReceivePrivate.new.perform(alice.id, data, false) Workers::ReceivePrivate.new.perform(alice.id, data)
}.to raise_error DiasporaFederation::Federation::Fetcher::NotFetchable }.to raise_error DiasporaFederation::Federation::Fetcher::NotFetchable
end end
end end

View file

@ -4,28 +4,26 @@ describe Workers::ReceivePublic do
let(:data) { "<xml></xml>" } let(:data) { "<xml></xml>" }
it "calls receive_public of federation gem" do it "calls receive_public of federation gem" do
expect(DiasporaFederation::Federation::Receiver).to receive(:receive_public).with(data, true) expect(DiasporaFederation::Federation::Receiver).to receive(:receive_public).with(data)
Workers::ReceivePublic.new.perform(data, true) Workers::ReceivePublic.new.perform(data)
end end
it "filters errors that would also fail on second try" do it "filters errors that would also fail on second try" do
expect(DiasporaFederation::Federation::Receiver).to receive(:receive_public).with( expect(DiasporaFederation::Federation::Receiver)
data, false .to receive(:receive_public).with(data).and_raise(DiasporaFederation::Salmon::InvalidSignature)
).and_raise(DiasporaFederation::Salmon::InvalidSignature)
expect { expect {
Workers::ReceivePublic.new.perform(data, false) Workers::ReceivePublic.new.perform(data)
}.not_to raise_error }.not_to raise_error
end end
it "does not filter errors that would succeed on second try" do it "does not filter errors that would succeed on second try" do
expect(DiasporaFederation::Federation::Receiver).to receive(:receive_public).with( expect(DiasporaFederation::Federation::Receiver)
data, false .to receive(:receive_public).with(data).and_raise(DiasporaFederation::Federation::Fetcher::NotFetchable)
).and_raise(DiasporaFederation::Federation::Fetcher::NotFetchable)
expect { expect {
Workers::ReceivePublic.new.perform(data, false) Workers::ReceivePublic.new.perform(data)
}.to raise_error DiasporaFederation::Federation::Fetcher::NotFetchable }.to raise_error DiasporaFederation::Federation::Fetcher::NotFetchable
end end
end end