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.

123 lines
3.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe ProcessInteractionService 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 'follow request slap' do
  8. before do
  9. receiver.update(locked: true)
  10. payload = <<XML
  11. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  12. <author>
  13. <name>bob</name>
  14. <uri>https://cb6e6126.ngrok.io/users/bob</uri>
  15. </author>
  16. <id>someIdHere</id>
  17. <activity:verb>http://activitystrea.ms/schema/1.0/request-friend</activity:verb>
  18. </entry>
  19. XML
  20. envelope = OStatus2::Salmon.new.pack(payload, sender.keypair)
  21. subject.call(envelope, receiver)
  22. end
  23. it 'creates a record' do
  24. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to_not be_nil
  25. end
  26. end
  27. describe 'follow request slap from known remote user identified by email' do
  28. before do
  29. receiver.update(locked: true)
  30. # Copy already-generated key
  31. remote_sender.update(private_key: sender.private_key, public_key: remote_sender.public_key)
  32. payload = <<XML
  33. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  34. <author>
  35. <email>carol@localdomain.com</email>
  36. <name>carol</name>
  37. <uri>https://webdomain.com/users/carol</uri>
  38. </author>
  39. <id>someIdHere</id>
  40. <activity:verb>http://activitystrea.ms/schema/1.0/request-friend</activity:verb>
  41. </entry>
  42. XML
  43. envelope = OStatus2::Salmon.new.pack(payload, remote_sender.keypair)
  44. subject.call(envelope, receiver)
  45. end
  46. it 'creates a record' do
  47. expect(FollowRequest.find_by(account: remote_sender, target_account: receiver)).to_not be_nil
  48. end
  49. end
  50. describe 'follow request authorization slap' do
  51. before do
  52. receiver.update(locked: true)
  53. FollowRequest.create(account: sender, target_account: receiver)
  54. payload = <<XML
  55. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  56. <author>
  57. <name>alice</name>
  58. <uri>https://cb6e6126.ngrok.io/users/alice</uri>
  59. </author>
  60. <id>someIdHere</id>
  61. <activity:verb>http://activitystrea.ms/schema/1.0/authorize</activity:verb>
  62. </entry>
  63. XML
  64. envelope = OStatus2::Salmon.new.pack(payload, receiver.keypair)
  65. subject.call(envelope, sender)
  66. end
  67. it 'creates a follow relationship' do
  68. expect(Follow.find_by(account: sender, target_account: receiver)).to_not be_nil
  69. end
  70. it 'removes the follow request' do
  71. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to be_nil
  72. end
  73. end
  74. describe 'follow request rejection slap' do
  75. before do
  76. receiver.update(locked: true)
  77. FollowRequest.create(account: sender, target_account: receiver)
  78. payload = <<XML
  79. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  80. <author>
  81. <name>alice</name>
  82. <uri>https://cb6e6126.ngrok.io/users/alice</uri>
  83. </author>
  84. <id>someIdHere</id>
  85. <activity:verb>http://activitystrea.ms/schema/1.0/reject</activity:verb>
  86. </entry>
  87. XML
  88. envelope = OStatus2::Salmon.new.pack(payload, receiver.keypair)
  89. subject.call(envelope, sender)
  90. end
  91. it 'does not create a follow relationship' do
  92. expect(Follow.find_by(account: sender, target_account: receiver)).to be_nil
  93. end
  94. it 'removes the follow request' do
  95. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to be_nil
  96. end
  97. end
  98. end