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.

180 lines
5.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Announce do
  3. let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', uri: 'https://example.com/actor') }
  4. let(:recipient) { Fabricate(:account) }
  5. let(:status) { Fabricate(:status, account: recipient) }
  6. let(:json) do
  7. {
  8. '@context': 'https://www.w3.org/ns/activitystreams',
  9. id: 'foo',
  10. type: 'Announce',
  11. actor: 'https://example.com/actor',
  12. object: object_json,
  13. to: 'http://example.com/followers',
  14. }.with_indifferent_access
  15. end
  16. let(:unknown_object_json) do
  17. {
  18. '@context': 'https://www.w3.org/ns/activitystreams',
  19. id: 'https://example.com/actor/hello-world',
  20. type: 'Note',
  21. attributedTo: 'https://example.com/actor',
  22. content: 'Hello world',
  23. to: 'http://example.com/followers',
  24. }
  25. end
  26. subject { described_class.new(json, sender) }
  27. describe '#perform' do
  28. context 'when sender is followed by a local account' do
  29. before do
  30. Fabricate(:account).follow!(sender)
  31. stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json))
  32. subject.perform
  33. end
  34. context 'a known status' do
  35. let(:object_json) do
  36. ActivityPub::TagManager.instance.uri_for(status)
  37. end
  38. it 'creates a reblog by sender of status' do
  39. expect(sender.reblogged?(status)).to be true
  40. end
  41. end
  42. context 'an unknown status' do
  43. let(:object_json) { 'https://example.com/actor/hello-world' }
  44. it 'creates a reblog by sender of status' do
  45. reblog = sender.statuses.first
  46. expect(reblog).to_not be_nil
  47. expect(reblog.reblog.text).to eq 'Hello world'
  48. end
  49. end
  50. context 'self-boost of a previously unknown status with correct attributedTo' do
  51. let(:object_json) do
  52. {
  53. id: 'https://example.com/actor#bar',
  54. type: 'Note',
  55. content: 'Lorem ipsum',
  56. attributedTo: 'https://example.com/actor',
  57. to: 'http://example.com/followers',
  58. }
  59. end
  60. it 'creates a reblog by sender of status' do
  61. expect(sender.reblogged?(sender.statuses.first)).to be true
  62. end
  63. end
  64. context 'self-boost of a previously unknown status with correct attributedTo, inlined Collection in audience' do
  65. let(:object_json) do
  66. {
  67. id: 'https://example.com/actor#bar',
  68. type: 'Note',
  69. content: 'Lorem ipsum',
  70. attributedTo: 'https://example.com/actor',
  71. to: {
  72. 'type': 'OrderedCollection',
  73. 'id': 'http://example.com/followers',
  74. 'first': 'http://example.com/followers?page=true',
  75. }
  76. }
  77. end
  78. it 'creates a reblog by sender of status' do
  79. expect(sender.reblogged?(sender.statuses.first)).to be true
  80. end
  81. end
  82. end
  83. context 'when the status belongs to a local user' do
  84. before do
  85. subject.perform
  86. end
  87. let(:object_json) do
  88. ActivityPub::TagManager.instance.uri_for(status)
  89. end
  90. it 'creates a reblog by sender of status' do
  91. expect(sender.reblogged?(status)).to be true
  92. end
  93. end
  94. context 'when the sender is relayed' do
  95. let!(:relay_account) { Fabricate(:account, inbox_url: 'https://relay.example.com/inbox') }
  96. let!(:relay) { Fabricate(:relay, inbox_url: 'https://relay.example.com/inbox') }
  97. subject { described_class.new(json, sender, relayed_through_account: relay_account) }
  98. context 'and the relay is enabled' do
  99. before do
  100. relay.update(state: :accepted)
  101. subject.perform
  102. end
  103. let(:object_json) do
  104. {
  105. id: 'https://example.com/actor#bar',
  106. type: 'Note',
  107. content: 'Lorem ipsum',
  108. to: 'http://example.com/followers',
  109. attributedTo: 'https://example.com/actor',
  110. }
  111. end
  112. it 'creates a reblog by sender of status' do
  113. expect(sender.statuses.count).to eq 2
  114. end
  115. end
  116. context 'and the relay is disabled' do
  117. before do
  118. subject.perform
  119. end
  120. let(:object_json) do
  121. {
  122. id: 'https://example.com/actor#bar',
  123. type: 'Note',
  124. content: 'Lorem ipsum',
  125. to: 'http://example.com/followers',
  126. attributedTo: 'https://example.com/actor',
  127. }
  128. end
  129. it 'does not create anything' do
  130. expect(sender.statuses.count).to eq 0
  131. end
  132. end
  133. end
  134. context 'when the sender has no relevance to local activity' do
  135. before do
  136. subject.perform
  137. end
  138. let(:object_json) do
  139. {
  140. id: 'https://example.com/actor#bar',
  141. type: 'Note',
  142. content: 'Lorem ipsum',
  143. to: 'http://example.com/followers',
  144. attributedTo: 'https://example.com/actor',
  145. }
  146. end
  147. it 'does not create anything' do
  148. expect(sender.statuses.count).to eq 0
  149. end
  150. end
  151. end
  152. end