diff --git a/app/models/post.rb b/app/models/post.rb index ee004ce459c30c62d29ff29ff4602da8154272f9..a4d710f191650d5d63ce5a1e247f5d778c5965e8 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -46,7 +46,7 @@ class Post #ENCRYPTION before_validation :sign_if_mine - #validates_true_for :owner_signature, :logic => lambda {self.verify_signature} + validates_true_for :owner_signature, :logic => lambda {self.verify_signature} key :owner_signature, String diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cf8bb59d749c3d47444846ee20b9b7fb6bb12936..7273c0d282186a730fe9ec60379d58e04b2d53d6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,7 +12,7 @@ include Devise::TestHelpers Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |config| - + config.mock_with :mocha config.mock_with :rspec DatabaseCleaner.strategy = :truncation @@ -20,11 +20,12 @@ RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation) + stub_signature_verification end config.before(:each) do DatabaseCleaner.start - stub_sockets_controller + stub_sockets_controller end config.after(:each) do @@ -39,3 +40,15 @@ end mock_sockets_controller.stub!(:delete_subscriber).and_return(true) SocketsController.stub!(:new).and_return(mock_sockets_controller) end + + def stub_signature_verification + Post.any_instance.stubs(:verify_signature).returns(true) + StatusMessage.any_instance.stubs(:verify_signature).returns(true) + Blog.any_instance.stubs(:verify_signature).returns(true) + Bookmark.any_instance.stubs(:verify_signature).returns(true) + end + + def unstub_mocha_stubs + Mocha::Mockery.instance.stubba.unstub_all + + end diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 65d772fff5e30f5fe9739a34463d2c536966a067..905324c40e0d8c6e5bc68b584a9fb65aaa407fd5 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -9,6 +9,7 @@ describe 'user encryption' do end before do + unstub_mocha_stubs @u = Factory.create(:user) @u.send(:assign_key) @u.save @@ -22,12 +23,13 @@ describe 'user encryption' do end -# after :all do + after do + stub_signature_verification #gpgdir = File.expand_path("../../db/gpg-#{Rails.env}", __FILE__) #ctx = GPGME::Ctx.new #keys = ctx.keys #keys.each{|k| ctx.delete_key(k, true)} - #end + end 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" @@ -79,9 +81,9 @@ describe 'user encryption' do end describe 'signing and verifying' do + it 'should sign a message on create' do message = Factory.create(:status_message, :person => @u) - puts message.owner_signature message.verify_signature.should be true end @@ -126,8 +128,6 @@ describe 'user encryption' do xml.include?(message.owner_signature).should be true end it 'the signature should be verified on marshaling' do - pending "We're going to work on embeded profile" - message = Factory.build(:status_message, :person => @person) message.owner_signature = GPGME.sign(message.signable_string, nil, {:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@u.key]})