2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-09 05:52:15 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ActivityPub::Activity::Block do
|
2024-10-16 00:51:52 +11:00
|
|
|
subject { described_class.new(json, sender) }
|
|
|
|
|
2017-08-09 05:52:15 +10:00
|
|
|
let(:sender) { Fabricate(:account) }
|
|
|
|
let(:recipient) { Fabricate(:account) }
|
|
|
|
|
|
|
|
let(:json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: 'Block',
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
object: ActivityPub::TagManager.instance.uri_for(recipient),
|
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
describe '#perform' do
|
|
|
|
context 'when the recipient does not follow the sender' do
|
|
|
|
it 'creates a block from sender to recipient' do
|
2019-01-02 11:12:02 +11:00
|
|
|
subject.perform
|
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
expect(sender)
|
|
|
|
.to be_blocking(recipient)
|
2019-01-02 11:12:02 +11:00
|
|
|
end
|
|
|
|
end
|
Fix not handling Undo on some activity types when they aren't inlined (#14346)
* Fix not handling Undo on some activity types when they aren't inlined
When receiving an Undo for a non-inlined activity, try looking it up in
database using the URI. The queries are ad-hoc because we don't have a global
index of object URIs, and not all activity types are stored in database with
an index on their URI.
Announces are just statuses, and have an index on URIs, so this check can
be done efficiently.
Accepts cannot be handled at all because we don't record their URI at any
point.
Follows don't have an index on URI, but they have an index on the issuing
account, which should make such queries largely manageable.
Likes don't have an index on URI, they have an index on the issuing account,
but the number of favs per account may be very high, so I decided not to
handle that.
Blocks don't have an index on URI, but they have an index on the issuing
account, which should make such queries largely manageable.
In all cases, if an Undo could not be handled properly, we call `delete_later!`
because that does not require us to know more than the URI of the undone
property.
* Add tests
* Make newer blocks overwrite older ones
Allows re-synchronizing block info by re-blocking and un-blocking again
when the original Undo Block has been lost.
2020-07-22 19:45:35 +10:00
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
context 'when the recipient is already blocked' do
|
|
|
|
before { sender.block!(recipient, uri: 'old') }
|
Fix not handling Undo on some activity types when they aren't inlined (#14346)
* Fix not handling Undo on some activity types when they aren't inlined
When receiving an Undo for a non-inlined activity, try looking it up in
database using the URI. The queries are ad-hoc because we don't have a global
index of object URIs, and not all activity types are stored in database with
an index on their URI.
Announces are just statuses, and have an index on URIs, so this check can
be done efficiently.
Accepts cannot be handled at all because we don't record their URI at any
point.
Follows don't have an index on URI, but they have an index on the issuing
account, which should make such queries largely manageable.
Likes don't have an index on URI, they have an index on the issuing account,
but the number of favs per account may be very high, so I decided not to
handle that.
Blocks don't have an index on URI, but they have an index on the issuing
account, which should make such queries largely manageable.
In all cases, if an Undo could not be handled properly, we call `delete_later!`
because that does not require us to know more than the URI of the undone
property.
* Add tests
* Make newer blocks overwrite older ones
Allows re-synchronizing block info by re-blocking and un-blocking again
when the original Undo Block has been lost.
2020-07-22 19:45:35 +10:00
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
it 'creates a block from sender to recipient and sets uri to last received block activity' do
|
Fix not handling Undo on some activity types when they aren't inlined (#14346)
* Fix not handling Undo on some activity types when they aren't inlined
When receiving an Undo for a non-inlined activity, try looking it up in
database using the URI. The queries are ad-hoc because we don't have a global
index of object URIs, and not all activity types are stored in database with
an index on their URI.
Announces are just statuses, and have an index on URIs, so this check can
be done efficiently.
Accepts cannot be handled at all because we don't record their URI at any
point.
Follows don't have an index on URI, but they have an index on the issuing
account, which should make such queries largely manageable.
Likes don't have an index on URI, they have an index on the issuing account,
but the number of favs per account may be very high, so I decided not to
handle that.
Blocks don't have an index on URI, but they have an index on the issuing
account, which should make such queries largely manageable.
In all cases, if an Undo could not be handled properly, we call `delete_later!`
because that does not require us to know more than the URI of the undone
property.
* Add tests
* Make newer blocks overwrite older ones
Allows re-synchronizing block info by re-blocking and un-blocking again
when the original Undo Block has been lost.
2020-07-22 19:45:35 +10:00
|
|
|
subject.perform
|
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
expect(sender)
|
|
|
|
.to be_blocking(recipient)
|
|
|
|
expect(sender.block_relationships.find_by(target_account: recipient).uri)
|
|
|
|
.to eq 'foo'
|
Fix not handling Undo on some activity types when they aren't inlined (#14346)
* Fix not handling Undo on some activity types when they aren't inlined
When receiving an Undo for a non-inlined activity, try looking it up in
database using the URI. The queries are ad-hoc because we don't have a global
index of object URIs, and not all activity types are stored in database with
an index on their URI.
Announces are just statuses, and have an index on URIs, so this check can
be done efficiently.
Accepts cannot be handled at all because we don't record their URI at any
point.
Follows don't have an index on URI, but they have an index on the issuing
account, which should make such queries largely manageable.
Likes don't have an index on URI, they have an index on the issuing account,
but the number of favs per account may be very high, so I decided not to
handle that.
Blocks don't have an index on URI, but they have an index on the issuing
account, which should make such queries largely manageable.
In all cases, if an Undo could not be handled properly, we call `delete_later!`
because that does not require us to know more than the URI of the undone
property.
* Add tests
* Make newer blocks overwrite older ones
Allows re-synchronizing block info by re-blocking and un-blocking again
when the original Undo Block has been lost.
2020-07-22 19:45:35 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
context 'when the recipient follows the sender' do
|
|
|
|
before { recipient.follow!(sender) }
|
2019-01-02 11:12:02 +11:00
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
it 'creates a block from sender to recipient and ensures recipient not following sender' do
|
2019-01-02 11:12:02 +11:00
|
|
|
subject.perform
|
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
expect(sender)
|
|
|
|
.to be_blocking(recipient)
|
|
|
|
expect(recipient)
|
|
|
|
.to_not be_following(sender)
|
2019-01-02 11:12:02 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
context 'when a matching undo has been received first' do
|
|
|
|
let(:undo_json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'bar',
|
|
|
|
type: 'Undo',
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
object: json,
|
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
2019-01-02 11:12:02 +11:00
|
|
|
|
|
|
|
before do
|
2024-10-16 00:51:52 +11:00
|
|
|
recipient.follow!(sender)
|
|
|
|
ActivityPub::Activity::Undo.new(undo_json, sender).perform
|
2019-01-02 11:12:02 +11:00
|
|
|
end
|
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
it 'does not create a block from sender to recipient and ensures recipient not following sender' do
|
|
|
|
subject.perform
|
2019-01-02 11:12:02 +11:00
|
|
|
|
2024-10-16 00:51:52 +11:00
|
|
|
expect(sender)
|
|
|
|
.to_not be_blocking(recipient)
|
|
|
|
expect(recipient)
|
|
|
|
.to_not be_following(sender)
|
2019-01-02 11:12:02 +11:00
|
|
|
end
|
2017-08-09 05:52:15 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|