requests are almost there
This commit is contained in:
parent
1acc206fa4
commit
f6b4be97a3
6 changed files with 66 additions and 62 deletions
|
|
@ -9,18 +9,18 @@ class Request
|
||||||
include Diaspora::Webhooks
|
include Diaspora::Webhooks
|
||||||
include ROXML
|
include ROXML
|
||||||
|
|
||||||
xml_accessor :_id
|
xml_reader :_id
|
||||||
xml_accessor :person, :as => Person
|
xml_reader :diaspora_handle
|
||||||
xml_accessor :destination_url
|
xml_reader :destination_url
|
||||||
xml_accessor :callback_url
|
xml_reader :callback_url
|
||||||
xml_accessor :exported_key, :cdata => true
|
|
||||||
|
|
||||||
key :person_id, ObjectId
|
key :aspect_id, ObjectId
|
||||||
key :aspect_id, ObjectId
|
|
||||||
key :destination_url, String
|
key :destination_url, String
|
||||||
key :callback_url, String
|
key :callback_url, String
|
||||||
key :exported_key, String
|
key :exported_key, String
|
||||||
|
|
||||||
|
key :diaspora_handle, String
|
||||||
|
|
||||||
belongs_to :person
|
belongs_to :person
|
||||||
|
|
||||||
validates_presence_of :destination_url, :callback_url
|
validates_presence_of :destination_url, :callback_url
|
||||||
|
|
@ -30,15 +30,13 @@ class Request
|
||||||
person = options[:from]
|
person = options[:from]
|
||||||
self.new(:destination_url => options[:to],
|
self.new(:destination_url => options[:to],
|
||||||
:callback_url => person.receive_url,
|
:callback_url => person.receive_url,
|
||||||
:person => person,
|
:diaspora_handle => person.diaspora_handle,
|
||||||
:exported_key => person.exported_key,
|
:aspect_id => options[:into])
|
||||||
:aspect_id => options[:into])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reverse_for accepting_user
|
def reverse_for accepting_user
|
||||||
self.person = accepting_user.person
|
self.diaspora_handle = accepting_user.diaspora_handle
|
||||||
self.exported_key = accepting_user.exported_key
|
self.destination_url = self.callback_url
|
||||||
self.destination_url = self.callback_url
|
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ module Diaspora
|
||||||
Rails.logger.debug("From: #{object.person.inspect}") if object.person
|
Rails.logger.debug("From: #{object.person.inspect}") if object.person
|
||||||
|
|
||||||
|
|
||||||
if object.is_a?(Comment) || object.is_a?(Post)
|
if object.is_a?(Comment) || object.is_a?(Post)|| object.is_a?(Request)
|
||||||
e = EMWebfinger.new(object.diaspora_handle)
|
e = EMWebfinger.new(object.diaspora_handle)
|
||||||
|
|
||||||
e.on_person { |person|
|
e.on_person { |person|
|
||||||
|
|
@ -32,6 +32,10 @@ module Diaspora
|
||||||
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
|
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if object.is_a? Request
|
||||||
|
return receive_request object, sender_in_xml
|
||||||
|
end
|
||||||
|
|
||||||
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
||||||
|
|
||||||
if object.is_a?(Comment)
|
if object.is_a?(Comment)
|
||||||
|
|
@ -50,17 +54,12 @@ module Diaspora
|
||||||
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
|
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
|
||||||
end
|
end
|
||||||
|
|
||||||
if object.is_a? Request
|
|
||||||
return receive_request object, sender_in_xml
|
|
||||||
end
|
|
||||||
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
||||||
|
|
||||||
if object.is_a? Retraction
|
if object.is_a? Retraction
|
||||||
receive_retraction object, xml
|
receive_retraction object, xml
|
||||||
elsif object.is_a? Profile
|
elsif object.is_a? Profile
|
||||||
receive_profile object, xml
|
receive_profile object, xml
|
||||||
else
|
|
||||||
receive_post object, xml
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -68,8 +67,6 @@ module Diaspora
|
||||||
def sender(object, xml, webfingered_person = nil)
|
def sender(object, xml, webfingered_person = nil)
|
||||||
if object.is_a? Retraction
|
if object.is_a? Retraction
|
||||||
sender = object.person
|
sender = object.person
|
||||||
elsif object.is_a? Request
|
|
||||||
sender = object.person
|
|
||||||
elsif object.is_a? Profile
|
elsif object.is_a? Profile
|
||||||
sender = Diaspora::Parser.owner_id_from_xml xml
|
sender = Diaspora::Parser.owner_id_from_xml xml
|
||||||
|
|
||||||
|
|
@ -98,10 +95,9 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def receive_request request, person
|
def receive_request request, person
|
||||||
person.serialized_public_key ||= request.exported_key
|
|
||||||
request.person = person
|
request.person = person
|
||||||
request.person.save
|
request.person.save
|
||||||
old_request = Request.first(:id => request.id)
|
old_request = Request.find(request.id)
|
||||||
Rails.logger.info("I got a reqest_id #{request.id} with old request #{old_request.inspect}")
|
Rails.logger.info("I got a reqest_id #{request.id} with old request #{old_request.inspect}")
|
||||||
request.aspect_id = old_request.aspect_id if old_request
|
request.aspect_id = old_request.aspect_id if old_request
|
||||||
request.save
|
request.save
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,12 @@ module HelperMethods
|
||||||
|
|
||||||
def friend_users(user1, aspect1, user2, aspect2)
|
def friend_users(user1, aspect1, user2, aspect2)
|
||||||
request = user1.send_friend_request_to(user2.person, aspect1)
|
request = user1.send_friend_request_to(user2.person, aspect1)
|
||||||
user2.receive_friend_request(request)
|
|
||||||
|
user2.receive request.to_diaspora_xml, user1.person
|
||||||
|
|
||||||
reversed_request = user2.accept_friend_request( request.id, aspect2.id)
|
reversed_request = user2.accept_friend_request( request.id, aspect2.id)
|
||||||
user1.reload
|
user1.reload
|
||||||
|
|
||||||
user1.receive reversed_request.to_diaspora_xml, user2.person
|
user1.receive reversed_request.to_diaspora_xml, user2.person
|
||||||
user1.reload
|
user1.reload
|
||||||
aspect1.reload
|
aspect1.reload
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ describe Diaspora::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "friending" do
|
context "friending" do
|
||||||
|
|
||||||
|
let(:good_request) { FakeHttpRequest.new(:success)}
|
||||||
before do
|
before do
|
||||||
deliverable = Object.new
|
deliverable = Object.new
|
||||||
deliverable.stub!(:deliver)
|
deliverable.stub!(:deliver)
|
||||||
|
|
@ -42,30 +44,24 @@ describe Diaspora::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create a new person upon getting a person request" do
|
it "should create a new person upon getting a person request" do
|
||||||
|
webfinger_mock = EMWebfinger.new(person.diaspora_handle)
|
||||||
|
webfinger_mock.should_receive(:on_person)
|
||||||
|
|
||||||
|
EMWebfinger.should_receive(:new).and_return(webfinger_mock)
|
||||||
|
|
||||||
|
|
||||||
request = Request.instantiate(:to =>"http://www.google.com/", :from => person)
|
request = Request.instantiate(:to =>"http://www.google.com/", :from => person)
|
||||||
|
|
||||||
xml = request.to_diaspora_xml
|
xml = request.to_diaspora_xml
|
||||||
|
|
||||||
user3.destroy
|
user3.delete
|
||||||
person.destroy
|
person.delete
|
||||||
|
Person.should_receive(:by_account_identifier).exactly(2).times.and_return(person)
|
||||||
user
|
user
|
||||||
lambda { user.receive xml, person }.should change(Person, :count).by(1)
|
lambda { user.receive xml, person }.should change(Person, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not create a new person if the person is already here" do
|
|
||||||
request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person)
|
|
||||||
original_person_id = user2.person.id
|
|
||||||
xml = request.to_diaspora_xml
|
|
||||||
user
|
|
||||||
lambda { user.receive xml, user2.person }.should_not change(Person, :count)
|
|
||||||
|
|
||||||
user2.reload
|
|
||||||
user2.person.reload
|
|
||||||
user2.serialized_private_key.include?("PRIVATE").should be true
|
|
||||||
|
|
||||||
url = "http://" + request.callback_url.split("/")[2] + "/"
|
|
||||||
Person.where(:url => url).first.id.should == original_person_id
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should activate the Person if I initiated a request to that url" do
|
it "should activate the Person if I initiated a request to that url" do
|
||||||
|
|
@ -73,13 +69,12 @@ describe Diaspora::Parser do
|
||||||
user.reload
|
user.reload
|
||||||
request.reverse_for user3
|
request.reverse_for user3
|
||||||
|
|
||||||
xml = request.to_diaspora_xml
|
xml = user3.salmon(request).xml_for(user.person)
|
||||||
|
|
||||||
user3.person.destroy
|
user3.delete
|
||||||
user3.destroy
|
|
||||||
|
|
||||||
user.receive xml, user3.person
|
user.receive_salmon(xml)
|
||||||
new_person = Person.first(:url => user3.person.url)
|
new_person = Person.find_by_url(user3.person.url)
|
||||||
new_person.nil?.should be false
|
new_person.nil?.should be false
|
||||||
|
|
||||||
user.reload
|
user.reload
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,6 @@ describe Request do
|
||||||
person_request.valid?.should be true
|
person_request.valid?.should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate xml for the User as a Person' do
|
|
||||||
|
|
||||||
request = user.send_friend_request_to person, aspect
|
|
||||||
xml = request.to_xml.to_s
|
|
||||||
|
|
||||||
xml.should include user.person.diaspora_handle
|
|
||||||
xml.should include user.person.url
|
|
||||||
xml.should include user.profile.first_name
|
|
||||||
xml.should include user.profile.last_name
|
|
||||||
xml.should include user.exported_key
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should strip the destination url' do
|
it 'should strip the destination url' do
|
||||||
person_request = Request.new
|
person_request = Request.new
|
||||||
|
|
@ -68,4 +57,28 @@ describe Request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'serialization' do
|
||||||
|
it 'should not generate xml for the User as a Person' do
|
||||||
|
request = user.send_friend_request_to person, aspect
|
||||||
|
xml = request.to_xml.to_s
|
||||||
|
|
||||||
|
xml.should_not include user.person.profile.first_name
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should serialize the handle and not the sender' do
|
||||||
|
request = user.send_friend_request_to person, aspect
|
||||||
|
xml = request.to_xml.to_s
|
||||||
|
|
||||||
|
xml.should include user.person.diaspora_handle
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not serialize the exported key' do
|
||||||
|
request = user.send_friend_request_to person, aspect
|
||||||
|
xml = request.to_xml.to_s
|
||||||
|
|
||||||
|
xml.should_not include user.person.exported_key
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -233,23 +233,22 @@ describe Diaspora::UserModules::Friending do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "keeps the right counts of friends" do
|
it "keeps the right counts of friends" do
|
||||||
user.receive_friend_request @request
|
user.receive @request.to_diaspora_xml, person_one
|
||||||
|
|
||||||
person_two.destroy
|
user.reload.pending_requests.size.should == 1
|
||||||
user.reload.pending_requests.size.should be 1
|
|
||||||
user.friends.size.should be 0
|
user.friends.size.should be 0
|
||||||
|
|
||||||
user.receive_friend_request @request_two
|
user.receive @request_two.to_diaspora_xml, person_two
|
||||||
user.reload.pending_requests.size.should be 2
|
user.reload.pending_requests.size.should == 2
|
||||||
user.friends.size.should be 0
|
user.friends.size.should be 0
|
||||||
|
|
||||||
user.accept_friend_request @request.id, aspect.id
|
user.accept_friend_request @request.id, aspect.id
|
||||||
user.reload.pending_requests.size.should be 1
|
user.reload.pending_requests.size.should == 1
|
||||||
user.friends.size.should be 1
|
user.friends.size.should be 1
|
||||||
user.contact_for(person_one).should_not be_nil
|
user.contact_for(person_one).should_not be_nil
|
||||||
|
|
||||||
user.ignore_friend_request @request_two.id
|
user.ignore_friend_request @request_two.id
|
||||||
user.reload.pending_requests.size.should be 0
|
user.reload.pending_requests.size.should == 0
|
||||||
user.friends.size.should be 1
|
user.friends.size.should be 1
|
||||||
user.contact_for(person_two).should be_nil
|
user.contact_for(person_two).should be_nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue