diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-03-10 09:52:45 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-03-10 09:52:45 +0100 |
commit | 24e83246f9efaa57ff025a606795ab8bc21a42df (patch) | |
tree | 203ec54d28707f1615f4c2ce026bb3e11d2ddcea /spec | |
parent | 02133866e6915e37431298b396e1aded1e4c44c5 (diff) | |
parent | d7fab238a891d2530c9937a2fa627b622972d409 (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `app/models/status.rb`: Upstream updated media and edit-related code textually close to glitch-soc additions (local-only and content-type). Ported upstream changes. - `app/models/status_edit.rb`: Upstream changes textually close to glitch-soc additions (content-type). Ported upstream changes. - `app/serializers/activitypub/note_serializer.rb`: Upstream changed how media attachments are handled. Not really a conflict, but textually close to glitch-soc additions (directMessage attribute). Ported upstream changes. - `app/services/remove_status_service.rb`: Upstream changed how media attachments are handled. Not really a conflict, but textually close to glitch-soc additions (DM timeline). Ported upstream changes. - `app/services/update_status_service.rb`: Upstream fixed an issue with language selection. Not really a conflict, but textually close to glitch-soc additions (content-type). Ported upstream changes. - `db/schema.rb`: Upstream added columns to the `status_edits` table, the conflict is because of an additional column (`content-type`) in glitch-soc. Ported upstream changes. - `package.json`: Upstream dependency (express) textually adjacent to a glitch-soc-specific one (favico.js) got updated. Updated it as well.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin/domain_blocks_controller_spec.rb | 9 | ||||
-rw-r--r-- | spec/models/report_spec.rb | 13 | ||||
-rw-r--r-- | spec/services/activitypub/process_collection_service_spec.rb | 140 | ||||
-rw-r--r-- | spec/services/activitypub/process_status_update_service_spec.rb | 17 | ||||
-rw-r--r-- | spec/services/reblog_service_spec.rb | 12 | ||||
-rw-r--r-- | spec/services/update_status_service_spec.rb | 14 |
6 files changed, 171 insertions, 34 deletions
diff --git a/spec/controllers/admin/domain_blocks_controller_spec.rb b/spec/controllers/admin/domain_blocks_controller_spec.rb index fb23658c0..ecc79292b 100644 --- a/spec/controllers/admin/domain_blocks_controller_spec.rb +++ b/spec/controllers/admin/domain_blocks_controller_spec.rb @@ -16,15 +16,6 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do end end - describe 'GET #show' do - it 'returns http success' do - domain_block = Fabricate(:domain_block) - get :show, params: { id: domain_block.id } - - expect(response).to have_http_status(200) - end - end - describe 'POST #create' do it 'blocks the domain when succeeded to save' do allow(DomainBlockWorker).to receive(:perform_async).and_return(true) diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index df32a7c9d..874be4132 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -11,14 +11,13 @@ describe Report do end end - describe 'media_attachments' do - it 'returns media attachments from statuses' do - status = Fabricate(:status) - media_attachment = Fabricate(:media_attachment, status: status) - _other_media_attachment = Fabricate(:media_attachment) - report = Fabricate(:report, status_ids: [status.id]) + describe 'media_attachments_count' do + it 'returns count of media attachments in statuses' do + status1 = Fabricate(:status, ordered_media_attachment_ids: [1, 2]) + status2 = Fabricate(:status, ordered_media_attachment_ids: [5]) + report = Fabricate(:report, status_ids: [status1.id, status2.id]) - expect(report.media_attachments).to eq [media_attachment] + expect(report.media_attachments_count).to eq 3 end end diff --git a/spec/services/activitypub/process_collection_service_spec.rb b/spec/services/activitypub/process_collection_service_spec.rb index 00d71a86a..3eccaab5b 100644 --- a/spec/services/activitypub/process_collection_service_spec.rb +++ b/spec/services/activitypub/process_collection_service_spec.rb @@ -91,6 +91,146 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do subject.call(json, forwarder) end + + context 'when receiving a fabricated status' do + let!(:actor) do + Fabricate(:account, + username: 'bob', + domain: 'example.com', + uri: 'https://example.com/users/bob', + public_key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuuYyoyfsRkYnXRotMsId\nW3euBDDfiv9oVqOxUVC7bhel8KednIMrMCRWFAkgJhbrlzbIkjVr68o1MP9qLcn7\nCmH/BXHp7yhuFTr4byjdJKpwB+/i2jNEsvDH5jR8WTAeTCe0x/QHg21V3F7dSI5m\nCCZ/1dSIyOXLRTWVlfDlm3rE4ntlCo+US3/7oSWbg/4/4qEnt1HC32kvklgScxua\n4LR5ATdoXa5bFoopPWhul7MJ6NyWCyQyScUuGdlj8EN4kmKQJvphKHrI9fvhgOuG\nTvhTR1S5InA4azSSchY0tXEEw/VNxraeX0KPjbgr6DPcwhPd/m0nhVDq0zVyVBBD\nMwIDAQAB\n-----END PUBLIC KEY-----\n", + private_key: nil) + end + + let(:payload) do + { + '@context': [ + 'https://www.w3.org/ns/activitystreams', + nil, + {'object': 'https://www.w3.org/ns/activitystreams#object'} + ], + 'id': 'https://example.com/users/bob/fake-status/activity', + 'type': 'Create', + 'actor': 'https://example.com/users/bob', + 'published': '2022-01-22T15:00:00Z', + 'to': [ + 'https://www.w3.org/ns/activitystreams#Public' + ], + 'cc': [ + 'https://example.com/users/bob/followers' + ], + 'signature': { + 'type': 'RsaSignature2017', + 'creator': 'https://example.com/users/bob#main-key', + 'created': '2022-03-09T21:57:25Z', + 'signatureValue': 'WculK0LelTQ0MvGwU9TPoq5pFzFfGYRDCJqjZ232/Udj4CHqDTGOSw5UTDLShqBOyycCkbZGrQwXG+dpyDpQLSe1UVPZ5TPQtc/9XtI57WlS2nMNpdvRuxGnnb2btPdesXZ7n3pCxo0zjaXrJMe0mqQh5QJO22mahb4bDwwmfTHgbD3nmkD+fBfGi+UV2qWwqr+jlV4L4JqNkh0gWljF5KTePLRRZCuWiQ/FAt7c67636cdIPf7fR+usjuZltTQyLZKEGuK8VUn2Gkfsx5qns7Vcjvlz1JqlAjyO8HPBbzTTHzUG2nUOIgC3PojCSWv6mNTmRGoLZzOscCAYQA6cKw==' + }, + '@id': 'https://example.com/users/bob/statuses/107928807471117876/activity', + '@type': 'https://www.w3.org/ns/activitystreams#Create', + 'https://www.w3.org/ns/activitystreams#actor': { + '@id': 'https://example.com/users/bob' + }, + 'https://www.w3.org/ns/activitystreams#cc': { + '@id': 'https://example.com/users/bob/followers' + }, + 'object': { + 'id': 'https://example.com/users/bob/fake-status', + 'type': 'Note', + 'published': '2022-01-22T15:00:00Z', + 'url': 'https://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=puck-was-here', + 'attributedTo': 'https://example.com/users/bob', + 'to': [ + 'https://www.w3.org/ns/activitystreams#Public' + ], + 'cc': [ + 'https://example.com/users/bob/followers' + ], + 'sensitive': false, + 'atomUri': 'https://example.com/users/bob/fake-status', + 'conversation': 'tag:example.com,2022-03-09:objectId=15:objectType=Conversation', + 'content': '<p>puck was here</p>', + + '@id': 'https://example.com/users/bob/statuses/107928807471117876', + '@type': 'https://www.w3.org/ns/activitystreams#Note', + 'http://ostatus.org#atomUri': 'https://example.com/users/bob/statuses/107928807471117876', + 'http://ostatus.org#conversation': 'tag:example.com,2022-03-09:objectId=15:objectType=Conversation', + 'https://www.w3.org/ns/activitystreams#attachment': [], + 'https://www.w3.org/ns/activitystreams#attributedTo': { + '@id': 'https://example.com/users/bob' + }, + 'https://www.w3.org/ns/activitystreams#cc': { + '@id': 'https://example.com/users/bob/followers' + }, + 'https://www.w3.org/ns/activitystreams#content': [ + '<p>hello world</p>', + { + '@value': '<p>hello world</p>', + '@language': 'en' + } + ], + 'https://www.w3.org/ns/activitystreams#published': { + '@type': 'http://www.w3.org/2001/XMLSchema#dateTime', + '@value': '2022-03-09T21:55:07Z' + }, + 'https://www.w3.org/ns/activitystreams#replies': { + '@id': 'https://example.com/users/bob/statuses/107928807471117876/replies', + '@type': 'https://www.w3.org/ns/activitystreams#Collection', + 'https://www.w3.org/ns/activitystreams#first': { + '@type': 'https://www.w3.org/ns/activitystreams#CollectionPage', + 'https://www.w3.org/ns/activitystreams#items': [], + 'https://www.w3.org/ns/activitystreams#next': { + '@id': 'https://example.com/users/bob/statuses/107928807471117876/replies?only_other_accounts=true&page=true' + }, + 'https://www.w3.org/ns/activitystreams#partOf': { + '@id': 'https://example.com/users/bob/statuses/107928807471117876/replies' + } + } + }, + 'https://www.w3.org/ns/activitystreams#sensitive': false, + 'https://www.w3.org/ns/activitystreams#tag': [], + 'https://www.w3.org/ns/activitystreams#to': { + '@id': 'https://www.w3.org/ns/activitystreams#Public' + }, + 'https://www.w3.org/ns/activitystreams#url': { + '@id': 'https://example.com/@bob/107928807471117876' + } + }, + 'https://www.w3.org/ns/activitystreams#published': { + '@type': 'http://www.w3.org/2001/XMLSchema#dateTime', + '@value': '2022-03-09T21:55:07Z' + }, + 'https://www.w3.org/ns/activitystreams#to': { + '@id': 'https://www.w3.org/ns/activitystreams#Public' + } + } + end + + it 'does not process forged payload' do + expect(ActivityPub::Activity).not_to receive(:factory).with( + hash_including( + 'object' => hash_including( + 'id' => 'https://example.com/users/bob/fake-status' + ) + ), + anything(), + anything() + ) + + expect(ActivityPub::Activity).not_to receive(:factory).with( + hash_including( + 'object' => hash_including( + 'content' => '<p>puck was here</p>' + ) + ), + anything(), + anything() + ) + + subject.call(json, forwarder) + + expect(Status.where(uri: 'https://example.com/users/bob/fake-status').exists?).to be false + end + end end end end diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index 6ee1dcb43..40b405217 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -124,7 +124,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do end it 'updates media attachments' do - media_attachment = status.media_attachments.reload.first + media_attachment = status.reload.ordered_media_attachments.first expect(media_attachment).to_not be_nil expect(media_attachment.remote_url).to eq 'https://example.com/foo.png' @@ -135,7 +135,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do end it 'records media change in edit' do - expect(status.edits.reload.last.media_attachments_changed).to be true + expect(status.edits.reload.last.ordered_media_attachment_ids).to_not be_empty end end @@ -173,11 +173,11 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do end it 'updates media attachments' do - expect(status.media_attachments.reload.map(&:remote_url)).to eq %w(https://example.com/foo.png) + expect(status.ordered_media_attachments.map(&:remote_url)).to eq %w(https://example.com/foo.png) end it 'records media change in edit' do - expect(status.edits.reload.last.media_attachments_changed).to be true + expect(status.edits.reload.last.ordered_media_attachment_ids).to_not be_empty end end @@ -193,7 +193,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do end it 'records media change in edit' do - expect(status.edits.reload.last.media_attachments_changed).to be true + expect(status.edits.reload.last.poll_options).to be_nil end end @@ -226,7 +226,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do end it 'records media change in edit' do - expect(status.edits.reload.last.media_attachments_changed).to be true + expect(status.edits.reload.last.poll_options).to eq %w(Foo Bar Baz) end end @@ -239,10 +239,5 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do subject.call(status, json) expect(status.reload.edited_at.to_s).to eq '2021-09-08 22:39:25 UTC' end - - it 'records that no media has been changed in edit' do - subject.call(status, json) - expect(status.edits.reload.last.media_attachments_changed).to be false - end end end diff --git a/spec/services/reblog_service_spec.rb b/spec/services/reblog_service_spec.rb index e2077f282..c0ae5eedc 100644 --- a/spec/services/reblog_service_spec.rb +++ b/spec/services/reblog_service_spec.rb @@ -32,6 +32,18 @@ RSpec.describe ReblogService, type: :service do end end + context 'when the reblogged status is discarded in the meantime' do + let(:status) { Fabricate(:status, account: alice, visibility: :public) } + + before do + status.discard + end + + it 'raises an exception' do + expect { subject.call(alice, status) }.to raise_error ActiveRecord::ActiveRecordError + end + end + context 'ActivityPub' do let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } let(:status) { Fabricate(:status, account: bob) } diff --git a/spec/services/update_status_service_spec.rb b/spec/services/update_status_service_spec.rb index 4fd4837c6..78cc89cd4 100644 --- a/spec/services/update_status_service_spec.rb +++ b/spec/services/update_status_service_spec.rb @@ -21,7 +21,7 @@ RSpec.describe UpdateStatusService, type: :service do end it 'saves edit history' do - expect(status.edits.pluck(:text, :media_attachments_changed)).to eq [['Foo', false], ['Bar', false]] + expect(status.edits.pluck(:text)).to eq %w(Foo Bar) end end @@ -39,7 +39,7 @@ RSpec.describe UpdateStatusService, type: :service do end it 'saves edit history' do - expect(status.edits.pluck(:text, :spoiler_text, :media_attachments_changed)).to eq [['Foo', '', false], ['Foo', 'Bar', false]] + expect(status.edits.pluck(:text, :spoiler_text)).to eq [['Foo', ''], ['Foo', 'Bar']] end end @@ -54,11 +54,11 @@ RSpec.describe UpdateStatusService, type: :service do end it 'updates media attachments' do - expect(status.media_attachments.to_a).to eq [attached_media_attachment] + expect(status.ordered_media_attachments).to eq [attached_media_attachment] end - it 'detaches detached media attachments' do - expect(detached_media_attachment.reload.status_id).to be_nil + it 'does not detach detached media attachments' do + expect(detached_media_attachment.reload.status_id).to eq status.id end it 'attaches attached media attachments' do @@ -66,7 +66,7 @@ RSpec.describe UpdateStatusService, type: :service do end it 'saves edit history' do - expect(status.edits.pluck(:text, :media_attachments_changed)).to eq [['Foo', false], ['Foo', true]] + expect(status.edits.pluck(:ordered_media_attachment_ids)).to eq [[detached_media_attachment.id], [attached_media_attachment.id]] end end @@ -95,7 +95,7 @@ RSpec.describe UpdateStatusService, type: :service do end it 'saves edit history' do - expect(status.edits.pluck(:text, :media_attachments_changed)).to eq [['Foo', false], ['Foo', true]] + expect(status.edits.pluck(:poll_options)).to eq [%w(Foo Bar), %w(Bar Baz Foo)] end end |