You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.7 KiB

  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, protocol) }
  17. let(:prefetched_body) { Oj.dump(note) }
  18. let(:protocol) { :activitypub }
  19. before do
  20. account.update(uri: ActivityPub::TagManager.instance.uri_for(account))
  21. subject
  22. end
  23. it 'creates status' do
  24. status = account.statuses.first
  25. expect(status).to_not be_nil
  26. expect(status.text).to eq 'Lorem ipsum'
  27. end
  28. end
  29. context 'protocol is :ostatus' do
  30. subject { described_class.new }
  31. before do
  32. Fabricate(:account, username: 'tracer', domain: 'real.domain', remote_url: 'https://real.domain/users/tracer')
  33. end
  34. it 'does not create status with author at different domain' do
  35. status_body = <<-XML.squish
  36. <?xml version="1.0"?>
  37. <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">
  38. <id>tag:real.domain,2017-04-27:objectId=4487555:objectType=Status</id>
  39. <published>2017-04-27T13:49:25Z</published>
  40. <updated>2017-04-27T13:49:25Z</updated>
  41. <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
  42. <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
  43. <author>
  44. <id>https://real.domain/users/tracer</id>
  45. <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
  46. <uri>https://real.domain/users/tracer</uri>
  47. <name>tracer</name>
  48. </author>
  49. <content type="html">Overwatch rocks</content>
  50. </entry>
  51. XML
  52. expect(subject.call('https://fake.domain/foo', status_body, :ostatus)).to be_nil
  53. end
  54. it 'does not create status with wrong id when id uses http format' do
  55. status_body = <<-XML.squish
  56. <?xml version="1.0"?>
  57. <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">
  58. <id>https://other-real.domain/statuses/123</id>
  59. <published>2017-04-27T13:49:25Z</published>
  60. <updated>2017-04-27T13:49:25Z</updated>
  61. <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
  62. <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
  63. <author>
  64. <id>https://real.domain/users/tracer</id>
  65. <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
  66. <uri>https://real.domain/users/tracer</uri>
  67. <name>tracer</name>
  68. </author>
  69. <content type="html">Overwatch rocks</content>
  70. </entry>
  71. XML
  72. expect(subject.call('https://real.domain/statuses/456', status_body, :ostatus)).to be_nil
  73. end
  74. end
  75. end