more tests pass
This commit is contained in:
parent
1e349e6a61
commit
6d139ab946
4 changed files with 52 additions and 33 deletions
|
|
@ -54,12 +54,17 @@ class RequestsController < ApplicationController
|
||||||
#socket to tell people this failed?
|
#socket to tell people this failed?
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
rescue Exception => e
|
|
||||||
flash[:error] = e.message
|
|
||||||
end
|
|
||||||
|
|
||||||
|
rescue Exception => e
|
||||||
flash[:notice] = "we tried our best to send a message to #{account}" unless flash[:error]
|
flash[:error] = e.message
|
||||||
redirect_to aspects_manage_path
|
end
|
||||||
|
|
||||||
|
if params[:getting_started]
|
||||||
|
redirect_to getting_started_path(:step=>params[:getting_started])
|
||||||
|
else
|
||||||
|
flash[:notice] = "we tried our best to send a message to #{account}" unless flash[:error]
|
||||||
|
respond_with :location => aspects_manage_path
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ module Diaspora
|
||||||
webfinger = EMWebfinger.new(salmon.author_email)
|
webfinger = EMWebfinger.new(salmon.author_email)
|
||||||
|
|
||||||
webfinger.on_person { |salmon_author|
|
webfinger.on_person { |salmon_author|
|
||||||
if salmon.verified_for_key?(salmon_author.public_key)
|
if salmon.verified_for_key?(salmon_author.public_key)
|
||||||
Rails.logger.info("data in salmon: #{salmon.parsed_data}")
|
Rails.logger.info("data in salmon: #{salmon.parsed_data}")
|
||||||
self.receive(salmon.parsed_data, salmon_author)
|
self.receive(salmon.parsed_data, salmon_author)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -20,29 +20,45 @@ module Diaspora
|
||||||
Rails.logger.debug("Receiving object for #{self.real_name}:\n#{object.inspect}")
|
Rails.logger.debug("Receiving object for #{self.real_name}:\n#{object.inspect}")
|
||||||
Rails.logger.debug("From: #{object.person.inspect}") if object.person
|
Rails.logger.debug("From: #{object.person.inspect}") if object.person
|
||||||
|
|
||||||
sender_in_xml = sender(object, xml)
|
|
||||||
|
|
||||||
if (salmon_author != sender_in_xml)
|
if object.is_a?(Comment)
|
||||||
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} "
|
e = EMWebfinger.new(object.diaspora_handle)
|
||||||
end
|
|
||||||
|
|
||||||
if object.is_a? Request
|
e.on_person { |person|
|
||||||
return receive_request object, sender_in_xml
|
|
||||||
end
|
if person.class == Person
|
||||||
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
sender_in_xml = sender(object, xml, person)
|
||||||
|
if (salmon_author != sender_in_xml)
|
||||||
|
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
|
||||||
|
|
||||||
|
receive_comment object, xml
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
if object.is_a? Retraction
|
|
||||||
receive_retraction object, xml
|
|
||||||
elsif object.is_a? Profile
|
|
||||||
receive_profile object, xml
|
|
||||||
elsif object.is_a?(Comment)
|
|
||||||
receive_comment object, xml
|
|
||||||
else
|
else
|
||||||
receive_post object, xml
|
sender_in_xml = sender(object, xml)
|
||||||
|
|
||||||
|
if (salmon_author != sender_in_xml)
|
||||||
|
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
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
if object.is_a? Retraction
|
||||||
|
receive_retraction object, xml
|
||||||
|
elsif object.is_a? Profile
|
||||||
|
receive_profile object, xml
|
||||||
|
else
|
||||||
|
receive_post object, xml
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sender(object, xml)
|
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
|
elsif object.is_a? Request
|
||||||
|
|
@ -50,7 +66,7 @@ module Diaspora
|
||||||
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
|
||||||
elsif object.is_a?(Comment)
|
elsif object.is_a?(Comment)
|
||||||
object.person = Person.by_webfinger(object.diaspora_handle)
|
object.person = webfingered_person
|
||||||
sender = (owns?(object.post))? object.person : object.post.person
|
sender = (owns?(object.post))? object.person : object.post.person
|
||||||
else
|
else
|
||||||
sender = object.person
|
sender = object.person
|
||||||
|
|
@ -77,9 +93,9 @@ module Diaspora
|
||||||
request.person.save
|
request.person.save
|
||||||
old_request = Request.first(:id => request.id)
|
old_request = Request.first(:id => 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
|
||||||
receive_friend_request(request)
|
receive_friend_request(request)
|
||||||
end
|
end
|
||||||
|
|
||||||
def receive_profile profile, xml
|
def receive_profile profile, xml
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@ class EMWebfinger
|
||||||
# Raise an error if identifier has a port number
|
# Raise an error if identifier has a port number
|
||||||
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
||||||
# Raise an error if identifier is not a valid email (generous regexp)
|
# Raise an error if identifier is not a valid email (generous regexp)
|
||||||
raise "Identifier is invalid" if !(@account=~ /\A.*\@.*\..*\Z/)
|
raise "Identifier is invalid" if !(@account=~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)
|
||||||
end
|
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
raise 'you need to set a callback before calling fetch' if @callbacks.empty?
|
raise 'you need to set a callback before calling fetch' if @callbacks.empty?
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,6 @@ describe Comment do
|
||||||
it 'should send a comment a person made on your post to all people' do
|
it 'should send a comment a person made on your post to all people' do
|
||||||
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status)
|
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status)
|
||||||
User::QUEUE.should_receive(:add_post_request).twice
|
User::QUEUE.should_receive(:add_post_request).twice
|
||||||
Person.should_receive(:by_webfinger).and_return(@person)
|
|
||||||
user.receive comment.to_diaspora_xml, @person
|
user.receive comment.to_diaspora_xml, @person
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue