comment specs fixed, comments now signed by post poster

This commit is contained in:
Raphael 2010-07-15 14:41:39 -07:00
parent 64c81f0551
commit d7e07dfda8
7 changed files with 17 additions and 11 deletions

View file

@ -29,7 +29,8 @@ class Comment
#ENCRYPTION #ENCRYPTION
before_validation :sign_if_mine, :sign_if_my_post before_validation :sign_if_mine, :sign_if_my_post
validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature} #validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
validates_true_for :post_creator_signature, :logic => lambda {self.verify_post_creator_signature}
xml_accessor :creator_signature xml_accessor :creator_signature
key :creator_signature, String key :creator_signature, String
@ -49,8 +50,12 @@ class Comment
(self.send accessor.to_sym).to_s}.join ';' (self.send accessor.to_sym).to_s}.join ';'
end end
def verify_post_creator_signature def verify_post_creator_signature
verify_signature(post_creator_signature, post.person) unless person == User.owner
verify_signature(post_creator_signature, post.person)
else
true
end
end end

View file

@ -26,7 +26,7 @@ class Person
validates_true_for :url, :logic => lambda { self.url_unique?} validates_true_for :url, :logic => lambda { self.url_unique?}
after_destroy :remove_all_traces#, :remove_key after_destroy :remove_all_traces, :remove_key
scope :friends, where(:_type => "Person", :active => true) scope :friends, where(:_type => "Person", :active => true)

Binary file not shown.

View file

@ -11,7 +11,6 @@
validity = nil validity = nil
GPGME::verify(creator_signature, signable_string, GPGME::verify(creator_signature, signable_string,
{:armor => true, :always_trust => true}){ |signature| {:armor => true, :always_trust => true}){ |signature|
puts signature
validity = signature.status == GPGME::GPG_ERR_NO_ERROR && validity = signature.status == GPGME::GPG_ERR_NO_ERROR &&
signature.fpr == person.key_fingerprint signature.fpr == person.key_fingerprint
} }

View file

@ -34,7 +34,7 @@ describe Person do
end end
it 'should delete all of user upon user deletion' do it 'should delete all of user except comments upon user deletion' do
Factory.create(:user) Factory.create(:user)
f = Factory.create(:person) f = Factory.create(:person)
@ -53,8 +53,8 @@ describe Person do
f.destroy f.destroy
Post.count.should == 1 Post.count.should == 1
Comment.all.count.should == 1 Comment.all.count.should == 4
s.comments.count.should == 1 s.comments.count.should == 4
end end
it 'should let a user unfriend another user' do it 'should let a user unfriend another user' do

View file

@ -47,6 +47,9 @@ end
Blog.any_instance.stubs(:verify_creator_signature).returns(true) Blog.any_instance.stubs(:verify_creator_signature).returns(true)
Bookmark.any_instance.stubs(:verify_creator_signature).returns(true) Bookmark.any_instance.stubs(:verify_creator_signature).returns(true)
Comment.any_instance.stubs(:verify_creator_signature).returns(true) Comment.any_instance.stubs(:verify_creator_signature).returns(true)
Comment.any_instance.stubs(:verify_post_creator_signature).returns(true)
Person.any_instance.stubs(:remove_key).returns(true)
User.any_instance.stubs(:remove_key).returns(true)
end end
def unstub_mocha_stubs def unstub_mocha_stubs

View file

@ -36,7 +36,6 @@ describe 'user encryption' do
end end
it 'should remove the key from the keyring on person destroy' do it 'should remove the key from the keyring on person destroy' do
pending "We can implement deleting from the keyring later, its annoying to test b/c no stub any instance of"
person = Factory.create :person person = Factory.create :person
keyid = person.key_fingerprint keyid = person.key_fingerprint
original_key = person.export_key original_key = person.export_key
@ -167,7 +166,7 @@ describe 'user encryption' do
it 'should verify a comment made on a remote post by a different friend' do it 'should verify a comment made on a remote post by a different friend' do
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message) comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
comment.creator_signature = GPGME.sign(@remote_message.signable_string, nil, comment.creator_signature = GPGME.sign(comment.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person2.key]}) {:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person2.key]})
comment.verify_creator_signature.should be true comment.verify_creator_signature.should be true
@ -175,7 +174,7 @@ describe 'user encryption' do
it 'should reject comments on a remote post with only a creator sig' do it 'should reject comments on a remote post with only a creator sig' do
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message) comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
comment.creator_signature = GPGME.sign(@remote_message.signable_string, nil, comment.creator_signature = GPGME.sign(comment.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person2.key]}) {:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person2.key]})
comment.verify_creator_signature.should be true comment.verify_creator_signature.should be true
comment.verify_post_creator_signature.should be false comment.verify_post_creator_signature.should be false