From 087415d0fe8d9a719eb2df7e915b08f4d4d0360a Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 25 Jan 2024 12:13:36 +0100 Subject: [PATCH] Add tests for processing statuses using bearcap URIs (#28904) --- spec/lib/activitypub/activity/create_spec.rb | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 3e3a4978c..e4966cffa 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -893,6 +893,49 @@ RSpec.describe ActivityPub::Activity::Create do end end + context 'when object URI uses bearcaps' do + subject { described_class.new(json, sender) } + + let(:token) { 'foo' } + + let(:json) do + { + '@context': 'https://www.w3.org/ns/activitystreams', + id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join, + type: 'Create', + actor: ActivityPub::TagManager.instance.uri_for(sender), + object: Addressable::URI.new(scheme: 'bear', query_values: { t: token, u: object_json[:id] }).to_s, + }.with_indifferent_access + end + + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + to: 'https://www.w3.org/ns/activitystreams#Public', + } + end + + before do + stub_request(:get, object_json[:id]) + .with(headers: { Authorization: "Bearer #{token}" }) + .to_return(body: Oj.dump(object_json), headers: { 'Content-Type': 'application/activity+json' }) + + subject.perform + end + + it 'creates status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status).to have_attributes( + visibility: 'public', + text: 'Lorem ipsum' + ) + end + end + context 'with an encrypted message' do subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }