Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/archive_importer/entity_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ def import
rescue DiasporaFederation::Entities::Signable::SignatureVerificationFailed,
DiasporaFederation::Discovery::InvalidDocument,
DiasporaFederation::Discovery::DiscoveryError,
DiasporaFederation::Federation::Fetcher::NotFetchable,
OwnRelayableImporter::NoParentError,
ActiveRecord::RecordInvalid => e
logger.warn "#{self}: #{e}"
self.persisted_object = nil
end

attr_reader :json
Expand Down
4 changes: 3 additions & 1 deletion lib/archive_importer/own_entity_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def substitute_author
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
Expand Down
4 changes: 4 additions & 0 deletions lib/archive_importer/own_relayable_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class ArchiveImporter
class OwnRelayableImporter < OwnEntityImporter
class NoParentError < RuntimeError; end

def entity
fetch_parent(symbolized_entity_data)
entity_class.new(symbolized_entity_data)
Expand All @@ -19,6 +21,8 @@ def fetch_parent(data)
break entity_class::PARENT_TYPE if entity_class.const_defined?(:PARENT_TYPE)
}
entity = Diaspora::Federation::Mappings.model_class_for(type).find_by(guid: data.fetch(:parent_guid))
raise NoParentError if entity.nil?

data[:parent] = Diaspora::Federation::Entities.related_entity(entity)
end
end
Expand Down
23 changes: 23 additions & 0 deletions spec/lib/archive_importer/own_relayable_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,27 @@
).to_json
}
end

context "with comment with unknown parent" do
let(:new_user) { FactoryGirl.create(:user) }
let(:instance) { described_class.new(entity_json, new_user) }
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",
"parent_guid": "#{UUID.generate(:compact)}"
},
"entity_type": "comment"
}
JSON

it "doesn't raise error" do
expect {
instance.import
}.not_to raise_error
end
end
end
34 changes: 34 additions & 0 deletions spec/lib/archive_importer/post_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,39 @@
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