mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 00:38:27 +00:00
Merge commit '715cbee93d419e26cf952bf7fc70f9c1cc217d8b' into glitch-soc/merge-upstream
This commit is contained in:
51
spec/lib/activitypub/activity/quote_request_spec.rb
Normal file
51
spec/lib/activitypub/activity/quote_request_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::Activity::QuoteRequest, feature: :inbound_quotes do
|
||||
let(:sender) { Fabricate(:account, domain: 'example.com') }
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
let(:quoted_post) { Fabricate(:status, account: recipient) }
|
||||
let(:request_uri) { 'https://example.com/missing-ui' }
|
||||
let(:quoted_uri) { ActivityPub::TagManager.instance.uri_for(quoted_post) }
|
||||
|
||||
let(:json) do
|
||||
{
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
{
|
||||
QuoteRequest: 'https://w3id.org/fep/044f#QuoteRequest',
|
||||
},
|
||||
],
|
||||
id: request_uri,
|
||||
type: 'QuoteRequest',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
||||
object: quoted_uri,
|
||||
instrument: 'https://example.com/unknown-status',
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
context 'when trying to quote an unknown status' do
|
||||
let(:quoted_uri) { 'https://example.com/statuses/1234' }
|
||||
|
||||
it 'does not send anything' do
|
||||
expect { subject.perform }
|
||||
.to_not enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when trying to quote an unquotable local status' do
|
||||
it 'sends a Reject activity' do
|
||||
expect { subject.perform }
|
||||
.to enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
||||
.with(satisfying do |body|
|
||||
outgoing_json = Oj.load(body)
|
||||
outgoing_json['type'] == 'Reject' && %w(type id actor object instrument).all? { |key| json[key] == outgoing_json['object'][key] }
|
||||
end, recipient.id, sender.inbox_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -7,10 +7,11 @@ RSpec.describe ActivityPub::Parser::StatusParser do
|
||||
|
||||
let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', domain: 'example.com', uri: 'https://example.com/actor') }
|
||||
let(:follower) { Fabricate(:account, username: 'bob') }
|
||||
let(:context) { 'https://www.w3.org/ns/activitystreams' }
|
||||
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'@context': context,
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
|
||||
type: 'Create',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
||||
@@ -47,4 +48,116 @@ RSpec.describe ActivityPub::Parser::StatusParser do
|
||||
language: :en
|
||||
)
|
||||
end
|
||||
|
||||
describe '#quote_policy' do
|
||||
subject do
|
||||
described_class
|
||||
.new(
|
||||
json,
|
||||
actor_uri: ActivityPub::TagManager.instance.uri_for(sender),
|
||||
followers_collection: sender.followers_url
|
||||
).quote_policy
|
||||
end
|
||||
|
||||
let(:context) do
|
||||
[
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
{
|
||||
gts: 'https://gotosocial.org/ns#',
|
||||
interactionPolicy: {
|
||||
'@id': 'gts:interactionPolicy',
|
||||
'@type': '@id',
|
||||
},
|
||||
canQuote: {
|
||||
'@id': 'gts:canQuote',
|
||||
'@type': '@id',
|
||||
},
|
||||
automaticApproval: {
|
||||
'@id': 'gts:automaticApproval',
|
||||
'@type': '@id',
|
||||
},
|
||||
manualApproval: {
|
||||
'@id': 'gts:manualApproval',
|
||||
'@type': '@id',
|
||||
},
|
||||
},
|
||||
]
|
||||
end
|
||||
|
||||
context 'when nobody is allowed to quote' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), 'post1'].join('/'),
|
||||
type: 'Note',
|
||||
to: [
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
ActivityPub::TagManager.instance.uri_for(follower),
|
||||
],
|
||||
interactionPolicy: {
|
||||
canQuote: {
|
||||
automaticApproval: ActivityPub::TagManager.instance.uri_for(sender),
|
||||
},
|
||||
},
|
||||
content: 'bleh',
|
||||
published: 1.hour.ago.utc.iso8601,
|
||||
updated: 1.hour.ago.utc.iso8601,
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns a policy not allowing anyone to quote' do
|
||||
expect(subject).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
context 'when everybody is allowed to quote' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), 'post1'].join('/'),
|
||||
type: 'Note',
|
||||
to: [
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
ActivityPub::TagManager.instance.uri_for(follower),
|
||||
],
|
||||
interactionPolicy: {
|
||||
canQuote: {
|
||||
automaticApproval: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
},
|
||||
},
|
||||
content: 'bleh',
|
||||
published: 1.hour.ago.utc.iso8601,
|
||||
updated: 1.hour.ago.utc.iso8601,
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns a policy not allowing anyone to quote' do
|
||||
expect(subject).to eq(Status::QUOTE_APPROVAL_POLICY_FLAGS[:public] << 16)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when everybody is allowed to quote but only followers are automatically approved' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), 'post1'].join('/'),
|
||||
type: 'Note',
|
||||
to: [
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
ActivityPub::TagManager.instance.uri_for(follower),
|
||||
],
|
||||
interactionPolicy: {
|
||||
canQuote: {
|
||||
automaticApproval: sender.followers_url,
|
||||
manualApproval: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
},
|
||||
},
|
||||
content: 'bleh',
|
||||
published: 1.hour.ago.utc.iso8601,
|
||||
updated: 1.hour.ago.utc.iso8601,
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns a policy allowing everyone including followers' do
|
||||
expect(subject).to eq Status::QUOTE_APPROVAL_POLICY_FLAGS[:public] | (Status::QUOTE_APPROVAL_POLICY_FLAGS[:followers] << 16)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user