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.

151 lines
4.7 KiB

  1. require 'rails_helper'
  2. RSpec.describe ProcessInteractionService, type: :service do
  3. let(:receiver) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }
  4. let(:sender) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  5. let(:remote_sender) { Fabricate(:account, username: 'carol', domain: 'localdomain.com', uri: 'https://webdomain.com/users/carol') }
  6. subject { ProcessInteractionService.new }
  7. describe 'status delete slap' do
  8. let(:remote_status) { Fabricate(:status, account: remote_sender) }
  9. let(:envelope) { OStatus2::Salmon.new.pack(payload, sender.keypair) }
  10. let(:payload) {
  11. <<~XML
  12. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  13. <author>
  14. <email>carol@localdomain.com</email>
  15. <name>carol</name>
  16. <uri>https://webdomain.com/users/carol</uri>
  17. </author>
  18. <id>#{remote_status.id}</id>
  19. <activity:verb>http://activitystrea.ms/schema/1.0/delete</activity:verb>
  20. </entry>
  21. XML
  22. }
  23. before do
  24. receiver.update(locked: true)
  25. remote_sender.update(private_key: sender.private_key, public_key: remote_sender.public_key)
  26. end
  27. it 'deletes a record' do
  28. expect(RemovalWorker).to receive(:perform_async).with(remote_status.id)
  29. subject.call(envelope, receiver)
  30. end
  31. end
  32. describe 'follow request slap' do
  33. before do
  34. receiver.update(locked: true)
  35. payload = <<XML
  36. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  37. <author>
  38. <name>bob</name>
  39. <uri>https://cb6e6126.ngrok.io/users/bob</uri>
  40. </author>
  41. <id>someIdHere</id>
  42. <activity:verb>http://activitystrea.ms/schema/1.0/request-friend</activity:verb>
  43. </entry>
  44. XML
  45. envelope = OStatus2::Salmon.new.pack(payload, sender.keypair)
  46. subject.call(envelope, receiver)
  47. end
  48. it 'creates a record' do
  49. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to_not be_nil
  50. end
  51. end
  52. describe 'follow request slap from known remote user identified by email' do
  53. before do
  54. receiver.update(locked: true)
  55. # Copy already-generated key
  56. remote_sender.update(private_key: sender.private_key, public_key: remote_sender.public_key)
  57. payload = <<XML
  58. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  59. <author>
  60. <email>carol@localdomain.com</email>
  61. <name>carol</name>
  62. <uri>https://webdomain.com/users/carol</uri>
  63. </author>
  64. <id>someIdHere</id>
  65. <activity:verb>http://activitystrea.ms/schema/1.0/request-friend</activity:verb>
  66. </entry>
  67. XML
  68. envelope = OStatus2::Salmon.new.pack(payload, remote_sender.keypair)
  69. subject.call(envelope, receiver)
  70. end
  71. it 'creates a record' do
  72. expect(FollowRequest.find_by(account: remote_sender, target_account: receiver)).to_not be_nil
  73. end
  74. end
  75. describe 'follow request authorization slap' do
  76. before do
  77. receiver.update(locked: true)
  78. FollowRequest.create(account: sender, target_account: receiver)
  79. payload = <<XML
  80. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  81. <author>
  82. <name>alice</name>
  83. <uri>https://cb6e6126.ngrok.io/users/alice</uri>
  84. </author>
  85. <id>someIdHere</id>
  86. <activity:verb>http://activitystrea.ms/schema/1.0/authorize</activity:verb>
  87. </entry>
  88. XML
  89. envelope = OStatus2::Salmon.new.pack(payload, receiver.keypair)
  90. subject.call(envelope, sender)
  91. end
  92. it 'creates a follow relationship' do
  93. expect(Follow.find_by(account: sender, target_account: receiver)).to_not be_nil
  94. end
  95. it 'removes the follow request' do
  96. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to be_nil
  97. end
  98. end
  99. describe 'follow request rejection slap' do
  100. before do
  101. receiver.update(locked: true)
  102. FollowRequest.create(account: sender, target_account: receiver)
  103. payload = <<XML
  104. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  105. <author>
  106. <name>alice</name>
  107. <uri>https://cb6e6126.ngrok.io/users/alice</uri>
  108. </author>
  109. <id>someIdHere</id>
  110. <activity:verb>http://activitystrea.ms/schema/1.0/reject</activity:verb>
  111. </entry>
  112. XML
  113. envelope = OStatus2::Salmon.new.pack(payload, receiver.keypair)
  114. subject.call(envelope, sender)
  115. end
  116. it 'does not create a follow relationship' do
  117. expect(Follow.find_by(account: sender, target_account: receiver)).to be_nil
  118. end
  119. it 'removes the follow request' do
  120. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to be_nil
  121. end
  122. end
  123. end