Skip to content
Extraits de code Groupes Projets
encryptor_spec.rb 1,53 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    
    Raphael's avatar
    Raphael a validé
    #   the COPYRIGHT file.
    
    require 'spec_helper'
    
    
    describe 'user encryption' do
    
      before do
    
    Raphael's avatar
    Raphael a validé
        @user = Factory.create(:user)
    
    Raphael's avatar
    Raphael a validé
        @aspect = @user.aspect(:name => 'dudes')
    
    ilya's avatar
    ilya a validé
      describe 'key exchange on friending' do
    
    
        it 'should receive and marshal a public key from a request' do
    
          remote_user = Factory.build(:user)
          remote_user.encryption_key.nil?.should== false
    
    Raphael's avatar
    Raphael a validé
          deliverable = Object.new
          deliverable.stub!(:deliver)
          Notifier.stub!(:new_request).and_return(deliverable)
    
          Person.should_receive(:by_webfinger).and_return(remote_user.person)
    
          #should move this to friend request, but i found it here
    
          id = remote_user.person.id
    
          request = remote_user.send_friend_request_to(
    
    Raphael's avatar
    Raphael a validé
            @user.person, remote_user.aspect(:name => "temp"))
    
          xml = remote_user.salmon(request).xml_for(@user)
    
    ilya's avatar
    ilya a validé
          remote_user.person.delete
          remote_user.delete
    
          person_count = Person.all.count
    
          @user.receive_salmon xml
    
    ilya's avatar
    ilya a validé
            
    
          Person.all.count.should == person_count + 1
          new_person = Person.first(:id => id)
    
          new_person.exported_key.should == original_key
    
        end
    
    ilya's avatar
    ilya a validé
      end
    
    
    Raphael's avatar
    Raphael a validé
      describe 'encryption' do
    
          string = "Secretsauce"
          ciphertext = @user.encrypt string
          ciphertext.include?(string).should be false
          @user.decrypt(ciphertext).should == string
    
    Raphael's avatar
    Raphael a validé
        end
      end