fetch_remote_status_service_spec.rb 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. require 'rails_helper'
  2. RSpec.describe FetchRemoteStatusService, type: :service do
  3. let(:account) { Fabricate(:account) }
  4. let(:prefetched_body) { nil }
  5. let(:valid_domain) { Rails.configuration.x.local_domain }
  6. let(:note) do
  7. {
  8. '@context': 'https://www.w3.org/ns/activitystreams',
  9. id: "https://#{valid_domain}/@foo/1234",
  10. type: 'Note',
  11. content: 'Lorem ipsum',
  12. attributedTo: ActivityPub::TagManager.instance.uri_for(account),
  13. }
  14. end
  15. context 'protocol is :activitypub' do
  16. subject { described_class.new.call(note[:id], prefetched_body) }
  17. let(:prefetched_body) { Oj.dump(note) }
  18. before do
  19. account.update(uri: ActivityPub::TagManager.instance.uri_for(account))
  20. subject
  21. end
  22. it 'creates status' do
  23. status = account.statuses.first
  24. expect(status).to_not be_nil
  25. expect(status.text).to eq 'Lorem ipsum'
  26. end
  27. end
  28. context 'protocol is :ostatus' do
  29. subject { described_class.new }
  30. before do
  31. Fabricate(:account, username: 'tracer', domain: 'real.domain', remote_url: 'https://real.domain/users/tracer')
  32. end
  33. it 'does not create status with author at different domain' do
  34. status_body = <<-XML.squish
  35. <?xml version="1.0"?>
  36. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0">
  37. <id>tag:real.domain,2017-04-27:objectId=4487555:objectType=Status</id>
  38. <published>2017-04-27T13:49:25Z</published>
  39. <updated>2017-04-27T13:49:25Z</updated>
  40. <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
  41. <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
  42. <author>
  43. <id>https://real.domain/users/tracer</id>
  44. <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
  45. <uri>https://real.domain/users/tracer</uri>
  46. <name>tracer</name>
  47. </author>
  48. <content type="html">Overwatch rocks</content>
  49. </entry>
  50. XML
  51. expect(subject.call('https://fake.domain/foo', status_body)).to be_nil
  52. end
  53. it 'does not create status with wrong id when id uses http format' do
  54. status_body = <<-XML.squish
  55. <?xml version="1.0"?>
  56. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0">
  57. <id>https://other-real.domain/statuses/123</id>
  58. <published>2017-04-27T13:49:25Z</published>
  59. <updated>2017-04-27T13:49:25Z</updated>
  60. <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
  61. <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
  62. <author>
  63. <id>https://real.domain/users/tracer</id>
  64. <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
  65. <uri>https://real.domain/users/tracer</uri>
  66. <name>tracer</name>
  67. </author>
  68. <content type="html">Overwatch rocks</content>
  69. </entry>
  70. XML
  71. expect(subject.call('https://real.domain/statuses/456', status_body)).to be_nil
  72. end
  73. end
  74. end