diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb
index d6182a6eb..e6506c55e 100644
--- a/app/controllers/publics_controller.rb
+++ b/app/controllers/publics_controller.rb
@@ -25,7 +25,7 @@ class PublicsController < ApplicationController
def receive
@user = Person.first(:id => params[:id]).owner
Rails.logger.debug "PublicsController has received: #{params[:xml]}"
- @user.receive params[:xml]
+ @user.receive params[:xml] if params[:xml]
render :nothing => true
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 35acbd2f0..d54422445 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -120,7 +120,7 @@ class User
###### Receiving #######
def receive xml
- object = Diaspora::Parser.parse_from_xml(xml)
+ object = Diaspora::Parser.from_xml(xml)
Rails.logger.debug("Receiving object:\n#{object.inspect}")
if object.is_a? Retraction
@@ -128,7 +128,7 @@ class User
object.perform
elsif object.is_a? Request
- person = get_or_create_person_object_from_xml( xml )
+ person = Diaspora::Parser.get_or_create_person_object_from_xml( xml )
person.serialized_key ||= object.exported_key
object.person = person
object.person.save
@@ -136,10 +136,10 @@ class User
receive_friend_request(object)
elsif object.is_a? Profile
- person = Diaspora::Parser.parse_owner_id_from_xml xml
+ person = Diaspora::Parser.owner_id_from_xml xml
person.profile = object
person.save
- elsif object.respond_to?(:person) && !(object.person.nil?) && !(object.person.is_a? User)
+ else
Rails.logger.debug("Saving object with success: #{object.save}")
end
end
diff --git a/lib/diaspora/parser.rb b/lib/diaspora/parser.rb
index a82fd722c..8835bd83b 100644
--- a/lib/diaspora/parser.rb
+++ b/lib/diaspora/parser.rb
@@ -1,17 +1,12 @@
module Diaspora
module Parser
- def parse_body_contents_from_xml(xml)
- doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
- doc.xpath("/XML/post")
- end
-
- def parse_owner_id_from_xml(xml)
+ def self.owner_id_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
id = doc.xpath("//person_id").text.to_s
Person.first(:id => id)
end
- def get_or_create_person_object_from_xml(xml)
+ def self.get_or_create_person_object_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
@@ -19,9 +14,10 @@ module Diaspora
person ? person : Person.from_xml( person_xml)
end
- def parse_from_xml(xml)
+ def self.from_xml(xml)
- return unless body = parse_body_contents_from_xml(xml).children.first
+ doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
+ return unless body = doc.xpath("/XML/post").children.first
begin
body.name.camelize.constantize.from_xml body.to_s
diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb
index 1afd93ead..da96e80d9 100644
--- a/spec/lib/diaspora_parser_spec.rb
+++ b/spec/lib/diaspora_parser_spec.rb
@@ -10,29 +10,35 @@ describe Diaspora::Parser do
@user = Factory.create(:user, :email => "bob@aol.com")
@person = Factory.create(:person_with_private_key, :email => "bill@gates.com")
end
+ describe 'with encryption' do
+ before do
+ unstub_mocha_stubs
+ end
+ after do
+ stub_signature_verification
+ end
+ it "should not store posts from me" do
+ 10.times {
+ message = Factory.build(:status_message, :person => @user)
+ xml = message.to_diaspora_xml
+ @user.receive xml
+ }
+ StatusMessage.count.should == 0
+ end
+
+ it "should reject xml with no sender" do
+ xml = "
+
+
+ \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n
+
+ \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n
+ "
+ @user.receive xml
+ Post.count.should == 0
- it "should not store posts from me" do
- 10.times {
- message = Factory.build(:status_message, :person => @user)
- xml = message.to_diaspora_xml
- @user.receive xml
- }
- StatusMessage.count.should == 0
- end
-
- it "should reject xml with no sender" do
- xml = "
-
-
- \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n
-
- \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n
- "
- @user.receive xml
- Post.count.should == 0
-
- end
-
+ end
+ end
it 'should discard types which are not of type post' do
xml = "
@@ -47,12 +53,6 @@ describe Diaspora::Parser do
before do
@xml = Factory.build(:status_message).to_diaspora_xml
end
-
- it 'should be able to parse the body\'s contents' do
- body = parse_body_contents_from_xml(@xml).to_s
- body.should include ""
- body.should include ""
- end
it 'should be able to correctly handle comments' do
person = Factory.create(:person, :email => "test@testing.com")
@@ -60,7 +60,7 @@ describe Diaspora::Parser do
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
xml = comment.to_diaspora_xml
- comment = parse_from_xml(xml)
+ comment = Diaspora::Parser.from_xml(xml)
comment.text.should == "Freedom!"
comment.person.should == person
comment.post.should == post
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index bb54daeb6..62cb7dad1 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1,7 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper'
-include Diaspora::Parser
-
describe User do
before do
@user = Factory.create(:user)