Files
jcoffey-dev 319ed76dbd
Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Import Mastodon v4.7.3
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from
https://github.com/mastodon/mastodon, unmodified.
2026-10-05 22:03:13 -07:00

123 lines
4.6 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ActivityPub::Activity::QuoteRequest 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(:instrument) { 'https://example.com/unknown-status' }
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: instrument,
}.deep_stringify_keys
end
let(:status_json) do
{
'@context': [
'https://www.w3.org/ns/activitystreams',
{
'@id': 'https://w3id.org/fep/044f#quote',
'@type': '@id',
},
{
'@id': 'https://w3id.org/fep/044f#quoteAuthorization',
'@type': '@id',
},
],
id: 'https://example.com/unknown-status',
type: 'Note',
summary: 'Show more',
content: 'Hello universe',
quote: ActivityPub::TagManager.instance.uri_for(quoted_post),
attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
}.deep_stringify_keys
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 = JSON.parse(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
context 'when trying to quote an unquotable local status with an inlined instrument' do
let(:instrument) { status_json.without('@context') }
it 'sends a Reject activity' do
expect { subject.perform }
.to enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
.with(satisfying do |body|
outgoing_json = JSON.parse(body)
outgoing_json['type'] == 'Reject' && json['instrument']['id'] == outgoing_json['object']['instrument'] && %w(type id actor object).all? { |key| json[key] == outgoing_json['object'][key] }
end, recipient.id, sender.inbox_url)
end
end
context 'when trying to quote a quotable local status' do
before do
stub_request(:get, 'https://example.com/unknown-status').to_return(status: 200, body: status_json.to_json, headers: { 'Content-Type': 'application/activity+json' })
quoted_post.update(quote_approval_policy: InteractionPolicy::POLICY_FLAGS[:public] << 16)
end
it 'accepts the quote and sends an Accept activity' do
expect { subject.perform }
.to change { quoted_post.reload.quotes.accepted.count }.by(1)
.and enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
.with(satisfying do |body|
outgoing_json = JSON.parse(body)
outgoing_json['type'] == 'Accept' && %w(type id actor object instrument).all? { |key| json[key] == outgoing_json['object'][key] }
end, recipient.id, sender.inbox_url)
end
end
context 'when trying to quote a quotable local status with an inlined instrument' do
let(:instrument) { status_json.without('@context') }
before do
quoted_post.update(quote_approval_policy: InteractionPolicy::POLICY_FLAGS[:public] << 16)
end
it 'accepts the quote and sends an Accept activity' do
expect { subject.perform }
.to change { quoted_post.reload.quotes.accepted.count }.by(1)
.and enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
.with(satisfying do |body|
outgoing_json = JSON.parse(body)
outgoing_json['type'] == 'Accept' && json['instrument']['id'] == outgoing_json['object']['instrument'] && %w(type id actor object).all? { |key| json[key] == outgoing_json['object'][key] }
end, recipient.id, sender.inbox_url)
end
end
end
end