2017-08-08 19:52:15 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-05-02 16:58:48 +00:00
|
|
|
RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do
|
2017-11-30 03:06:20 +00:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
|
2022-03-12 08:11:36 +00: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 14:21:42 +00: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 08:11:36 +00:00
|
|
|
before do
|
|
|
|
stub_request(:head, 'https://example.com/watch?v=12345').to_return(status: 404, body: '')
|
|
|
|
end
|
|
|
|
|
2017-08-24 14:21:42 +00:00
|
|
|
describe '#call' do
|
|
|
|
before do
|
2022-03-12 08:11:36 +00:00
|
|
|
existing_status
|
2017-10-03 23:13:48 +00:00
|
|
|
subject.call(object[:id], prefetched_body: Oj.dump(object))
|
2017-08-24 14:21:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with Note object' do
|
|
|
|
let(:object) { note }
|
|
|
|
|
|
|
|
it 'creates status' do
|
|
|
|
status = sender.statuses.first
|
2017-11-17 01:52:30 +00:00
|
|
|
|
2017-08-24 14:21:42 +00:00
|
|
|
expect(status).to_not be_nil
|
|
|
|
expect(status.text).to eq 'Lorem ipsum'
|
|
|
|
end
|
|
|
|
end
|
2017-11-30 03:06:20 +00: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-08 04:00:23 +00:00
|
|
|
href: "https://#{valid_domain}/12345.torrent",
|
2017-11-30 03:06:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
type: 'Link',
|
2019-06-26 17:32:36 +00: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 21:37:27 +00:00
|
|
|
expect(strip_tags(status.text)).to eq "Nyan Cat 10 hours remixhttps://#{valid_domain}/watch?v=12345"
|
2019-06-26 17:32:36 +00: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-30 03:06:20 +00:00
|
|
|
mimeType: 'text/html',
|
2018-01-08 04:00:23 +00:00
|
|
|
href: "https://#{valid_domain}/watch?v=12345",
|
2017-11-30 03:06:20 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates status' do
|
|
|
|
status = sender.statuses.first
|
|
|
|
|
|
|
|
expect(status).to_not be_nil
|
2018-01-08 04:00:23 +00:00
|
|
|
expect(status.url).to eq "https://#{valid_domain}/watch?v=12345"
|
2022-01-19 21:37:27 +00:00
|
|
|
expect(strip_tags(status.text)).to eq "Nyan Cat 10 hours remixhttps://#{valid_domain}/watch?v=12345"
|
2017-11-30 03:06:20 +00:00
|
|
|
end
|
|
|
|
end
|
2018-08-22 18:55:14 +00:00
|
|
|
|
2019-12-16 22:55:28 +00: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 21:37:27 +00:00
|
|
|
expect(strip_tags(status.text)).to eq "Let's change the worldhttps://#{valid_domain}/@foo/1234"
|
2019-12-16 22:55:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-22 18:55:14 +00: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 23:14:04 +00: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 08:11:36 +00: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
|
|
|
|
let(:object) { note }
|
|
|
|
|
|
|
|
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),
|
|
|
|
object: note,
|
|
|
|
}
|
|
|
|
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 14:21:42 +00:00
|
|
|
end
|
2017-08-08 19:52:15 +00:00
|
|
|
end
|