require 'rails_helper' RSpec.describe FetchRemoteStatusService, type: :service do let(:account) { Fabricate(:account) } let(:prefetched_body) { nil } let(:valid_domain) { Rails.configuration.x.local_domain } let(:note) do { '@context': 'https://www.w3.org/ns/activitystreams', id: "https://#{valid_domain}/@foo/1234", type: 'Note', content: 'Lorem ipsum', attributedTo: ActivityPub::TagManager.instance.uri_for(account), } end context 'protocol is :activitypub' do subject { described_class.new.call(note[:id], prefetched_body) } let(:prefetched_body) { Oj.dump(note) } before do account.update(uri: ActivityPub::TagManager.instance.uri_for(account)) subject end it 'creates status' do status = account.statuses.first expect(status).to_not be_nil expect(status.text).to eq 'Lorem ipsum' end end context 'protocol is :ostatus' do subject { described_class.new } before do Fabricate(:account, username: 'tracer', domain: 'real.domain', remote_url: 'https://real.domain/users/tracer') end it 'does not create status with author at different domain' do status_body = <<-XML.squish tag:real.domain,2017-04-27:objectId=4487555:objectType=Status 2017-04-27T13:49:25Z 2017-04-27T13:49:25Z http://activitystrea.ms/schema/1.0/note http://activitystrea.ms/schema/1.0/post https://real.domain/users/tracer http://activitystrea.ms/schema/1.0/person https://real.domain/users/tracer tracer Overwatch rocks XML expect(subject.call('https://fake.domain/foo', status_body)).to be_nil end it 'does not create status with wrong id when id uses http format' do status_body = <<-XML.squish https://other-real.domain/statuses/123 2017-04-27T13:49:25Z 2017-04-27T13:49:25Z http://activitystrea.ms/schema/1.0/note http://activitystrea.ms/schema/1.0/post https://real.domain/users/tracer http://activitystrea.ms/schema/1.0/person https://real.domain/users/tracer tracer Overwatch rocks XML expect(subject.call('https://real.domain/statuses/456', status_body)).to be_nil end end end