more tests pass

This commit is contained in:
maxwell 2010-10-28 17:43:38 -07:00
parent 1e349e6a61
commit 6d139ab946
4 changed files with 52 additions and 33 deletions

View file

@ -54,12 +54,17 @@ class RequestsController < ApplicationController
#socket to tell people this failed? #socket to tell people this failed?
end end
} }
rescue Exception => e rescue Exception => e
flash[:error] = e.message flash[:error] = e.message
end 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] flash[:notice] = "we tried our best to send a message to #{account}" unless flash[:error]
redirect_to aspects_manage_path respond_with :location => aspects_manage_path
return
end
end end
end end

View file

@ -20,6 +20,23 @@ 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
if object.is_a?(Comment)
e = EMWebfinger.new(object.diaspora_handle)
e.on_person { |person|
if person.class == Person
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
}
else
sender_in_xml = sender(object, xml) sender_in_xml = sender(object, xml)
if (salmon_author != sender_in_xml) if (salmon_author != sender_in_xml)
@ -35,14 +52,13 @@ module Diaspora
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
elsif object.is_a?(Comment)
receive_comment object, xml
else else
receive_post object, xml 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

View file

@ -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?

View file

@ -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