Tests now pass, export_key changed to exported_key, profile.person changed to _parent_document
This commit is contained in:
parent
ba4468f9cc
commit
c629c23232
6 changed files with 20 additions and 17 deletions
|
|
@ -6,7 +6,7 @@ class Person
|
||||||
xml_accessor :email
|
xml_accessor :email
|
||||||
xml_accessor :url
|
xml_accessor :url
|
||||||
xml_accessor :profile, :as => Profile
|
xml_accessor :profile, :as => Profile
|
||||||
xml_reader :serialized_key
|
xml_reader :exported_key
|
||||||
|
|
||||||
|
|
||||||
key :email, String, :unique => true
|
key :email, String, :unique => true
|
||||||
|
|
@ -52,20 +52,19 @@ class Person
|
||||||
serialized_key = new_key.export
|
serialized_key = new_key.export
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialized_key= new_key
|
|
||||||
raise "Don't change a key" if serialized_key
|
|
||||||
|
|
||||||
@serialized_key = new_key
|
|
||||||
end
|
|
||||||
|
|
||||||
def public_key_hash
|
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
|
end
|
||||||
|
|
||||||
def export_key
|
def exported_key
|
||||||
encryption_key.public_key.export
|
encryption_key.public_key.export
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exported_key= new_key
|
||||||
|
raise "Don't change a key" if serialized_key
|
||||||
|
@serialized_key = new_key
|
||||||
|
end
|
||||||
|
|
||||||
def owns?(post)
|
def owns?(post)
|
||||||
self.id == post.person.id
|
self.id == post.person.id
|
||||||
end
|
end
|
||||||
|
|
@ -83,6 +82,7 @@ class Person
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def clean_url
|
def clean_url
|
||||||
self.url ||= "http://localhost:3000/" if self.class == User
|
self.url ||= "http://localhost:3000/" if self.class == User
|
||||||
if self.url
|
if self.url
|
||||||
|
|
@ -90,7 +90,9 @@ class Person
|
||||||
self.url = self.url + '/' if self.url[-1,1] != '/'
|
self.url = self.url + '/' if self.url[-1,1] != '/'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def remove_all_traces
|
def remove_all_traces
|
||||||
Post.all(:person_id => id).each{|p| p.delete}
|
Post.all(:person_id => id).each{|p| p.delete}
|
||||||
Album.all(:person_id => id).each{|p| p.delete}
|
Album.all(:person_id => id).each{|p| p.delete}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class Profile
|
||||||
end
|
end
|
||||||
|
|
||||||
def person
|
def person
|
||||||
Person.first(:id => self.person_id)
|
self._parent_document
|
||||||
end
|
end
|
||||||
|
|
||||||
##this needs to go once we move to Salmon
|
##this needs to go once we move to Salmon
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,13 @@ class Request
|
||||||
self.new(:destination_url => options[:to],
|
self.new(:destination_url => options[:to],
|
||||||
:callback_url => person.receive_url,
|
:callback_url => person.receive_url,
|
||||||
:person => person,
|
:person => person,
|
||||||
:exported_key => person.export_key,
|
:exported_key => person.exported_key,
|
||||||
:group_id => options[:into])
|
:group_id => options[:into])
|
||||||
end
|
end
|
||||||
|
|
||||||
def reverse_for accepting_user
|
def reverse_for accepting_user
|
||||||
self.person = accepting_user.person
|
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.destination_url = self.callback_url
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,7 @@ class User
|
||||||
object = Diaspora::Parser.from_xml(xml)
|
object = Diaspora::Parser.from_xml(xml)
|
||||||
Rails.logger.debug("Receiving object:\n#{object.inspect}")
|
Rails.logger.debug("Receiving object:\n#{object.inspect}")
|
||||||
Rails.logger.debug("From: #{object.person.inspect}") if object.person
|
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.is_a? Retraction
|
||||||
if object.type == 'Person' && object.signature_valid?
|
if object.type == 'Person' && object.signature_valid?
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ describe Salmon do
|
||||||
x.magic_sig.signable_string.should == z.magic_sig.signable_string
|
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
|
x.verified_for_key?(OpenSSL::PKey::RSA.new(@user.exported_key)).should be true
|
||||||
z.verified_for_key?(OpenSSL::PKey::RSA.new(@user.export_key)).should be true
|
z.verified_for_key?(OpenSSL::PKey::RSA.new(@user.exported_key)).should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ describe 'user encryption' do
|
||||||
it 'should send over a public key' do
|
it 'should send over a public key' do
|
||||||
message_queue.stub!(:add_post_request)
|
message_queue.stub!(:add_post_request)
|
||||||
request = @user.send_friend_request_to("http://example.com/", @group.id)
|
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
|
end
|
||||||
|
|
||||||
it 'should receive and marshal a public key from a request' do
|
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
|
remote_user.encryption_key.nil?.should== false
|
||||||
#should move this to friend request, but i found it here
|
#should move this to friend request, but i found it here
|
||||||
id = remote_user.person.id
|
id = remote_user.person.id
|
||||||
original_key = remote_user.export_key
|
original_key = remote_user.exported_key
|
||||||
|
|
||||||
request = remote_user.send_friend_request_to(
|
request = remote_user.send_friend_request_to(
|
||||||
@user.receive_url, remote_user.group(:name => "temp").id)
|
@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/
|
proc {@user.receive xml}.should_not raise_error /ignature was not valid/
|
||||||
Person.all.count.should == person_count + 1
|
Person.all.count.should == person_count + 1
|
||||||
new_person = Person.first(:id => id)
|
new_person = Person.first(:id => id)
|
||||||
new_person.export_key.should == original_key
|
new_person.exported_key.should == original_key
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue