diff --git a/spec/controllers/diaspora_federation/fetch_controller_spec.rb b/spec/controllers/diaspora_federation/fetch_controller_spec.rb
index 7031f2d..a43f14d 100644
--- a/spec/controllers/diaspora_federation/fetch_controller_spec.rb
+++ b/spec/controllers/diaspora_federation/fetch_controller_spec.rb
@@ -7,18 +7,12 @@ module DiasporaFederation
describe "GET #fetch" do
it "returns the magic-envelope with the status message" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_entity, "StatusMessage", guid
- ).and_return(post)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, alice.diaspora_id
- ).and_return(alice.private_key)
+ expect_callback(:fetch_public_entity, "StatusMessage", guid).and_return(post)
+ expect_callback(:fetch_private_key, alice.diaspora_id).and_return(alice.private_key)
get :fetch, type: "status_message", guid: guid
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, alice.diaspora_id
- ).and_return(alice.public_key)
+ expect_callback(:fetch_public_key, alice.diaspora_id).and_return(alice.public_key)
magic_env_xml = Nokogiri::XML::Document.parse(response.body).root
magic_env = Salmon::MagicEnvelope.unenvelop(magic_env_xml)
@@ -32,18 +26,12 @@ module DiasporaFederation
end
it "works with type 'post'" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_entity, "Post", guid
- ).and_return(post)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, alice.diaspora_id
- ).and_return(alice.private_key)
+ expect_callback(:fetch_public_entity, "Post", guid).and_return(post)
+ expect_callback(:fetch_private_key, alice.diaspora_id).and_return(alice.private_key)
get :fetch, type: "post", guid: guid
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, alice.diaspora_id
- ).and_return(alice.public_key)
+ expect_callback(:fetch_public_key, alice.diaspora_id).and_return(alice.public_key)
magic_env_xml = Nokogiri::XML::Document.parse(response.body).root
magic_env = Salmon::MagicEnvelope.unenvelop(magic_env_xml)
@@ -57,15 +45,10 @@ module DiasporaFederation
end
it "redirects when the entity is from another pod" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_entity, "Post", guid
- ).and_return(post)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, alice.diaspora_id
- ).and_return(nil)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_person_url_to, alice.diaspora_id, "/fetch/post/#{guid}"
- ).and_return("http://example.org/fetch/post/#{guid}")
+ expect_callback(:fetch_public_entity, "Post", guid).and_return(post)
+ expect_callback(:fetch_private_key, alice.diaspora_id).and_return(nil)
+ expect_callback(:fetch_person_url_to, alice.diaspora_id, "/fetch/post/#{guid}")
+ .and_return("http://example.org/fetch/post/#{guid}")
get :fetch, type: "post", guid: guid
@@ -74,9 +57,7 @@ module DiasporaFederation
end
it "404s when the post does not exist" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_entity, "Post", guid
- ).and_return(nil)
+ expect_callback(:fetch_public_entity, "Post", guid).and_return(nil)
get :fetch, type: "post", guid: guid
diff --git a/spec/controllers/diaspora_federation/h_card_controller_spec.rb b/spec/controllers/diaspora_federation/h_card_controller_spec.rb
index 83544eb..113150a 100644
--- a/spec/controllers/diaspora_federation/h_card_controller_spec.rb
+++ b/spec/controllers/diaspora_federation/h_card_controller_spec.rb
@@ -25,9 +25,7 @@ module DiasporaFederation
end
it "calls the fetch_person_for_hcard callback" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_person_for_hcard, alice.guid
- ).and_call_original
+ expect_callback(:fetch_person_for_hcard, alice.guid).and_call_original
get :hcard, "guid" => alice.guid
end
diff --git a/spec/controllers/diaspora_federation/receive_controller_spec.rb b/spec/controllers/diaspora_federation/receive_controller_spec.rb
index 5acbe14..b349c1a 100644
--- a/spec/controllers/diaspora_federation/receive_controller_spec.rb
+++ b/spec/controllers/diaspora_federation/receive_controller_spec.rb
@@ -16,14 +16,14 @@ module DiasporaFederation
end
it "returns a 202 if queued correctly" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(:queue_public_receive, "", true)
+ expect_callback(:queue_public_receive, "", true)
post :public, xml: ""
expect(response.code).to eq("202")
end
it "unescapes the xml before sending it to the callback" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(:queue_public_receive, "", true)
+ expect_callback(:queue_public_receive, "", true)
post :public, xml: CGI.escape("")
end
@@ -35,7 +35,7 @@ module DiasporaFederation
end
it "returns a 202 if queued correctly" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(:queue_public_receive, "", false)
+ expect_callback(:queue_public_receive, "", false)
post :public, ""
expect(response.code).to eq("202")
@@ -46,9 +46,7 @@ module DiasporaFederation
describe "POST #private" do
context "legacy salmon slap" do
it "return a 404 if not queued successfully (unknown user guid)" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :queue_private_receive, "any-guid", "", true
- ).and_return(false)
+ expect_callback(:queue_private_receive, "any-guid", "", true).and_return(false)
post :private, guid: "any-guid", xml: ""
expect(response.code).to eq("404")
@@ -66,18 +64,14 @@ module DiasporaFederation
end
it "returns a 202 if the callback returned true" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :queue_private_receive, "any-guid", "", true
- ).and_return(true)
+ expect_callback(:queue_private_receive, "any-guid", "", true).and_return(true)
post :private, guid: "any-guid", xml: ""
expect(response.code).to eq("202")
end
it "unescapes the xml before sending it to the callback" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :queue_private_receive, "any-guid", "", true
- ).and_return(true)
+ expect_callback(:queue_private_receive, "any-guid", "", true).and_return(true)
post :private, guid: "any-guid", xml: CGI.escape("")
end
@@ -89,7 +83,7 @@ module DiasporaFederation
end
it "return a 404 if not queued successfully (unknown user guid)" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
+ expect_callback(
:queue_private_receive, "any-guid", "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", false
).and_return(false)
@@ -98,7 +92,7 @@ module DiasporaFederation
end
it "returns a 202 if the callback returned true" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
+ expect_callback(
:queue_private_receive, "any-guid", "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", false
).and_return(true)
diff --git a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb
index 85ff894..8c8c946 100644
--- a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb
+++ b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb
@@ -59,9 +59,7 @@ module DiasporaFederation
end
it "calls the fetch_person_for_webfinger callback" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_person_for_webfinger, "alice@localhost:3000"
- ).and_call_original
+ expect_callback(:fetch_person_for_webfinger, "alice@localhost:3000").and_call_original
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
end
diff --git a/spec/integration/comment_integration_spec.rb b/spec/integration/comment_integration_spec.rb
index e77c906..c99fdc9 100644
--- a/spec/integration/comment_integration_spec.rb
+++ b/spec/integration/comment_integration_spec.rb
@@ -187,26 +187,16 @@ XML
# this was used to create the XMLs above
context "test-data creation" do
it "creates comment xml" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, author
- ).and_return(author_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, parent.author
- ).and_return(nil)
+ expect_callback(:fetch_private_key, author).and_return(author_key)
+ expect_callback(:fetch_private_key, parent.author).and_return(nil)
comment.to_xml
end
it "creates relayed comment xml" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_key.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, parent.author
- ).and_return(parent_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_related_entity, "Post", parent_guid
- ).and_return(parent)
+ expect_callback(:fetch_public_key, author).and_return(author_key.public_key)
+ expect_callback(:fetch_private_key, parent.author).and_return(parent_key)
+ expect_callback(:fetch_related_entity, "Post", parent_guid).and_return(parent)
xml = Nokogiri::XML::Document.parse(new_data_comment_xml_alice).root
Salmon::XmlPayload.unpack(xml).to_xml
@@ -215,15 +205,9 @@ XML
context "relaying on bobs pod" do
before do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_key.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, parent.author
- ).and_return(parent_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_related_entity, "Post", parent_guid
- ).and_return(parent)
+ expect_callback(:fetch_public_key, author).and_return(author_key.public_key)
+ expect_callback(:fetch_private_key, parent.author).and_return(parent_key)
+ expect_callback(:fetch_related_entity, "Post", parent_guid).and_return(parent)
end
it "relays legacy signatures and xml" do
@@ -249,15 +233,9 @@ XML
let(:parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id, local: false) }
before do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_key.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, parent.author
- ).and_return(parent_key.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_related_entity, "Post", parent_guid
- ).and_return(parent)
+ expect_callback(:fetch_public_key, author).and_return(author_key.public_key)
+ expect_callback(:fetch_public_key, parent.author).and_return(parent_key.public_key)
+ expect_callback(:fetch_related_entity, "Post", parent_guid).and_return(parent)
end
it "parses legacy signatures and xml" do
diff --git a/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb b/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb
index 4a2580c..2613443 100644
--- a/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb
+++ b/spec/lib/diaspora_federation/entities/relayable_retraction_spec.rb
@@ -44,9 +44,7 @@ XML
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) }
it "updates author signature when it was nil and key was supplied" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, hash[:author]
- ).and_return(author_pkey)
+ expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
signed_string = "#{hash[:target_guid]};#{hash[:target_type]}"
@@ -60,9 +58,7 @@ XML
parent = FactoryGirl.build(:related_entity, author: hash[:author])
hash[:target] = FactoryGirl.build(:related_entity, author: bob.diaspora_id, parent: parent)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, hash[:author]
- ).and_return(author_pkey)
+ expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
signed_string = "#{hash[:target_guid]};#{hash[:target_type]}"
@@ -82,9 +78,7 @@ XML
end
it "doesn't change signatures if keys weren't supplied" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, hash[:author]
- ).and_return(nil)
+ expect_callback(:fetch_private_key, hash[:author]).and_return(nil)
xml = Entities::RelayableRetraction.new(hash).to_xml
expect(xml.at_xpath("target_author_signature").text).to eq("")
diff --git a/spec/lib/diaspora_federation/entities/relayable_spec.rb b/spec/lib/diaspora_federation/entities/relayable_spec.rb
index 80c8972..83be123 100644
--- a/spec/lib/diaspora_federation/entities/relayable_spec.rb
+++ b/spec/lib/diaspora_federation/entities/relayable_spec.rb
@@ -42,20 +42,14 @@ module DiasporaFederation
hash[:parent_author_signature] = sign_with_key(parent_pkey, legacy_signature_data)
hash[:parent] = remote_parent
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, remote_parent.author
- ).and_return(parent_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, remote_parent.author).and_return(parent_pkey.public_key)
expect { SomeRelayable.new(hash).verify_signatures }.not_to raise_error
end
it "raises when no public key for author was fetched" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, anything
- ).and_return(nil)
+ expect_callback(:fetch_public_key, anything).and_return(nil)
expect {
SomeRelayable.new(hash).verify_signatures
@@ -65,9 +59,7 @@ module DiasporaFederation
it "raises when bad author signature was passed" do
hash[:author_signature] = nil
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
expect {
SomeRelayable.new(hash).verify_signatures
@@ -78,12 +70,8 @@ module DiasporaFederation
hash[:author_signature] = sign_with_key(author_pkey, legacy_signature_data)
hash[:parent] = remote_parent
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, remote_parent.author
- ).and_return(nil)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, remote_parent.author).and_return(nil)
expect {
SomeRelayable.new(hash).verify_signatures
@@ -95,12 +83,8 @@ module DiasporaFederation
hash[:parent_author_signature] = nil
hash[:parent] = remote_parent
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, remote_parent.author
- ).and_return(parent_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, remote_parent.author).and_return(parent_pkey.public_key)
expect {
SomeRelayable.new(hash).verify_signatures
@@ -112,9 +96,7 @@ module DiasporaFederation
hash[:parent_author_signature] = nil
hash[:parent] = local_parent
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
expect { SomeRelayable.new(hash).verify_signatures }.not_to raise_error
end
@@ -128,12 +110,8 @@ module DiasporaFederation
hash[:parent_author_signature] = sign_with_key(parent_pkey, signature_data)
hash[:parent] = remote_parent
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, remote_parent.author
- ).and_return(parent_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, remote_parent.author).and_return(parent_pkey.public_key)
expect { SomeRelayable.new(hash, xml_order).verify_signatures }.not_to raise_error
end
@@ -146,12 +124,8 @@ module DiasporaFederation
hash[:parent_author_signature] = sign_with_key(parent_pkey, signature_data_with_new_property)
hash[:parent] = remote_parent
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, remote_parent.author
- ).and_return(parent_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, remote_parent.author).and_return(parent_pkey.public_key)
expect {
SomeRelayable.new(hash, xml_order, "new_property" => new_property).verify_signatures
@@ -161,9 +135,7 @@ module DiasporaFederation
it "raises with legacy-signatures and with new property and order" do
hash[:author_signature] = sign_with_key(author_pkey, legacy_signature_data)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
xml_order = [:author, :guid, :parent_guid, :property, "new_property"]
expect {
@@ -195,12 +167,8 @@ XML
end
it "computes correct signatures for the entity" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, author
- ).and_return(author_pkey)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, local_parent.author
- ).and_return(parent_pkey)
+ expect_callback(:fetch_private_key, author).and_return(author_pkey)
+ expect_callback(:fetch_private_key, local_parent.author).and_return(parent_pkey)
xml = SomeRelayable.new(hash).to_xml
@@ -212,12 +180,8 @@ XML
end
it "computes correct signatures for the entity with new unknown xml elements" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, author
- ).and_return(author_pkey)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, local_parent.author
- ).and_return(parent_pkey)
+ expect_callback(:fetch_private_key, author).and_return(author_pkey)
+ expect_callback(:fetch_private_key, local_parent.author).and_return(parent_pkey)
xml_order = [:author, :guid, :parent_guid, "new_property", :property]
signature_data_with_new_property = "#{author};#{guid};#{parent_guid};#{new_property};#{property}"
@@ -241,9 +205,7 @@ XML
end
it "raises when author_signature not set and key isn't supplied" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, author
- ).and_return(nil)
+ expect_callback(:fetch_private_key, author).and_return(nil)
expect {
SomeRelayable.new(hash).to_xml
@@ -251,12 +213,8 @@ XML
end
it "doesn't set parent_author_signature if key isn't supplied" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, author
- ).and_return(author_pkey)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, local_parent.author
- ).and_return(nil)
+ expect_callback(:fetch_private_key, author).and_return(author_pkey)
+ expect_callback(:fetch_private_key, local_parent.author).and_return(nil)
xml = SomeRelayable.new(hash).to_xml
@@ -266,19 +224,13 @@ XML
describe ".from_xml" do
before do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_related_entity, "Parent", parent_guid
- ).and_return(remote_parent)
+ expect_callback(:fetch_related_entity, "Parent", parent_guid).and_return(remote_parent)
end
context "parsing" do
before do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, remote_parent.author
- ).and_return(parent_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, remote_parent.author).and_return(parent_pkey.public_key)
end
let(:new_signature_data) { "#{author};#{guid};#{parent_guid};#{new_property};#{property}" }
@@ -334,9 +286,7 @@ XML
xml = SomeRelayable.new(hash).to_xml
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, author
- ).and_return(author_pkey.public_key)
+ expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
expect {
SomeRelayable.from_xml(xml)
diff --git a/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb b/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb
index 0463ec7..cd5652c 100644
--- a/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb
+++ b/spec/lib/diaspora_federation/entities/signed_retraction_spec.rb
@@ -34,9 +34,7 @@ XML
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) }
it "updates author signature when it was nil and key was supplied" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, hash[:author]
- ).and_return(author_pkey)
+ expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
signed_string = "#{hash[:target_guid]};#{hash[:target_type]}"
@@ -55,9 +53,7 @@ XML
end
it "doesn't change signature if a key wasn't supplied" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_private_key, hash[:author]
- ).and_return(nil)
+ expect_callback(:fetch_private_key, hash[:author]).and_return(nil)
xml = Entities::SignedRetraction.new(hash).to_xml
expect(xml.at_xpath("target_author_signature").text).to eq("")
diff --git a/spec/lib/diaspora_federation/federation/fetcher_spec.rb b/spec/lib/diaspora_federation/federation/fetcher_spec.rb
index e31a812..1dcdddf 100644
--- a/spec/lib/diaspora_federation/federation/fetcher_spec.rb
+++ b/spec/lib/diaspora_federation/federation/fetcher_spec.rb
@@ -8,12 +8,9 @@ module DiasporaFederation
stub_request(:get, "https://example.org/fetch/post/#{post.guid}")
.to_return(status: 200, body: post_magic_env)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_person_url_to, post.author, "/fetch/post/#{post.guid}"
- ).and_return("https://example.org/fetch/post/#{post.guid}")
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, post.author
- ).and_return(alice.public_key)
+ expect_callback(:fetch_person_url_to, post.author, "/fetch/post/#{post.guid}")
+ .and_return("https://example.org/fetch/post/#{post.guid}")
+ expect_callback(:fetch_public_key, post.author).and_return(alice.public_key)
receiver = double
expect(Federation::Receiver::Public).to receive(:new).with(
@@ -36,12 +33,9 @@ module DiasporaFederation
stub_request(:get, "https://example.com/fetch/post/#{post.guid}")
.to_return(status: 200, body: post_magic_env)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_person_url_to, post.author, "/fetch/post/#{post.guid}"
- ).and_return("https://example.org/fetch/post/#{post.guid}")
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, post.author
- ).and_return(alice.public_key)
+ expect_callback(:fetch_person_url_to, post.author, "/fetch/post/#{post.guid}")
+ .and_return("https://example.org/fetch/post/#{post.guid}")
+ expect_callback(:fetch_public_key, post.author).and_return(alice.public_key)
receiver = double
expect(Federation::Receiver::Public).to receive(:new).with(
@@ -56,9 +50,8 @@ module DiasporaFederation
stub_request(:get, "https://example.org/fetch/post/#{post.guid}")
.to_return(status: 404)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_person_url_to, post.author, "/fetch/post/#{post.guid}"
- ).and_return("https://example.org/fetch/post/#{post.guid}")
+ expect_callback(:fetch_person_url_to, post.author, "/fetch/post/#{post.guid}")
+ .and_return("https://example.org/fetch/post/#{post.guid}")
expect {
Federation::Fetcher.fetch_public(post.author, :post, post.guid)
@@ -70,9 +63,8 @@ module DiasporaFederation
"https://example.org/fetch/post/#{post.guid}"
).and_raise(Faraday::ConnectionFailed, "Couldn't connect to server")
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_person_url_to, post.author, "/fetch/post/#{post.guid}"
- ).and_return("https://example.org/fetch/post/#{post.guid}")
+ expect_callback(:fetch_person_url_to, post.author, "/fetch/post/#{post.guid}")
+ .and_return("https://example.org/fetch/post/#{post.guid}")
expect {
Federation::Fetcher.fetch_public(post.author, :post, post.guid)
diff --git a/spec/lib/diaspora_federation/federation/receiver/private_spec.rb b/spec/lib/diaspora_federation/federation/receiver/private_spec.rb
index bf56f20..e043df7 100644
--- a/spec/lib/diaspora_federation/federation/receiver/private_spec.rb
+++ b/spec/lib/diaspora_federation/federation/receiver/private_spec.rb
@@ -6,7 +6,7 @@ module DiasporaFederation
describe "#receive" do
it "receives a private post" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(:receive_entity, entity, recipient)
+ expect_callback(:receive_entity, entity, recipient)
described_class.new(magic_env, recipient).receive
end
diff --git a/spec/lib/diaspora_federation/federation/receiver/public_spec.rb b/spec/lib/diaspora_federation/federation/receiver/public_spec.rb
index f6bbec6..1318e9c 100644
--- a/spec/lib/diaspora_federation/federation/receiver/public_spec.rb
+++ b/spec/lib/diaspora_federation/federation/receiver/public_spec.rb
@@ -5,7 +5,7 @@ module DiasporaFederation
describe "#receive" do
it "receives a public post" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(:receive_entity, entity, nil)
+ expect_callback(:receive_entity, entity, nil)
described_class.new(magic_env).receive
end
diff --git a/spec/lib/diaspora_federation/federation/receiver_spec.rb b/spec/lib/diaspora_federation/federation/receiver_spec.rb
index da07828..643c1ef 100644
--- a/spec/lib/diaspora_federation/federation/receiver_spec.rb
+++ b/spec/lib/diaspora_federation/federation/receiver_spec.rb
@@ -7,15 +7,11 @@ module DiasporaFederation
let(:post) { FactoryGirl.build(:status_message_entity) }
it "parses the entity with magic envelope receiver" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, post.author
- ).and_return(sender_key)
+ expect_callback(:fetch_public_key, post.author).and_return(sender_key)
data = Salmon::MagicEnvelope.new(post, post.author).envelop(sender_key).to_xml
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :receive_entity, kind_of(Entities::StatusMessage), nil
- ) do |_, entity|
+ expect_callback(:receive_entity, kind_of(Entities::StatusMessage), nil) do |_, entity|
expect(entity.guid).to eq(post.guid)
expect(entity.author).to eq(post.author)
expect(entity.raw_message).to eq(post.raw_message)
@@ -26,15 +22,11 @@ module DiasporaFederation
end
it "parses the entity with legacy slap receiver" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, post.author
- ).and_return(sender_key)
+ expect_callback(:fetch_public_key, post.author).and_return(sender_key)
data = DiasporaFederation::Salmon::Slap.generate_xml(post.author, sender_key, post)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :receive_entity, kind_of(Entities::StatusMessage), nil
- ) do |_, entity|
+ expect_callback(:receive_entity, kind_of(Entities::StatusMessage), nil) do |_, entity|
expect(entity.guid).to eq(post.guid)
expect(entity.author).to eq(post.author)
expect(entity.raw_message).to eq(post.raw_message)
@@ -49,16 +41,12 @@ module DiasporaFederation
let(:post) { FactoryGirl.build(:status_message_entity, public: false) }
it "parses the entity with magic envelope receiver" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, post.author
- ).and_return(sender_key)
+ expect_callback(:fetch_public_key, post.author).and_return(sender_key)
magic_env = Salmon::MagicEnvelope.new(post, post.author).envelop(sender_key)
data = Salmon::EncryptedMagicEnvelope.encrypt(magic_env, recipient_key.public_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :receive_entity, kind_of(Entities::StatusMessage), 1234
- ) do |_, entity|
+ expect_callback(:receive_entity, kind_of(Entities::StatusMessage), 1234) do |_, entity|
expect(entity.guid).to eq(post.guid)
expect(entity.author).to eq(post.author)
expect(entity.raw_message).to eq(post.raw_message)
@@ -69,16 +57,12 @@ module DiasporaFederation
end
it "parses the entity with legacy slap receiver" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, post.author
- ).and_return(sender_key)
+ expect_callback(:fetch_public_key, post.author).and_return(sender_key)
data = DiasporaFederation::Salmon::EncryptedSlap.prepare(post.author, sender_key, post)
.generate_xml(recipient_key)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :receive_entity, kind_of(Entities::StatusMessage), 1234
- ) do |_, entity|
+ expect_callback(:receive_entity, kind_of(Entities::StatusMessage), 1234) do |_, entity|
expect(entity.guid).to eq(post.guid)
expect(entity.author).to eq(post.author)
expect(entity.raw_message).to eq(post.raw_message)
diff --git a/spec/lib/diaspora_federation/federation/sender/hydra_wrapper_spec.rb b/spec/lib/diaspora_federation/federation/sender/hydra_wrapper_spec.rb
index 5ea7917..649d555 100644
--- a/spec/lib/diaspora_federation/federation/sender/hydra_wrapper_spec.rb
+++ b/spec/lib/diaspora_federation/federation/sender/hydra_wrapper_spec.rb
@@ -69,16 +69,15 @@ module DiasporaFederation
end
it "calls the update_pod callback for all responses with effective_url and status" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(:update_pod, "https://example.org/", 202)
- expect(DiasporaFederation.callbacks).to receive(:trigger)
- .with(:update_pod, "http://example.com/", :couldnt_resolve_host)
+ expect_callback(:update_pod, "https://example.org/", 202)
+ expect_callback(:update_pod, "http://example.com/", :couldnt_resolve_host)
hydra_wrapper.send
end
it "calls the update_pod callback with http status code when there was no error" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(:update_pod, "https://example.org/", 202)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(:update_pod, "http://example.net/", 404)
+ expect_callback(:update_pod, "https://example.org/", 202)
+ expect_callback(:update_pod, "http://example.net/", 404)
allow(DiasporaFederation.callbacks).to receive(:trigger)
not_found = Typhoeus::Response.new(
diff --git a/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb b/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb
index 8023d9d..ac6d0d8 100644
--- a/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb
+++ b/spec/lib/diaspora_federation/salmon/encrypted_slap_spec.rb
@@ -139,9 +139,7 @@ module DiasporaFederation
describe ".from_xml" do
context "sanity" do
it "accepts correct params" do
- allow(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, sender
- ).and_return(privkey.public_key)
+ expect_callback(:fetch_public_key, sender).and_return(privkey.public_key)
expect {
Salmon::EncryptedSlap.from_xml(slap_xml, recipient_key)
diff --git a/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb b/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb
index c879b57..1d1c72e 100644
--- a/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb
+++ b/spec/lib/diaspora_federation/salmon/magic_envelope_spec.rb
@@ -139,9 +139,7 @@ module DiasporaFederation
other_sender = FactoryGirl.generate(:diaspora_id)
other_key = OpenSSL::PKey::RSA.generate(512)
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, other_sender
- ).and_return(other_key)
+ expect_callback(:fetch_public_key, other_sender).and_return(other_key)
expect {
Salmon::MagicEnvelope.unenvelop(envelope.envelop(privkey), other_sender)
@@ -174,9 +172,7 @@ module DiasporaFederation
end
it "decrypts on the fly, when cipher params are present" do
- allow(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, sender
- ).and_return(privkey.public_key)
+ expect_callback(:fetch_public_key, sender).and_return(privkey.public_key)
env = Salmon::MagicEnvelope.new(payload)
params = env.encrypt!
@@ -205,9 +201,7 @@ module DiasporaFederation
end
it "raises if the sender key is not found" do
- expect(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, sender
- ).and_return(nil)
+ expect_callback(:fetch_public_key, sender).and_return(nil)
expect {
Salmon::MagicEnvelope.unenvelop(envelope.envelop(privkey))
diff --git a/spec/lib/diaspora_federation/salmon/slap_spec.rb b/spec/lib/diaspora_federation/salmon/slap_spec.rb
index 2d597d0..5143e70 100644
--- a/spec/lib/diaspora_federation/salmon/slap_spec.rb
+++ b/spec/lib/diaspora_federation/salmon/slap_spec.rb
@@ -50,9 +50,7 @@ module DiasporaFederation
describe ".from_xml" do
context "sanity" do
it "accepts salmon xml as param" do
- allow(DiasporaFederation.callbacks).to receive(:trigger).with(
- :fetch_public_key, sender
- ).and_return(privkey.public_key)
+ expect_callback(:fetch_public_key, sender).and_return(privkey.public_key)
expect {
Salmon::Slap.from_xml(slap_xml)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 0e5ca61..33dc68a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -37,6 +37,10 @@ def bob
@bob ||= Person.find_by(diaspora_id: "bob@localhost:3000")
end
+def expect_callback(*opts)
+ expect(DiasporaFederation.callbacks).to receive(:trigger).with(*opts)
+end
+
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
fixture_builder_file = "#{File.dirname(__FILE__)}/support/fixture_builder.rb"