From 98936bfcdf48cfd25968d1314ecf41be7d4596c3 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 26 Sep 2017 01:33:11 +0900 Subject: Add missing validations in ActivityPub::Activity::Create (#5096) --- spec/lib/activitypub/activity/create_spec.rb | 104 +++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 1a9520f04..cdd499150 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -171,6 +171,26 @@ RSpec.describe ActivityPub::Activity::Create do end end + context 'with mentions missing href' do + let(:object_json) do + { + id: 'bar', + type: 'Note', + content: 'Lorem ipsum', + tag: [ + { + type: 'Mention', + }, + ], + } + end + + it 'creates status' do + status = sender.statuses.first + expect(status).to_not be_nil + end + end + context 'with media attachments' do let(:object_json) do { @@ -195,6 +215,27 @@ RSpec.describe ActivityPub::Activity::Create do end end + context 'with media attachments missing url' do + let(:object_json) do + { + id: 'bar', + type: 'Note', + content: 'Lorem ipsum', + attachment: [ + { + type: 'Document', + mime_type: 'image/png', + }, + ], + } + end + + it 'creates status' do + status = sender.statuses.first + expect(status).to_not be_nil + end + end + context 'with hashtags' do let(:object_json) do { @@ -219,6 +260,27 @@ RSpec.describe ActivityPub::Activity::Create do end end + context 'with hashtags missing name' do + let(:object_json) do + { + id: 'bar', + type: 'Note', + content: 'Lorem ipsum', + tag: [ + { + type: 'Hashtag', + href: 'http://example.com/blah', + }, + ], + } + end + + it 'creates status' do + status = sender.statuses.first + expect(status).to_not be_nil + end + end + context 'with emojis' do let(:object_json) do { @@ -242,5 +304,47 @@ RSpec.describe ActivityPub::Activity::Create do expect(status.emojis.map(&:shortcode)).to include('tinking') end end + + context 'with emojis missing name' do + let(:object_json) do + { + id: 'bar', + type: 'Note', + content: 'Lorem ipsum :tinking:', + tag: [ + { + type: 'Emoji', + href: 'http://example.com/emoji.png', + }, + ], + } + end + + it 'creates status' do + status = sender.statuses.first + expect(status).to_not be_nil + end + end + + context 'with emojis missing href' do + let(:object_json) do + { + id: 'bar', + type: 'Note', + content: 'Lorem ipsum :tinking:', + tag: [ + { + type: 'Emoji', + name: 'tinking', + }, + ], + } + end + + it 'creates status' do + status = sender.statuses.first + expect(status).to_not be_nil + end + end end end -- cgit