diff --git a/app/models/user.rb b/app/models/user.rb index c12730dba..ceaf9f564 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,7 +48,6 @@ class User to_group = self.group_by_id(opts[:to]) if from_group && to_group posts_to_move = from_group.posts.find_all_by_person_id(friend.id) - puts posts_to_move.inspect to_group.people << friend to_group.posts << posts_to_move from_group.person_ids.delete(friend.id.to_id) @@ -167,7 +166,6 @@ class User object = Diaspora::Parser.from_xml(xml) Rails.logger.debug("Receiving object:\n#{object.inspect}") Rails.logger.debug("From: #{object.person.inspect}") if object.person - object.person.save if object.is_a?(Comment) && Person.find_by_id(object.person_id).nil? raise "In receive for #{self.real_name}, signature was not valid on: #{object.inspect}" unless object.signature_valid? if object.is_a? Retraction if object.type == 'Person' && object.signature_valid? @@ -183,7 +181,7 @@ class User } end elsif object.is_a? Request - person = Diaspora::Parser.get_or_create_person_object_from_xml( xml ) + person = Diaspora::Parser.parse_or_find_person_from_xml( xml ) person.serialized_key ||= object.exported_key object.person = person object.person.save @@ -197,6 +195,9 @@ class User person.save elsif object.is_a?(Comment) + object.person = Diaspora::Parser.parse_or_find_person_from_xml( xml ).save if object.person.nil? + object.person.save + Rails.logger.debug("From: #{object.person.inspect}") if object.person raise "In receive for #{self.real_name}, signature was not valid on: #{object.inspect}" unless object.post.person == self.person || object.verify_post_creator_signature object.save dispatch_comment object unless owns?(object) diff --git a/lib/diaspora/parser.rb b/lib/diaspora/parser.rb index 650c4a4e4..51523724d 100644 --- a/lib/diaspora/parser.rb +++ b/lib/diaspora/parser.rb @@ -6,10 +6,10 @@ module Diaspora Person.first(:id => id) end - def self.get_or_create_person_object_from_xml(xml) + def self.parse_or_find_person_from_xml(xml) doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } - person_xml = doc.xpath("//request/person").to_s - person_id = doc.xpath("//request/person/_id").text.to_s + person_xml = doc.xpath("//person").to_s + person_id = doc.xpath("//person/_id").text.to_s person = Person.first(:_id => person_id) person ? person : Person.from_xml( person_xml) end @@ -36,6 +36,5 @@ module Diaspora raise e end end - end end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 2a08ba76a..980789318 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -40,14 +40,7 @@ describe User do @user.groups.size.should == num_groups end - describe 'comments' do - it 'should receive comments from unknown users' do - friend_users(@user, @group, @user2, @group2) - - status_message = @user.post, :status_message, :message => 'message', :to => @group.id - end - end describe 'post refs' do before do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 548c7867d..3b80d4c50 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,7 +43,7 @@ end def stub_signature_verification (get_models.map{|model| model.camelize.constantize} - [User]).each do |model| - model.any_instance.stubs(:signature_valid?).returns(true) + model.any_instance.stubs(:verify_signature).returns(true) end end diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 47433b80f..de21c343f 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -52,7 +52,7 @@ describe 'user encryption' do remote_user.destroy person_count = Person.all.count - proc {@user.receive xml}.should_not raise_error /Signature was not valid/ + proc {@user.receive xml}.should_not raise_error /ignature was not valid/ Person.all.count.should == person_count + 1 new_person = Person.first(:id => id) new_person.export_key.should == original_key @@ -125,7 +125,7 @@ describe 'user encryption' do xml = message.to_diaspora_xml message.destroy Post.count.should be 0 - proc {@user.receive xml}.should raise_error /Signature was not valid/ + proc {@user.receive xml}.should raise_error /ignature was not valid/ Post.count.should be 0 end