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 #ENCRYPTION
before_validation :sign_if_mine 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 key :owner_signature, String

View file

@ -12,7 +12,7 @@ include Devise::TestHelpers
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config| RSpec.configure do |config|
config.mock_with :mocha
config.mock_with :rspec config.mock_with :rspec
DatabaseCleaner.strategy = :truncation DatabaseCleaner.strategy = :truncation
@ -20,11 +20,12 @@ RSpec.configure do |config|
config.before(:suite) do config.before(:suite) do
DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.clean_with(:truncation)
stub_signature_verification
end end
config.before(:each) do config.before(:each) do
DatabaseCleaner.start DatabaseCleaner.start
stub_sockets_controller stub_sockets_controller
end end
config.after(:each) do config.after(:each) do
@ -39,3 +40,15 @@ end
mock_sockets_controller.stub!(:delete_subscriber).and_return(true) mock_sockets_controller.stub!(:delete_subscriber).and_return(true)
SocketsController.stub!(:new).and_return(mock_sockets_controller) SocketsController.stub!(:new).and_return(mock_sockets_controller)
end 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 end
before do before do
unstub_mocha_stubs
@u = Factory.create(:user) @u = Factory.create(:user)
@u.send(:assign_key) @u.send(:assign_key)
@u.save @u.save
@ -22,12 +23,13 @@ describe 'user encryption' do
end end
# after :all do after do
stub_signature_verification
#gpgdir = File.expand_path("../../db/gpg-#{Rails.env}", __FILE__) #gpgdir = File.expand_path("../../db/gpg-#{Rails.env}", __FILE__)
#ctx = GPGME::Ctx.new #ctx = GPGME::Ctx.new
#keys = ctx.keys #keys = ctx.keys
#keys.each{|k| ctx.delete_key(k, true)} #keys.each{|k| ctx.delete_key(k, true)}
#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" 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 end
describe 'signing and verifying' do describe 'signing and verifying' do
it 'should sign a message on create' do it 'should sign a message on create' do
message = Factory.create(:status_message, :person => @u) message = Factory.create(:status_message, :person => @u)
puts message.owner_signature
message.verify_signature.should be true message.verify_signature.should be true
end end
@ -126,8 +128,6 @@ describe 'user encryption' do
xml.include?(message.owner_signature).should be true xml.include?(message.owner_signature).should be true
end end
it 'the signature should be verified on marshaling' do 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 = Factory.build(:status_message, :person => @person)
message.owner_signature = GPGME.sign(message.signable_string, nil, message.owner_signature = GPGME.sign(message.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@u.key]}) {:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@u.key]})