Move comment signing spec to comment spec, make encryption spec not depend on message building
This commit is contained in:
parent
d8bbe38019
commit
7dd86b3c87
2 changed files with 51 additions and 53 deletions
|
|
@ -8,9 +8,6 @@ describe 'user encryption' do
|
|||
before do
|
||||
@user = Factory.create(:user)
|
||||
@aspect = @user.aspect(:name => 'dudes')
|
||||
|
||||
@user2 = Factory.create(:user)
|
||||
@aspect2 = @user2.aspect(:name => 'dudes')
|
||||
end
|
||||
|
||||
describe 'key exchange on friending' do
|
||||
|
|
@ -46,57 +43,12 @@ describe 'user encryption' do
|
|||
|
||||
describe 'encryption' do
|
||||
before do
|
||||
@message = @user.post :status_message, :message => "hi", :to => @aspect.id
|
||||
@string = File.open(File.dirname(__FILE__) + '/../fixtures/fb_status').read
|
||||
end
|
||||
it 'should encrypt large messages' do
|
||||
ciphertext = @user.encrypt @message.to_diaspora_xml
|
||||
ciphertext.include?(@message.to_diaspora_xml).should be false
|
||||
@user.decrypt(ciphertext).include?(@message.to_diaspora_xml).should be true
|
||||
it 'should encrypt a string' do
|
||||
ciphertext = @user.encrypt @string
|
||||
ciphertext.include?(@string).should be false
|
||||
@user.decrypt(ciphertext).should == @string
|
||||
end
|
||||
end
|
||||
|
||||
describe 'comments' do
|
||||
before do
|
||||
friend_users(@user, @aspect, @user2, @aspect2)
|
||||
@remote_message = @user2.post :status_message, :message => "hello", :to => @aspect2.id
|
||||
|
||||
|
||||
@message = @user.post :status_message, :message => "hi", :to => @aspect.id
|
||||
end
|
||||
it 'should attach the creator signature if the user is commenting' do
|
||||
@user.comment "Yeah, it was great", :on => @remote_message
|
||||
@remote_message.comments.first.signature_valid?.should be true
|
||||
end
|
||||
|
||||
it 'should sign the comment if the user is the post creator' do
|
||||
message = @user.post :status_message, :message => "hi", :to => @aspect.id
|
||||
@user.comment "Yeah, it was great", :on => message
|
||||
message.comments.first.signature_valid?.should be true
|
||||
message.comments.first.verify_post_creator_signature.should be true
|
||||
end
|
||||
|
||||
it 'should verify a comment made on a remote post by a different friend' do
|
||||
comment = Comment.new(:person => @user2.person, :text => "cats", :post => @remote_message)
|
||||
comment.creator_signature = comment.send(:sign_with_key,@user2.encryption_key)
|
||||
comment.signature_valid?.should be true
|
||||
comment.verify_post_creator_signature.should be false
|
||||
comment.post_creator_signature = comment.send(:sign_with_key,@user.encryption_key)
|
||||
comment.verify_post_creator_signature.should be true
|
||||
end
|
||||
|
||||
it 'should reject comments on a remote post with only a creator sig' do
|
||||
comment = Comment.new(:person => @user2.person, :text => "cats", :post => @remote_message)
|
||||
comment.creator_signature = comment.send(:sign_with_key,@user2.encryption_key)
|
||||
comment.signature_valid?.should be true
|
||||
comment.verify_post_creator_signature.should be false
|
||||
end
|
||||
|
||||
it 'should receive remote comments on a user post with a creator sig' do
|
||||
comment = Comment.new(:person => @user2.person, :text => "cats", :post => @message)
|
||||
comment.creator_signature = comment.send(:sign_with_key,@user2.encryption_key)
|
||||
comment.signature_valid?.should be true
|
||||
comment.verify_post_creator_signature.should be false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -138,4 +138,50 @@ describe Comment do
|
|||
comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'comments' do
|
||||
before do
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
@remote_message = user2.post :status_message, :message => "hello", :to => aspect2.id
|
||||
|
||||
|
||||
@message = user.post :status_message, :message => "hi", :to => aspect.id
|
||||
end
|
||||
it 'should attach the creator signature if the user is commenting' do
|
||||
user.comment "Yeah, it was great", :on => @remote_message
|
||||
@remote_message.comments.first.signature_valid?.should be true
|
||||
end
|
||||
|
||||
it 'should sign the comment if the user is the post creator' do
|
||||
message = user.post :status_message, :message => "hi", :to => aspect.id
|
||||
user.comment "Yeah, it was great", :on => message
|
||||
message.comments.first.signature_valid?.should be true
|
||||
message.comments.first.verify_post_creator_signature.should be true
|
||||
end
|
||||
|
||||
it 'should verify a comment made on a remote post by a different friend' do
|
||||
comment = Comment.new(:person => user2.person, :text => "cats", :post => @remote_message)
|
||||
comment.creator_signature = comment.send(:sign_with_key,user2.encryption_key)
|
||||
comment.signature_valid?.should be true
|
||||
comment.verify_post_creator_signature.should be false
|
||||
comment.post_creator_signature = comment.send(:sign_with_key,user.encryption_key)
|
||||
comment.verify_post_creator_signature.should be true
|
||||
end
|
||||
|
||||
it 'should reject comments on a remote post with only a creator sig' do
|
||||
comment = Comment.new(:person => user2.person, :text => "cats", :post => @remote_message)
|
||||
comment.creator_signature = comment.send(:sign_with_key,user2.encryption_key)
|
||||
comment.signature_valid?.should be true
|
||||
comment.verify_post_creator_signature.should be false
|
||||
end
|
||||
|
||||
it 'should receive remote comments on a user post with a creator sig' do
|
||||
comment = Comment.new(:person => user2.person, :text => "cats", :post => @message)
|
||||
comment.creator_signature = comment.send(:sign_with_key,user2.encryption_key)
|
||||
comment.signature_valid?.should be true
|
||||
comment.verify_post_creator_signature.should be false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue