Merge upstream tag 'v3.5.2'

This commit is contained in:
Mike Barnes 2022-05-23 19:28:18 +10:00
commit d161ca885c
2205 changed files with 91260 additions and 41616 deletions

View file

@ -23,6 +23,7 @@ RSpec.describe ActivityPub::Activity::Accept do
subject { described_class.new(json, sender) }
before do
allow(RemoteAccountRefreshWorker).to receive(:perform_async)
Fabricate(:follow_request, account: recipient, target_account: sender)
subject.perform
end
@ -34,6 +35,10 @@ RSpec.describe ActivityPub::Activity::Accept do
it 'removes the follow request' do
expect(recipient.requested?(sender)).to be false
end
it 'queues a refresh' do
expect(RemoteAccountRefreshWorker).to have_received(:perform_async).with(sender.id)
end
end
context 'given a relay' do

View file

@ -1,8 +1,8 @@
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Add do
let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured') }
let(:status) { Fabricate(:status, account: sender) }
let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured', domain: 'example.com') }
let(:status) { Fabricate(:status, account: sender, visibility: :private) }
let(:json) do
{
@ -24,6 +24,8 @@ RSpec.describe ActivityPub::Activity::Add do
end
context 'when status was not known before' do
let(:service_stub) { double }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
@ -36,12 +38,40 @@ RSpec.describe ActivityPub::Activity::Add do
end
before do
stub_request(:get, 'https://example.com/unknown').to_return(status: 410)
allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service_stub)
end
it 'fetches the status' do
subject.perform
expect(a_request(:get, 'https://example.com/unknown')).to have_been_made.at_least_once
context 'when there is a local follower' do
before do
account = Fabricate(:account)
account.follow!(sender)
end
it 'fetches the status and pins it' do
allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil|
expect(uri).to eq 'https://example.com/unknown'
expect(id).to eq true
expect(on_behalf_of&.following?(sender)).to eq true
status
end
subject.perform
expect(service_stub).to have_received(:call)
expect(sender.pinned?(status)).to be true
end
end
context 'when there is no local follower' do
it 'tries to fetch the status' do
allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil|
expect(uri).to eq 'https://example.com/unknown'
expect(id).to eq true
expect(on_behalf_of).to eq nil
nil
end
subject.perform
expect(service_stub).to have_received(:call)
expect(sender.pinned?(status)).to be false
end
end
end
end

View file

@ -113,26 +113,23 @@ RSpec.describe ActivityPub::Activity::Announce do
let!(:relay_account) { Fabricate(:account, inbox_url: 'https://relay.example.com/inbox') }
let!(:relay) { Fabricate(:relay, inbox_url: 'https://relay.example.com/inbox') }
let(:object_json) { 'https://example.com/actor/hello-world' }
subject { described_class.new(json, sender, relayed_through_account: relay_account) }
before do
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json))
end
context 'and the relay is enabled' do
before do
relay.update(state: :accepted)
subject.perform
end
let(:object_json) do
{
id: 'https://example.com/actor#bar',
type: 'Note',
content: 'Lorem ipsum',
to: 'http://example.com/followers',
attributedTo: 'https://example.com/actor',
}
end
it 'creates a reblog by sender of status' do
expect(sender.statuses.count).to eq 2
it 'fetches the remote status' do
expect(a_request(:get, 'https://example.com/actor/hello-world')).to have_been_made
expect(Status.find_by(uri: 'https://example.com/actor/hello-world').text).to eq 'Hello world'
end
end
@ -141,14 +138,9 @@ RSpec.describe ActivityPub::Activity::Announce do
subject.perform
end
let(:object_json) do
{
id: 'https://example.com/actor#bar',
type: 'Note',
content: 'Lorem ipsum',
to: 'http://example.com/followers',
attributedTo: 'https://example.com/actor',
}
it 'does not fetch the remote status' do
expect(a_request(:get, 'https://example.com/actor/hello-world')).not_to have_been_made
expect(Status.find_by(uri: 'https://example.com/actor/hello-world')).to be_nil
end
it 'does not create anything' do

View file

@ -29,6 +29,58 @@ RSpec.describe ActivityPub::Activity::Create do
subject.perform
end
context 'object has been edited' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
published: '2022-01-22T15:00:00Z',
updated: '2022-01-22T16:00:00Z',
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.text).to eq 'Lorem ipsum'
end
it 'marks status as edited' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.edited?).to eq true
end
end
context 'object has update date equal to creation date' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
published: '2022-01-22T15:00:00Z',
updated: '2022-01-22T15:00:00Z',
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.text).to eq 'Lorem ipsum'
end
it 'does not mark status as edited' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.edited?).to eq false
end
end
context 'unknown object type' do
let(:object_json) do
{

View file

@ -84,9 +84,9 @@ RSpec.describe ActivityPub::Activity::Move do
context 'when a Move has been recently processed' do
around do |example|
Redis.current.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
redis.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
example.run
Redis.current.del("move_in_progress:#{old_account.id}")
redis.del("move_in_progress:#{old_account.id}")
end
it 'does not set moved account on old account' do

View file

@ -4,43 +4,97 @@ RSpec.describe ActivityPub::Activity::Update do
let!(:sender) { Fabricate(:account) }
before do
stub_request(:get, actor_json[:outbox]).to_return(status: 404)
stub_request(:get, actor_json[:followers]).to_return(status: 404)
stub_request(:get, actor_json[:following]).to_return(status: 404)
stub_request(:get, actor_json[:featured]).to_return(status: 404)
sender.update!(uri: ActivityPub::TagManager.instance.uri_for(sender))
end
let(:modified_sender) do
sender.dup.tap do |modified_sender|
modified_sender.display_name = 'Totally modified now'
end
end
let(:actor_json) do
ActiveModelSerializers::SerializableResource.new(modified_sender, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter).as_json
end
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Update',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: actor_json,
}.with_indifferent_access
end
subject { described_class.new(json, sender) }
describe '#perform' do
subject { described_class.new(json, sender) }
context 'with an Actor object' do
let(:modified_sender) do
sender.tap do |modified_sender|
modified_sender.display_name = 'Totally modified now'
end
end
before do
subject.perform
let(:actor_json) do
ActiveModelSerializers::SerializableResource.new(modified_sender, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter).as_json
end
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Update',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: actor_json,
}.with_indifferent_access
end
before do
stub_request(:get, actor_json[:outbox]).to_return(status: 404)
stub_request(:get, actor_json[:followers]).to_return(status: 404)
stub_request(:get, actor_json[:following]).to_return(status: 404)
stub_request(:get, actor_json[:featured]).to_return(status: 404)
subject.perform
end
it 'updates profile' do
expect(sender.reload.display_name).to eq 'Totally modified now'
end
end
it 'updates profile' do
expect(sender.reload.display_name).to eq 'Totally modified now'
context 'with a Question object' do
let!(:at_time) { Time.now.utc }
let!(:status) { Fabricate(:status, account: sender, poll: Poll.new(account: sender, options: %w(Bar Baz), cached_tallies: [0, 0], expires_at: at_time + 5.days)) }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Update',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: {
type: 'Question',
id: ActivityPub::TagManager.instance.uri_for(status),
content: 'Foo',
endTime: (at_time + 5.days).iso8601,
oneOf: [
{
type: 'Note',
name: 'Bar',
replies: {
type: 'Collection',
totalItems: 0,
},
},
{
type: 'Note',
name: 'Baz',
replies: {
type: 'Collection',
totalItems: 12,
},
},
],
},
}.with_indifferent_access
end
before do
status.update!(uri: ActivityPub::TagManager.instance.uri_for(status))
subject.perform
end
it 'updates poll numbers' do
expect(status.preloadable_poll.cached_tallies).to eq [0, 12]
end
it 'does not set status as edited' do
expect(status.edited_at).to be_nil
end
end
end
end

View file

@ -81,6 +81,6 @@ RSpec.describe ActivityPub::LinkedDataSignature do
options_hash = Digest::SHA256.hexdigest(canonicalize(options.merge('@context' => ActivityPub::LinkedDataSignature::CONTEXT)))
document_hash = Digest::SHA256.hexdigest(canonicalize(document))
to_be_verified = options_hash + document_hash
Base64.strict_encode64(from_account.keypair.sign(OpenSSL::Digest::SHA256.new, to_be_verified))
Base64.strict_encode64(from_account.keypair.sign(OpenSSL::Digest.new('SHA256'), to_be_verified))
end
end