Fix reshare import when root is not fetchable

This commit is contained in:
cmrd Senya 2019-05-05 10:54:42 +03:00 committed by Benjamin Neff
parent 413926b56e
commit 1ec0314752
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
3 changed files with 39 additions and 1 deletions

View file

@ -15,8 +15,10 @@ class ArchiveImporter
rescue DiasporaFederation::Entities::Signable::SignatureVerificationFailed,
DiasporaFederation::Discovery::InvalidDocument,
DiasporaFederation::Discovery::DiscoveryError,
DiasporaFederation::Federation::Fetcher::NotFetchable,
ActiveRecord::RecordInvalid => e
logger.warn "#{self}: #{e}"
self.persisted_object = nil
end
attr_reader :json

View file

@ -21,7 +21,9 @@ class ArchiveImporter
attr_reader :old_author_id
def persisted_object
@persisted_object ||= (instance if real_author == old_author_id)
return @persisted_object if defined?(@persisted_object)
@persisted_object = (instance if real_author == old_author_id)
end
def real_author

View file

@ -113,5 +113,39 @@ describe ArchiveImporter::PostImporter do
end
end
end
context "with reshare" do
let!(:author) { FactoryGirl.create(:person, diaspora_handle: "author@example.com") }
let(:entity_json) { JSON.parse(<<~JSON) }
{
"entity_data" : {
"created_at" : "2015-10-19T13:58:16Z",
"guid" : "#{UUID.generate(:compact)}",
"text" : "test post",
"author" : "author@example.com",
"root_author": "root_author@remote-pod.com",
"root_guid": "#{UUID.generate(:compact)}"
},
"entity_type": "reshare"
}
JSON
context "when a remote pod responds 403 to discovery requests" do
before do
stub_request(:get, "https://remote-pod.com/.well-known/webfinger?resource=acct:root_author@remote-pod.com")
.to_return(status: 403, body: "", headers: {})
stub_request(:get, "https://remote-pod.com/.well-known/host-meta")
.to_return(status: 403, body: "", headers: {})
stub_request(:get, "http://remote-pod.com/.well-known/host-meta")
.to_return(status: 403, body: "", headers: {})
end
it "doesn't raise error" do
expect {
instance.import
}.not_to raise_error
end
end
end
end
end