2017-08-08 15:52:15 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-05-02 12:58:48 -04:00
|
|
|
RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do
|
2017-11-29 22:06:20 -05:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
|
2022-03-12 03:11:36 -05:00
|
|
|
let!(:sender) { Fabricate(:account).tap { |account| account.update(uri: ActivityPub::TagManager.instance.uri_for(account)) } }
|
|
|
|
let!(:recipient) { Fabricate(:account) }
|
|
|
|
let!(:valid_domain) { Rails.configuration.x.local_domain }
|
|
|
|
|
|
|
|
let(:existing_status) { nil }
|
2017-08-24 10:21:42 -04:00
|
|
|
|
|
|
|
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(sender),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
2022-03-12 03:11:36 -05:00
|
|
|
before do
|
|
|
|
stub_request(:head, 'https://example.com/watch?v=12345').to_return(status: 404, body: '')
|
|
|
|
end
|
|
|
|
|
2017-08-24 10:21:42 -04:00
|
|
|
describe '#call' do
|
|
|
|
before do
|
2022-03-12 03:11:36 -05:00
|
|
|
existing_status
|
2017-10-03 19:13:48 -04:00
|
|
|
subject.call(object[:id], prefetched_body: Oj.dump(object))
|
2017-08-24 10:21:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with Note object' do
|
|
|
|
let(:object) { note }
|
|
|
|
|
|
|
|
it 'creates status' do
|
|
|
|
status = sender.statuses.first
|
2017-11-16 20:52:30 -05:00
|
|
|
|
2017-08-24 10:21:42 -04:00
|
|
|
expect(status).to_not be_nil
|
|
|
|
expect(status.text).to eq 'Lorem ipsum'
|
|
|
|
end
|
|
|
|
end
|
2017-11-29 22:06:20 -05:00
|
|
|
|
|
|
|
context 'with Video object' do
|
|
|
|
let(:object) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: "https://#{valid_domain}/@foo/1234",
|
|
|
|
type: 'Video',
|
|
|
|
name: 'Nyan Cat 10 hours remix',
|
|
|
|
attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
url: [
|
|
|
|
{
|
|
|
|
type: 'Link',
|
|
|
|
mimeType: 'application/x-bittorrent',
|
2018-01-07 23:00:23 -05:00
|
|
|
href: "https://#{valid_domain}/12345.torrent",
|
2017-11-29 22:06:20 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
type: 'Link',
|
2019-06-26 13:32:36 -04:00
|
|
|
mimeType: 'text/html',
|
|
|
|
href: "https://#{valid_domain}/watch?v=12345",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates status' do
|
|
|
|
status = sender.statuses.first
|
|
|
|
|
|
|
|
expect(status).to_not be_nil
|
|
|
|
expect(status.url).to eq "https://#{valid_domain}/watch?v=12345"
|
2022-01-19 16:37:27 -05:00
|
|
|
expect(strip_tags(status.text)).to eq "Nyan Cat 10 hours remixhttps://#{valid_domain}/watch?v=12345"
|
2019-06-26 13:32:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with Audio object' do
|
|
|
|
let(:object) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: "https://#{valid_domain}/@foo/1234",
|
|
|
|
type: 'Audio',
|
|
|
|
name: 'Nyan Cat 10 hours remix',
|
|
|
|
attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
url: [
|
|
|
|
{
|
|
|
|
type: 'Link',
|
|
|
|
mimeType: 'application/x-bittorrent',
|
|
|
|
href: "https://#{valid_domain}/12345.torrent",
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
type: 'Link',
|
2017-11-29 22:06:20 -05:00
|
|
|
mimeType: 'text/html',
|
2018-01-07 23:00:23 -05:00
|
|
|
href: "https://#{valid_domain}/watch?v=12345",
|
2017-11-29 22:06:20 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates status' do
|
|
|
|
status = sender.statuses.first
|
|
|
|
|
|
|
|
expect(status).to_not be_nil
|
2018-01-07 23:00:23 -05:00
|
|
|
expect(status.url).to eq "https://#{valid_domain}/watch?v=12345"
|
2022-01-19 16:37:27 -05:00
|
|
|
expect(strip_tags(status.text)).to eq "Nyan Cat 10 hours remixhttps://#{valid_domain}/watch?v=12345"
|
2017-11-29 22:06:20 -05:00
|
|
|
end
|
|
|
|
end
|
2018-08-22 14:55:14 -04:00
|
|
|
|
2019-12-16 17:55:28 -05:00
|
|
|
context 'with Event object' do
|
|
|
|
let(:object) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: "https://#{valid_domain}/@foo/1234",
|
|
|
|
type: 'Event',
|
|
|
|
name: "Let's change the world",
|
|
|
|
attributedTo: ActivityPub::TagManager.instance.uri_for(sender)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates status' do
|
|
|
|
status = sender.statuses.first
|
|
|
|
|
|
|
|
expect(status).to_not be_nil
|
|
|
|
expect(status.url).to eq "https://#{valid_domain}/@foo/1234"
|
2022-01-19 16:37:27 -05:00
|
|
|
expect(strip_tags(status.text)).to eq "Let's change the worldhttps://#{valid_domain}/@foo/1234"
|
2019-12-16 17:55:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-22 14:55:14 -04:00
|
|
|
context 'with wrong id' do
|
|
|
|
let(:note) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: "https://real.address/@foo/1234",
|
|
|
|
type: 'Note',
|
|
|
|
content: 'Lorem ipsum',
|
|
|
|
attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:object) do
|
|
|
|
temp = note.dup
|
|
|
|
temp[:id] = 'https://fake.address/@foo/5678'
|
|
|
|
temp
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create status' do
|
|
|
|
expect(sender.statuses.first).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2021-10-20 19:14:04 -04:00
|
|
|
|
|
|
|
context 'with a valid Create activity' do
|
|
|
|
let(:object) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: "https://#{valid_domain}/@foo/1234/create",
|
|
|
|
type: 'Create',
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
object: note,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates status' do
|
|
|
|
status = sender.statuses.first
|
|
|
|
|
|
|
|
expect(status).to_not be_nil
|
|
|
|
expect(status.uri).to eq note[:id]
|
|
|
|
expect(status.text).to eq note[:content]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a Create activity with a mismatching id' do
|
|
|
|
let(:object) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: "https://#{valid_domain}/@foo/1234/create",
|
|
|
|
type: 'Create',
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
object: {
|
|
|
|
id: "https://real.address/@foo/1234",
|
|
|
|
type: 'Note',
|
|
|
|
content: 'Lorem ipsum',
|
|
|
|
attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create status' do
|
|
|
|
expect(sender.statuses.first).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2022-03-12 03:11:36 -05:00
|
|
|
|
|
|
|
context 'when status already exists' do
|
|
|
|
let(:existing_status) { Fabricate(:status, account: sender, text: 'Foo', uri: note[:id]) }
|
|
|
|
|
|
|
|
context 'with a Note object' do
|
2022-04-06 15:01:02 -04:00
|
|
|
let(:object) { note.merge(updated: '2021-09-08T22:39:25Z') }
|
2022-03-12 03:11:36 -05:00
|
|
|
|
|
|
|
it 'updates status' do
|
|
|
|
existing_status.reload
|
|
|
|
expect(existing_status.text).to eq 'Lorem ipsum'
|
|
|
|
expect(existing_status.edits).to_not be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a Create activity' do
|
|
|
|
let(:object) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: "https://#{valid_domain}/@foo/1234/create",
|
|
|
|
type: 'Create',
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
2022-04-06 15:01:02 -04:00
|
|
|
object: note.merge(updated: '2021-09-08T22:39:25Z'),
|
2022-03-12 03:11:36 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates status' do
|
|
|
|
existing_status.reload
|
|
|
|
expect(existing_status.text).to eq 'Lorem ipsum'
|
|
|
|
expect(existing_status.edits).to_not be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-24 10:21:42 -04:00
|
|
|
end
|
2017-08-08 15:52:15 -04:00
|
|
|
end
|