RS, IZ; Signature Verification now stubbed out outside of encryption specs, green

This commit is contained in:
Raphael 2010-07-14 11:01:21 -07:00
parent 4a0bd5fc0c
commit f680c4b71e
3 changed files with 21 additions and 8 deletions

View file

@ -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

View file

@ -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,6 +20,7 @@ RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
stub_signature_verification
end
config.before(: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

View file

@ -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]})