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.

172 lines
4.7 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 missing attributedTo' do
  51. let(:object_json) do
  52. {
  53. id: 'https://example.com/actor#bar',
  54. type: 'Note',
  55. content: 'Lorem ipsum',
  56. to: 'http://example.com/followers',
  57. }
  58. end
  59. it 'creates a reblog by sender of status' do
  60. expect(sender.reblogged?(sender.statuses.first)).to be true
  61. end
  62. end
  63. context 'self-boost of a previously unknown status with correct attributedTo' do
  64. let(:object_json) do
  65. {
  66. id: 'https://example.com/actor#bar',
  67. type: 'Note',
  68. content: 'Lorem ipsum',
  69. attributedTo: 'https://example.com/actor',
  70. to: 'http://example.com/followers',
  71. }
  72. end
  73. it 'creates a reblog by sender of status' do
  74. expect(sender.reblogged?(sender.statuses.first)).to be true
  75. end
  76. end
  77. end
  78. context 'when the status belongs to a local user' do
  79. before do
  80. subject.perform
  81. end
  82. let(:object_json) do
  83. ActivityPub::TagManager.instance.uri_for(status)
  84. end
  85. it 'creates a reblog by sender of status' do
  86. expect(sender.reblogged?(status)).to be true
  87. end
  88. end
  89. context 'when the sender is relayed' do
  90. let!(:relay_account) { Fabricate(:account, inbox_url: 'https://relay.example.com/inbox') }
  91. let!(:relay) { Fabricate(:relay, inbox_url: 'https://relay.example.com/inbox') }
  92. subject { described_class.new(json, sender, relayed_through_account: relay_account) }
  93. context 'and the relay is enabled' do
  94. before do
  95. relay.update(state: :accepted)
  96. subject.perform
  97. end
  98. let(:object_json) do
  99. {
  100. id: 'https://example.com/actor#bar',
  101. type: 'Note',
  102. content: 'Lorem ipsum',
  103. to: 'http://example.com/followers',
  104. }
  105. end
  106. it 'creates a reblog by sender of status' do
  107. expect(sender.statuses.count).to eq 2
  108. end
  109. end
  110. context 'and the relay is disabled' do
  111. before do
  112. subject.perform
  113. end
  114. let(:object_json) do
  115. {
  116. id: 'https://example.com/actor#bar',
  117. type: 'Note',
  118. content: 'Lorem ipsum',
  119. to: 'http://example.com/followers',
  120. }
  121. end
  122. it 'does not create anything' do
  123. expect(sender.statuses.count).to eq 0
  124. end
  125. end
  126. end
  127. context 'when the sender has no relevance to local activity' do
  128. before do
  129. subject.perform
  130. end
  131. let(:object_json) do
  132. {
  133. id: 'https://example.com/actor#bar',
  134. type: 'Note',
  135. content: 'Lorem ipsum',
  136. to: 'http://example.com/followers',
  137. }
  138. end
  139. it 'does not create anything' do
  140. expect(sender.statuses.count).to eq 0
  141. end
  142. end
  143. end
  144. end