Merge branch 'master' of github.com:diaspora/diaspora_rails

Conflicts:
	app/models/post.rb
This commit is contained in:
danielvincent 2010-07-17 19:00:53 -07:00
commit c53efbe56f
15 changed files with 90 additions and 45 deletions

View file

@ -26,7 +26,7 @@ class RequestsController < ApplicationController
def create def create
url = diaspora_url(params[:request][:destination_url]) url = diaspora_url(params[:request][:destination_url])
@request = current_user.send_friend_request_to(url) unless url.include?('@') @request = current_user.send_friend_request_to(url) unless url.include?('@')|| url == ''
if @request if @request
flash[:notice] = "a friend request was sent to #{@request.destination_url}" flash[:notice] = "a friend request was sent to #{@request.destination_url}"
redirect_to requests_url redirect_to requests_url

View file

@ -52,6 +52,7 @@ class Comment
def verify_post_creator_signature def verify_post_creator_signature
unless person == User.owner unless person == User.owner
puts "verifying post creator sig from #{post.person.real_name}"
verify_signature(post_creator_signature, post.person) verify_signature(post_creator_signature, post.person)
else else
true true

View file

@ -1,6 +1,8 @@
class Photo < Post class Photo < Post
require 'carrierwave/orm/mongomapper' require 'carrierwave/orm/mongomapper'
include MongoMapper::Document include MongoMapper::Document
before_validation {puts "I'M GONNA VALIDATE"}
before_save {puts "I'M GONNA SAVE"}
before_create {puts "I'M GONNA CREATE"}
mount_uploader :image, ImageUploader mount_uploader :image, ImageUploader
end end

View file

@ -44,8 +44,8 @@ class Post
end end
#ENCRYPTION #ENCRYPTION
#before_validation :sign_if_mine before_validation :sign_if_mine
#validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature} validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
xml_accessor :creator_signature xml_accessor :creator_signature
key :creator_signature, String key :creator_signature, String

View file

@ -5,6 +5,5 @@
= f.label :destination_url = f.label :destination_url
= f.text_field :destination_url = f.text_field :destination_url
%p %p
= f.submit = f.submit

View file

@ -2,8 +2,8 @@
= f.error_messages = f.error_messages
%p %p
enter a diaspora url, diaspora username, or random email address:
= f.label :destination_url = f.label :destination_url
= f.text_field :destination_url = f.text_field :destination_url
%p %p
= f.submit = f.submit

View file

@ -33,7 +33,7 @@ end
package :diaspora_dependencies do package :diaspora_dependencies do
description 'random dependencies' description 'random dependencies'
apt %w(libxslt1.1 libxslt1-dev libxml2 libgpgme11-dev ) apt %w(libxslt1.1 libxslt1-dev libxml2 libgpgme11-dev imagemagick libmagick9-dev)
end end
#package :diaspora do #package :diaspora do
# description 'Diaspora' # description 'Diaspora'

View file

@ -30,6 +30,7 @@ module Diaspora
def store_objects_from_xml(xml) def store_objects_from_xml(xml)
objects = parse_objects_from_xml(xml) objects = parse_objects_from_xml(xml)
objects.each do |p| objects.each do |p|
Rails.logger.info("Receiving object:\n#{p.inspect}")
if p.is_a? Retraction if p.is_a? Retraction
p.perform p.perform
elsif p.is_a? Request elsif p.is_a? Request

View file

@ -3,30 +3,38 @@
"" ""
end end
def verify_creator_signature def verify_creator_signature
#creator_signature = sign if creator_signature.nil? && person == User.owner
verify_signature(creator_signature, person) verify_signature(creator_signature, person)
end end
def verify_signature(signature, person) def verify_signature(signature, person)
return false unless signature && person.key_fingerprint return false unless signature && person.key_fingerprint
validity = nil validity = nil
GPGME::verify(creator_signature, signable_string, GPGME::verify(signature, signable_string,
{:armor => true, :always_trust => true}){ |signature| {:armor => true, :always_trust => true}){ |signature_analysis|
validity = signature.status == GPGME::GPG_ERR_NO_ERROR && puts signature_analysis
signature.fpr == person.key_fingerprint validity = signature_analysis.status == GPGME::GPG_ERR_NO_ERROR &&
signature_analysis.fpr == person.key_fingerprint
} }
return validity return validity
end end
protected protected
def sign_if_mine def sign_if_mine
puts "In sign_if_mine"
if self.person == User.owner if self.person == User.owner
self.creator_signature = sign self.creator_signature = sign
end end
end end
def sign def sign
puts "signing"
sign_with_key(User.owner.key)
end
def sign_with_key(key)
GPGME::sign(signable_string,nil, GPGME::sign(signable_string,nil,
{:armor=> true, :mode => GPGME::SIG_MODE_DETACH, :signers => [User.owner.key]}) {:armor=> true, :mode => GPGME::SIG_MODE_DETACH, :signers => [key]})
end end
end end

View file

@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe RequestsController do describe RequestsController do
describe "profile" do describe "profile" do
it 'should fetch the public webfinger profile on request' do it 'should fetch the public webfinger profile on request' do
pending "Duplicate test"
#post :create {:request => {:destination_url => 'tom@tom.joindiaspora.com'} #post :create {:request => {:destination_url => 'tom@tom.joindiaspora.com'}
url = RequestsController.diaspora_url('http://tom.joindiaspora.com/') url = RequestsController.diaspora_url('http://tom.joindiaspora.com/')

View file

@ -5,6 +5,7 @@ include RequestsHelper
describe RequestsHelper do describe RequestsHelper do
describe "profile" do describe "profile" do
it 'should fetch the public webfinger profile on request' do it 'should fetch the public webfinger profile on request' do
pending "Can we please find a way to do this that doesn't freak me out if my internet connection is down? Thanks, Rafi"
#post :create {:request => {:destination_url => 'tom@tom.joindiaspora.com'} #post :create {:request => {:destination_url => 'tom@tom.joindiaspora.com'}
url = diaspora_url('http://tom.joindiaspora.com/') url = diaspora_url('http://tom.joindiaspora.com/')

View file

@ -128,7 +128,7 @@ describe "parser in application helper" do
it "should activate the Person if I initiated a request to that url" do it "should activate the Person if I initiated a request to that url" do
request = Request.instantiate(:to => @person.url, :from => @user).save request = Request.instantiate(:to => @person.url, :from => @user).save
request_remote = Request.new(:_id => request.id)# request_remote = Request.new
request_remote.destination_url = @user.url request_remote.destination_url = @user.url
request_remote.callback_url = @user.url request_remote.callback_url = @user.url
request_remote.person = @person request_remote.person = @person

View file

@ -1,19 +1,39 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe Photo do describe Photo do
before do
@user = Factory.create(:user)
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
end
it 'should save a photo to GridFS' do it 'should save a photo to GridFS' do
photo = Photo.new photo = Photo.new(:person => @user)
fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg' file = File.open(@fixture_name)
file = File.open(fixture_name)
photo.image = file photo.image = file
photo.save.should == true photo.save.should == true
binary = photo.image.read binary = photo.image.read
fixture_binary = File.open(fixture_name).read fixture_binary = File.open(@fixture_name).read
binary.should == fixture_binary binary.should == fixture_binary
end end
it 'should create thumbnails' do it 'should create thumbnails' do
pending('need to figure this out... tearing issue') pending('need to figure this out... tearing issue')
end end
describe 'with encryption' do
before do
unstub_mocha_stubs
end
after do
stub_signature_verification
end
it 'should save a signed photo to GridFS' do
photo = Photo.new(:person => @user)
photo.image = File.open(@fixture_name)
photo.save.should == true
photo.verify_creator_signature.should be true
end
end end
end

View file

@ -42,11 +42,18 @@ end
end end
def stub_signature_verification def stub_signature_verification
Post.any_instance.stubs(:verify_creator_signature).returns(true) post_models = []
StatusMessage.any_instance.stubs(:verify_creator_signature).returns(true) get_models.each{ |model|
Blog.any_instance.stubs(:verify_creator_signature).returns(true) constant_model = model.camelize.constantize
Bookmark.any_instance.stubs(:verify_creator_signature).returns(true) if constant_model == Post || constant_model.superclass == Post
Comment.any_instance.stubs(:verify_creator_signature).returns(true) post_models << constant_model
end
}
post_models.each{ | model|
model.any_instance.stubs(:verify_creator_signature).returns(true)
}
Comment.any_instance.stubs(:verify_post_creator_signature).returns(true) Comment.any_instance.stubs(:verify_post_creator_signature).returns(true)
Person.any_instance.stubs(:remove_key).returns(true) Person.any_instance.stubs(:remove_key).returns(true)
User.any_instance.stubs(:remove_key).returns(true) User.any_instance.stubs(:remove_key).returns(true)
@ -54,5 +61,12 @@ end
def unstub_mocha_stubs def unstub_mocha_stubs
Mocha::Mockery.instance.stubba.unstub_all Mocha::Mockery.instance.stubba.unstub_all
end
def get_models
models = []
Dir.glob( File.dirname(__FILE__) + '/../app/models/*' ).each do |f|
models << File.basename( f ).gsub( /^(.+).rb/, '\1')
end
models
end end

View file

@ -100,8 +100,7 @@ describe 'user encryption' do
it 'should verify a remote signature' do it 'should verify a remote signature' do
message = Factory.build(:status_message, :person => @person) message = Factory.build(:status_message, :person => @person)
message.creator_signature = GPGME.sign(message.signable_string, nil, message.creator_signature = message.send(:sign_with_key,@person.key)
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person.key]})
message.save(:validate => false) message.save(:validate => false)
message.verify_creator_signature.should be true message.verify_creator_signature.should be true
end end
@ -109,16 +108,14 @@ describe 'user encryption' do
it 'should know if the signature is from the wrong person' do it 'should know if the signature is from the wrong person' do
message = Factory.build(:status_message, :person => @person) message = Factory.build(:status_message, :person => @person)
message.save(:validate => false) message.save(:validate => false)
message.creator_signature = GPGME.sign(message.signable_string, nil, message.creator_signature = message.send(:sign_with_key,@person.key)
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person.key]})
message.person = @user message.person = @user
message.verify_creator_signature.should be false message.verify_creator_signature.should be false
end end
it 'should know if the signature is for the wrong text' do it 'should know if the signature is for the wrong text' do
message = Factory.build(:status_message, :person => @person) message = Factory.build(:status_message, :person => @person)
message.creator_signature = GPGME.sign(message.signable_string, nil, message.creator_signature = message.send(:sign_with_key,@person.key)
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person.key]})
message.message = 'I love VENISON' message.message = 'I love VENISON'
message.save(:validate => false) message.save(:validate => false)
message.verify_creator_signature.should be false message.verify_creator_signature.should be false
@ -133,8 +130,7 @@ describe 'user encryption' do
end end
it 'A message with an invalid signature should be rejected' do it 'A message with an invalid signature should be rejected' do
message = Factory.build(:status_message, :person => @person) message = Factory.build(:status_message, :person => @person)
message.creator_signature = GPGME.sign(message.signable_string, nil, message.creator_signature = message.send(:sign )
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@user.key]})
message.save message.save
xml = Post.build_xml_for([message]) xml = Post.build_xml_for([message])
message.destroy message.destroy
@ -147,10 +143,9 @@ describe 'user encryption' do
describe 'comments' do describe 'comments' do
before do before do
@remote_message = Factory.build(:status_message, :person => @person) @remote_message = Factory.build(:status_message, :person => @person)
@remote_message.creator_signature = GPGME.sign(@remote_message.signable_string, nil, @remote_message.creator_signature = @remote_message.send(:sign_with_key,@person.key)
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person.key]})
@remote_message.save @remote_message.save
@message = Factory.create(:status_message, :person => @user)
end end
it 'should attach the creator signature if the user is commenting' do it 'should attach the creator signature if the user is commenting' do
@user.comment "Yeah, it was great", :on => @remote_message @user.comment "Yeah, it was great", :on => @remote_message
@ -160,29 +155,32 @@ describe 'user encryption' do
it 'should sign the comment if the user is the post creator' do it 'should sign the comment if the user is the post creator' do
message = Factory.create(:status_message, :person => @user) message = Factory.create(:status_message, :person => @user)
@user.comment "Yeah, it was great", :on => message @user.comment "Yeah, it was great", :on => message
StatusMessage.first.comments.first.verify_creator_signature.should be true message.comments.first.verify_creator_signature.should be true
StatusMessage.first.comments.first.verify_post_creator_signature.should be true StatusMessage.first.comments.first.verify_post_creator_signature.should be true
end end
it 'should verify a comment made on a remote post by a different friend' do it 'should verify a comment made on a remote post by a different friend' do
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message) comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
comment.creator_signature = GPGME.sign(comment.signable_string, nil, comment.creator_signature = comment.send(:sign_with_key,@person2.key)
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person2.key]})
comment.verify_creator_signature.should be true comment.verify_creator_signature.should be true
comment.valid?.should be false
comment.post_creator_signature = comment.send(:sign_with_key,@person.key)
comment.verify_post_creator_signature.should be true
comment.valid?.should be true
end end
it 'should reject comments on a remote post with only a creator sig' do it 'should reject comments on a remote post with only a creator sig' do
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message) comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
comment.creator_signature = GPGME.sign(comment.signable_string, nil, comment.creator_signature = comment.send(:sign_with_key,@person2.key)
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person2.key]})
comment.verify_creator_signature.should be true comment.verify_creator_signature.should be true
comment.verify_post_creator_signature.should be false comment.verify_post_creator_signature.should be false
comment.save.should be false comment.save.should be false
end end
it 'should receive remote comments on a user post with a creator sig' do it 'should receive remote comments on a user post with a creator sig' do
comment = Comment.new(:person => @person2, :text => "balls", :post => @message)
comment.creator_signature = comment.send(:sign_with_key,@person2.key)
comment.save.should be true
end end
end end