diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 1cd8e9b9d..9ebebab15 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -97,6 +97,10 @@ describe Comment do user.receive comment.to_diaspora_xml, user2.person end + context 'posts from a remote person' do + before(:all) do + stub_comment_signature_verification + end it 'should not send a comment a person made on his own post to anyone' do User::QUEUE.should_not_receive(:add_post_request) comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status) @@ -108,6 +112,10 @@ describe Comment do comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status) user.receive comment.to_diaspora_xml, @person end + after(:all) do + unstub_mocha_stubs + end + end it 'should not clear the aspect post array on receiving a comment' do aspect.post_ids.include?(@user_status.id).should be true diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 07b481b17..ab83b8c5d 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -115,6 +115,7 @@ describe User do comment_id = comment.id comment.delete + comment.post_creator_signature = comment.sign_with_key(user.encryption_key) user3.receive comment.to_diaspora_xml, user.person user3.reload diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 218def68b..80c863c67 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,10 +25,6 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :truncation DatabaseCleaner.orm = "mongo_mapper" - config.before(:suite) do - stub_signature_verification - end - config.before(:each) do stub_sockets DatabaseCleaner.clean @@ -49,10 +45,8 @@ ImageUploader.enable_processing = false Diaspora::WebSocket.unstub!(:unsubscribe) end - def stub_signature_verification - (get_models.map{|model| model.camelize.constantize} - [User]).each do |model| - model.any_instance.stubs(:verify_signature).returns(true) - end + def stub_comment_signature_verification + Comment.any_instance.stubs(:verify_signature).returns(true) end def unstub_mocha_stubs @@ -82,11 +76,12 @@ ImageUploader.enable_processing = false aspect2.reload end - def stub_success(address = 'abc@example.com') + def stub_success(address = 'abc@example.com', opts = {}) host = address.split('@')[1] stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) - if host.include?("joindiaspora.com") + if opts[:diaspora] || host.include?("diaspora") + puts address stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd) stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response) else diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 645563b9a..581e4f414 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -6,7 +6,6 @@ require 'spec_helper' describe 'user encryption' do before do - unstub_mocha_stubs @user = Factory.create(:user) @aspect = @user.aspect(:name => 'dudes') @@ -14,13 +13,6 @@ describe 'user encryption' do @aspect2 = @user2.aspect(:name => 'dudes') end - 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 it 'should have a key' do @user.encryption_key.should_not be nil end @@ -34,6 +26,8 @@ describe 'user encryption' 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 + + 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 original_key = remote_user.exported_key @@ -41,13 +35,13 @@ describe 'user encryption' do request = remote_user.send_friend_request_to( @user.person, remote_user.aspect(:name => "temp")) - xml = request.to_diaspora_xml + xml = remote_user.salmon(request).xml_for(@user) remote_user.person.delete remote_user.delete person_count = Person.all.count - @user.receive xml, remote_user.person + @user.receive_salmon xml Person.all.count.should == person_count + 1 new_person = Person.first(:id => id)