about summary refs log tree commit diff
path: root/spec/services
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2017-05-03 20:40:14 +0200
committerEugen Rochko <eugen@zeonfederated.com>2017-05-03 20:40:14 +0200
commit8d4e7504b16a4a33ec7ba5fa5edf3dcaf7669318 (patch)
tree877b05c5280341beb5e26e6661a7be03ff07835c /spec/services
parentaa6a26a2d5afb38ebd7774b8c61e247c27be1a0d (diff)
Additional specs for URI handling (#2759)
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/follow_remote_account_service_spec.rb12
-rw-r--r--spec/services/process_interaction_service_spec.rb30
2 files changed, 42 insertions, 0 deletions
diff --git a/spec/services/follow_remote_account_service_spec.rb b/spec/services/follow_remote_account_service_spec.rb
index f087bc4bc..9ae9ff0ce 100644
--- a/spec/services/follow_remote_account_service_spec.rb
+++ b/spec/services/follow_remote_account_service_spec.rb
@@ -15,6 +15,10 @@ RSpec.describe FollowRemoteAccountService do
     stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:catsrgr8@quitter.no").to_return(status: 404)
     stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
     stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
+    stub_request(:get, "https://localdomain.com/.well-known/host-meta").to_return(request_fixture('localdomain-hostmeta.txt'))
+    stub_request(:get, "https://localdomain.com/.well-known/webfinger?resource=acct:foo@localdomain.com").to_return(status: 404)
+    stub_request(:get, "https://webdomain.com/.well-known/webfinger?resource=acct:foo@localdomain.com").to_return(request_fixture('localdomain-webfinger.txt'))
+    stub_request(:get, "https://webdomain.com/users/foo.atom").to_return(request_fixture('localdomain-feed.txt'))
   end
 
   it 'raises error if no such user can be resolved via webfinger' do
@@ -56,4 +60,12 @@ RSpec.describe FollowRemoteAccountService do
   it 'prevents hijacking inexisting accounts' do
     expect { subject.call('hacker2@redirected.com') }.to raise_error Goldfinger::Error
   end
+
+  it 'returns a new remote account' do
+    account = subject.call('foo@localdomain.com')
+
+    expect(account.username).to eq 'foo'
+    expect(account.domain).to eq 'localdomain.com'
+    expect(account.remote_url).to eq 'https://webdomain.com/users/foo.atom'
+  end
 end
diff --git a/spec/services/process_interaction_service_spec.rb b/spec/services/process_interaction_service_spec.rb
index 0845e09ed..f589f690d 100644
--- a/spec/services/process_interaction_service_spec.rb
+++ b/spec/services/process_interaction_service_spec.rb
@@ -3,6 +3,7 @@ require 'rails_helper'
 RSpec.describe ProcessInteractionService do
   let(:receiver) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }
   let(:sender)   { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+  let(:remote_sender) { Fabricate(:account, username: 'carol', domain: 'localdomain.com', uri: 'https://webdomain.com/users/carol') }
 
   subject { ProcessInteractionService.new }
 
@@ -31,6 +32,35 @@ XML
     end
   end
 
+  describe 'follow request slap from known remote user identified by email' do
+    before do
+      receiver.update(locked: true)
+      # Copy already-generated key
+      remote_sender.update(private_key: sender.private_key, public_key: remote_sender.public_key)
+
+      payload = <<XML
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
+  <author>
+    <email>carol@localdomain.com</email>
+    <name>carol</name>
+    <uri>https://webdomain.com/users/carol</uri>
+  </author>
+
+  <id>someIdHere</id>
+  <activity:verb>http://activitystrea.ms/schema/1.0/request-friend</activity:verb>
+</entry>
+XML
+
+      envelope = OStatus2::Salmon.new.pack(payload, remote_sender.keypair)
+      subject.call(envelope, receiver)
+    end
+
+    it 'creates a record' do
+      expect(FollowRequest.find_by(account: remote_sender, target_account: receiver)).to_not be_nil
+    end
+  end
+
+
   describe 'follow request authorization slap' do
     before do
       receiver.update(locked: true)