add ParentNotFound error, if parent can't be fetched
This commit is contained in:
parent
d218a5dd2f
commit
5a9ba266b4
2 changed files with 20 additions and 2 deletions
|
|
@ -216,6 +216,7 @@ module DiasporaFederation
|
||||||
# fetch and receive parent from remote, if not available locally
|
# fetch and receive parent from remote, if not available locally
|
||||||
Federation::Fetcher.fetch_public(data[:author], type, guid)
|
Federation::Fetcher.fetch_public(data[:author], type, guid)
|
||||||
data[:parent] = DiasporaFederation.callbacks.trigger(:fetch_related_entity, type, guid)
|
data[:parent] = DiasporaFederation.callbacks.trigger(:fetch_related_entity, type, guid)
|
||||||
|
raise ParentNotFound unless data[:parent]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -231,6 +232,10 @@ module DiasporaFederation
|
||||||
# Raised, if verify_signatures fails to verify signatures (signatures are wrong)
|
# Raised, if verify_signatures fails to verify signatures (signatures are wrong)
|
||||||
class SignatureVerificationFailed < RuntimeError
|
class SignatureVerificationFailed < RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised, if parent was not found and can't be fetched
|
||||||
|
class ParentNotFound < RuntimeError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -297,8 +297,6 @@ XML
|
||||||
|
|
||||||
context "fetch parent" do
|
context "fetch parent" do
|
||||||
before do
|
before do
|
||||||
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_callback(:fetch_private_key, author).and_return(author_pkey)
|
expect_callback(:fetch_private_key, author).and_return(author_pkey)
|
||||||
expect_callback(:fetch_private_key, remote_parent.author).and_return(parent_pkey)
|
expect_callback(:fetch_private_key, remote_parent.author).and_return(parent_pkey)
|
||||||
end
|
end
|
||||||
|
|
@ -306,6 +304,9 @@ XML
|
||||||
let(:xml) { SomeRelayable.new(hash).to_xml }
|
let(:xml) { SomeRelayable.new(hash).to_xml }
|
||||||
|
|
||||||
it "fetches the parent from the backend" do
|
it "fetches the parent from the backend" do
|
||||||
|
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_callback(:fetch_related_entity, "Parent", parent_guid).and_return(remote_parent)
|
expect_callback(:fetch_related_entity, "Parent", parent_guid).and_return(remote_parent)
|
||||||
expect(Federation::Fetcher).not_to receive(:fetch_public)
|
expect(Federation::Fetcher).not_to receive(:fetch_public)
|
||||||
|
|
||||||
|
|
@ -315,6 +316,9 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fetches the parent from remote if not found on backend" do
|
it "fetches the parent from remote if not found on backend" do
|
||||||
|
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_callback(:fetch_related_entity, "Parent", parent_guid).and_return(nil, remote_parent)
|
expect_callback(:fetch_related_entity, "Parent", parent_guid).and_return(nil, remote_parent)
|
||||||
expect(Federation::Fetcher).to receive(:fetch_public).with(author, "Parent", parent_guid)
|
expect(Federation::Fetcher).to receive(:fetch_public).with(author, "Parent", parent_guid)
|
||||||
|
|
||||||
|
|
@ -322,6 +326,15 @@ XML
|
||||||
|
|
||||||
expect(entity.parent).to eq(remote_parent)
|
expect(entity.parent).to eq(remote_parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises if the parent can't be fetched from remote" do
|
||||||
|
expect_callback(:fetch_related_entity, "Parent", parent_guid).exactly(2).times.and_return(nil)
|
||||||
|
expect(Federation::Fetcher).to receive(:fetch_public).with(author, "Parent", parent_guid)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
SomeRelayable.from_xml(xml)
|
||||||
|
}.to raise_error DiasporaFederation::Entities::Relayable::ParentNotFound
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#sender_valid?" do
|
describe "#sender_valid?" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue