Added the Key Fingerprint validation to the person model(defaults to empty string)

This commit is contained in:
ilya 2010-07-10 06:09:53 -04:00
parent 7eba033c0d
commit 1bed575b90
7 changed files with 37 additions and 7 deletions

View file

@ -6,11 +6,12 @@ class Person
xml_accessor :url
xml_accessor :profile, :as => Profile
xml_accessor :_id
xml_accessor :key_fingerprint
key :email, String
key :url, String
key :active, Boolean, :default => false
key :key_fingerprint, String
key :key_fingerprint, String, :default => ""
one :profile, :class_name => 'Profile', :foreign_key => :person_id
many :posts, :class_name => 'Post', :foreign_key => :person_id
@ -18,7 +19,7 @@ class Person
timestamps!
before_validation :clean_url
validates_presence_of :email, :url
validates_presence_of :email, :url, :key_fingerprint
validates_format_of :url, :with =>
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
@ -36,7 +37,10 @@ class Person
def key
GPGME::Ctx.new.get_key key_fingerprint
end
def export_key
GPGME::export(key_fingerprint, :armor => true)
end
protected

View file

@ -8,10 +8,12 @@ class Request
xml_accessor :person, :as => Person
xml_accessor :destination_url
xml_accessor :callback_url
xml_accessor :exported_key, :cdata => true
key :destination_url, String
key :callback_url, String
key :person_id, ObjectId
key :exported_key, String
belongs_to :person
@ -22,7 +24,7 @@ class Request
def self.instantiate(options ={})
person = options[:from]
self.new(:destination_url => options[:to], :callback_url => person.url, :person => person)
self.new(:destination_url => options[:to], :callback_url => person.url, :person => person, :exported_key => person.export_key)
end
def activate_friend

View file

@ -57,6 +57,7 @@ class User < Person
friend_request.activate_friend
friend_request.destroy
else
friend_request.person.save
friend_request.save
end
end

Binary file not shown.

View file

@ -10,8 +10,9 @@ Factory.define :profile do |p|
end
Factory.define :person do |p|
p.email "bob@aol.com"
p.email "bob-person@aol.com"
p.sequence(:url) {|n|"http://google-#{n}.com/"}
p.key_fingerprint GPGME::list_keys("Aditi").first.subkeys.first.fingerprint
p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" )
end
@ -20,6 +21,7 @@ Factory.define :user do |u|
u.password "bluepin7"
u.password_confirmation "bluepin7"
u.url "www.example.com/"
u.key_fingerprint GPGME.list_keys(nil, true).first.subkeys.first.fingerprint
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
end

View file

@ -11,7 +11,7 @@ describe Request do
end
it 'should generate xml for the User as a Person' do
user = User.create(:email => "rob@bob.com")
user = Factory.build(:user, :email => "rob@bob.com")
user.profile = Factory.create(:profile)

View file

@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/spec_helper'
include ApplicationHelper
describe 'user encryption' do
before :all do
@ -28,7 +29,27 @@ describe 'user encryption' do
end
describe 'key exchange on friending' do
it 'should send over a public key' do
Comment.send(:class_variable_get, :@@queue).stub!(:add_post_request)
request = @u.send_friend_request_to("http://example.com/")
Request.build_xml_for([request]).include?( @u.export_key).should be true
end
it 'should receive and marshal a public key from a request' do
person = Factory.build(:person, :url => "http://test.url/" )
original_key = person.export_key
request = Request.instantiate(:to =>"http://www.google.com/", :from => person)
xml = Request.build_xml_for [request]
puts xml
person.destroy
store_objects_from_xml(xml)
new_person = Person.first(:url => "http://test.url/")
new_person.export_key.should == original_key
end
end
describe 'signing and verifying' do