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.

160 lines
4.4 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. end
  65. context 'when the status belongs to a local user' do
  66. before do
  67. subject.perform
  68. end
  69. let(:object_json) do
  70. ActivityPub::TagManager.instance.uri_for(status)
  71. end
  72. it 'creates a reblog by sender of status' do
  73. expect(sender.reblogged?(status)).to be true
  74. end
  75. end
  76. context 'when the sender is relayed' do
  77. let!(:relay_account) { Fabricate(:account, inbox_url: 'https://relay.example.com/inbox') }
  78. let!(:relay) { Fabricate(:relay, inbox_url: 'https://relay.example.com/inbox') }
  79. subject { described_class.new(json, sender, relayed_through_account: relay_account) }
  80. context 'and the relay is enabled' do
  81. before do
  82. relay.update(state: :accepted)
  83. subject.perform
  84. end
  85. let(:object_json) do
  86. {
  87. id: 'https://example.com/actor#bar',
  88. type: 'Note',
  89. content: 'Lorem ipsum',
  90. to: 'http://example.com/followers',
  91. attributedTo: 'https://example.com/actor',
  92. }
  93. end
  94. it 'creates a reblog by sender of status' do
  95. expect(sender.statuses.count).to eq 2
  96. end
  97. end
  98. context 'and the relay is disabled' do
  99. before do
  100. subject.perform
  101. end
  102. let(:object_json) do
  103. {
  104. id: 'https://example.com/actor#bar',
  105. type: 'Note',
  106. content: 'Lorem ipsum',
  107. to: 'http://example.com/followers',
  108. attributedTo: 'https://example.com/actor',
  109. }
  110. end
  111. it 'does not create anything' do
  112. expect(sender.statuses.count).to eq 0
  113. end
  114. end
  115. end
  116. context 'when the sender has no relevance to local activity' 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. end