From c629c23232136379e21e1a5e716d564255ebf13c Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 27 Aug 2010 10:05:14 -0700 Subject: [PATCH] Tests now pass, export_key changed to exported_key, profile.person changed to _parent_document --- app/models/person.rb | 20 +++++++++++--------- app/models/profile.rb | 2 +- app/models/request.rb | 4 ++-- app/models/user.rb | 1 + spec/lib/salmon_salmon_spec.rb | 4 ++-- spec/user_encryption_spec.rb | 6 +++--- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 8003e8520..8c44ca60b 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -6,7 +6,7 @@ class Person xml_accessor :email xml_accessor :url xml_accessor :profile, :as => Profile - xml_reader :serialized_key + xml_reader :exported_key key :email, String, :unique => true @@ -52,20 +52,19 @@ class Person serialized_key = new_key.export end - def serialized_key= new_key - raise "Don't change a key" if serialized_key - - @serialized_key = new_key - end - def public_key_hash - Base64.encode64 OpenSSL::Digest::SHA256.new(self.export_key).to_s + Base64.encode64 OpenSSL::Digest::SHA256.new(self.exported_key).to_s end - def export_key + def exported_key encryption_key.public_key.export end + def exported_key= new_key + raise "Don't change a key" if serialized_key + @serialized_key = new_key + end + def owns?(post) self.id == post.person.id end @@ -83,6 +82,7 @@ class Person end protected + def clean_url self.url ||= "http://localhost:3000/" if self.class == User if self.url @@ -90,7 +90,9 @@ class Person self.url = self.url + '/' if self.url[-1,1] != '/' end end + private + def remove_all_traces Post.all(:person_id => id).each{|p| p.delete} Album.all(:person_id => id).each{|p| p.delete} diff --git a/app/models/profile.rb b/app/models/profile.rb index 8ba7b4def..9bea4fdb0 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -21,7 +21,7 @@ class Profile end def person - Person.first(:id => self.person_id) + self._parent_document end ##this needs to go once we move to Salmon diff --git a/app/models/request.rb b/app/models/request.rb index 5289c757a..d8dd322e0 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -30,13 +30,13 @@ class Request self.new(:destination_url => options[:to], :callback_url => person.receive_url, :person => person, - :exported_key => person.export_key, + :exported_key => person.exported_key, :group_id => options[:into]) end def reverse_for accepting_user self.person = accepting_user.person - self.exported_key = accepting_user.export_key + self.exported_key = accepting_user.exported_key self.destination_url = self.callback_url self.save end diff --git a/app/models/user.rb b/app/models/user.rb index 072fd006e..d9c361efd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -166,6 +166,7 @@ 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 + 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? diff --git a/spec/lib/salmon_salmon_spec.rb b/spec/lib/salmon_salmon_spec.rb index 273762a41..49ffa483d 100644 --- a/spec/lib/salmon_salmon_spec.rb +++ b/spec/lib/salmon_salmon_spec.rb @@ -22,8 +22,8 @@ describe Salmon do x.magic_sig.signable_string.should == z.magic_sig.signable_string - x.verified_for_key?(OpenSSL::PKey::RSA.new(@user.export_key)).should be true - z.verified_for_key?(OpenSSL::PKey::RSA.new(@user.export_key)).should be true + x.verified_for_key?(OpenSSL::PKey::RSA.new(@user.exported_key)).should be true + z.verified_for_key?(OpenSSL::PKey::RSA.new(@user.exported_key)).should be true end diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index de21c343f..9432ac07b 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -33,7 +33,7 @@ describe 'user encryption' do it 'should send over a public key' do message_queue.stub!(:add_post_request) request = @user.send_friend_request_to("http://example.com/", @group.id) - request.to_diaspora_xml.include?( @user.export_key).should be true + request.to_diaspora_xml.include?( @user.exported_key).should be true end it 'should receive and marshal a public key from a request' do @@ -41,7 +41,7 @@ describe 'user encryption' do remote_user.encryption_key.nil?.should== false #should move this to friend request, but i found it here id = remote_user.person.id - original_key = remote_user.export_key + original_key = remote_user.exported_key request = remote_user.send_friend_request_to( @user.receive_url, remote_user.group(:name => "temp").id) @@ -55,7 +55,7 @@ describe 'user encryption' do 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 + new_person.exported_key.should == original_key end end