Skip to content
Extraits de code Groupes Projets
Valider 94bb754c rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Changed parseing person from xml a little, using it for comments.

parent 1ce34bc6
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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,7 @@ class User
person.save
elsif object.is_a?(Comment)
Diaspora::Parser.parse_or_find_person_from_xml( xml ).save if object.person.nil?
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)
......
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter