Merge branch 'friend-refactor' of github.com:diaspora/diaspora_rails into friend-refactor
This commit is contained in:
commit
8b51f94d1d
5 changed files with 30 additions and 23 deletions
|
|
@ -13,6 +13,7 @@ class Retraction
|
|||
retraction.type = object.class.to_s
|
||||
end
|
||||
retraction.person_id = person_id_from(object)
|
||||
retraction.send(:sign_if_mine)
|
||||
retraction
|
||||
end
|
||||
|
||||
|
|
@ -62,7 +63,13 @@ class Retraction
|
|||
xml_reader :creator_signature
|
||||
|
||||
def creator_signature
|
||||
@creator_signature ||= sign if person_id == User.owner.id
|
||||
object = self.type.constantize.first(:id => post_id)
|
||||
|
||||
if object.class == Person && person_id == object.id
|
||||
@creator_signature || sign_with_key(object.key)
|
||||
elsif person_id == object.person.id
|
||||
@creator_signature || sign_if_mine
|
||||
end
|
||||
end
|
||||
|
||||
def creator_signature= input
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ class User
|
|||
|
||||
if object.is_a? Retraction
|
||||
object.perform self.id
|
||||
|
||||
elsif object.is_a? Request
|
||||
person = Diaspora::Parser.get_or_create_person_object_from_xml( xml )
|
||||
person.serialized_key ||= object.exported_key
|
||||
|
|
@ -133,12 +132,11 @@ class User
|
|||
object.person.save
|
||||
object.save
|
||||
receive_friend_request(object)
|
||||
|
||||
elsif object.is_a? Profile
|
||||
person = Diaspora::Parser.owner_id_from_xml xml
|
||||
person.profile = object
|
||||
person.save
|
||||
else
|
||||
elsif object.verify_creator_signature == true
|
||||
Rails.logger.debug("Saving object with success: #{object.save}")
|
||||
object.socket_to_uid( id) if object.respond_to? :socket_to_uid
|
||||
end
|
||||
|
|
|
|||
|
|
@ -39,15 +39,6 @@ describe Diaspora::Parser do
|
|||
|
||||
end
|
||||
end
|
||||
it 'should discard types which are not of type post' do
|
||||
xml = "<XML>
|
||||
<post><person></person></post>
|
||||
</XML>"
|
||||
|
||||
@user.receive xml
|
||||
Post.count.should == 0
|
||||
end
|
||||
|
||||
|
||||
describe "parsing compliant XML object" do
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -22,4 +22,6 @@ describe Retraction do
|
|||
@post.destroy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,12 +3,6 @@ include ApplicationHelper
|
|||
include Diaspora::Parser
|
||||
|
||||
describe 'user encryption' do
|
||||
before :all do
|
||||
#ctx = GPGME::Ctx.new
|
||||
#keys = ctx.keys
|
||||
#keys.each{|k| ctx.delete_key(k, true)}
|
||||
|
||||
end
|
||||
before do
|
||||
unstub_mocha_stubs
|
||||
@user = Factory.create(:user)
|
||||
|
|
@ -69,6 +63,17 @@ describe 'user encryption' do
|
|||
message.verify_creator_signature.should be true
|
||||
end
|
||||
|
||||
it 'should sign a retraction on create' do
|
||||
|
||||
unstub_mocha_stubs
|
||||
message = @user.post :status_message, :message => "hi"
|
||||
|
||||
|
||||
retraction = Retraction.for(message)
|
||||
retraction.verify_creator_signature.should be true
|
||||
|
||||
end
|
||||
|
||||
it 'should not be able to verify a message from a person without a key' do
|
||||
person = Factory.create(:person, :serialized_key => "lskdfhdlfjnh;klsf")
|
||||
message = Factory.build(:status_message, :person => person)
|
||||
|
|
@ -106,10 +111,14 @@ describe 'user encryption' do
|
|||
xml = message.to_xml.to_s
|
||||
xml.include?(message.creator_signature).should be true
|
||||
end
|
||||
|
||||
it 'A message with an invalid signature should be rejected' do
|
||||
message = Factory.build(:status_message, :person => @person)
|
||||
@user2 = Factory.create :user
|
||||
|
||||
message = @user2.post :status_message, :message => "hey"
|
||||
message.creator_signature = "totally valid"
|
||||
message.save
|
||||
message.save(:validate => false)
|
||||
|
||||
xml = message.to_diaspora_xml
|
||||
message.destroy
|
||||
Post.count.should be 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue