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