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

This commit is contained in:
maxwell 2010-07-17 19:22:26 -07:00
commit ec3f6e6765
22 changed files with 124 additions and 63 deletions

View file

@ -1,5 +1,5 @@
class PhotosController < ApplicationController
#before_filter :authenticate_user!
before_filter :authenticate_user!
def index
@photos = Photo.paginate :page => params[:page], :order => 'created_at DESC'
@ -7,6 +7,7 @@ class PhotosController < ApplicationController
def create
@photo = Photo.new(params[:photo])
@photo.person = current_user
if @photo.save
flash[:notice] = "Successfully uploaded photo."

View file

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

View file

@ -1,6 +1,8 @@
class Photo < Post
require 'carrierwave/orm/mongomapper'
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
end

View file

@ -36,15 +36,15 @@ class Post
self.first(:person_id => person.id, :order => '_id desc')
end
def self.my_newest
self.newest(User.owner)
end
def self.my_newest
self.newest(User.owner)
end
def self.newest_by_email(email)
self.newest(Person.first(:email => email))
end
#ENCRYPTION
before_validation :sign_if_mine
before_validation :sign_if_mine
validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
xml_accessor :creator_signature

View file

@ -1,4 +1,7 @@
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
= person_image_tag(post.person)
%span.from
= link_to_person post.person
%b wrote a new blog post
@ -7,7 +10,7 @@
%br
= raw post.body
%div.time
= link_to(how_long_ago(post), blog_path(post))
= link_to(how_long_ago(post), object_path(post))
\--
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
= render "comments/comments", :post => post

View file

@ -10,6 +10,9 @@
%strong Owner:
= @blog.person.real_name
%h4= "comments (#{@blog.comments.count})"
= render "comments/comments", :post => @blog
%p
= link_to "Edit", edit_blog_path(@blog)
|

View file

@ -1,4 +1,7 @@
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
= person_image_tag(post.person)
%span.from
= link_to_person post.person
%b shared a link
@ -8,7 +11,7 @@
%a{:href => "#{post.link}"}
= post.link
%div.time
= link_to(how_long_ago(post), bookmark_path(post))
= link_to(how_long_ago(post), object_path(post))
\--
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
= render "comments/comments", :post => post

View file

@ -10,6 +10,9 @@
%strong Owner:
= @bookmark.person.real_name
%h4= "comments (#{@bookmark.comments.count})"
= render "comments/comments", :post => @bookmark
%p
= link_to "Edit", edit_bookmark_path(@bookmark)
|

View file

@ -1,3 +1,15 @@
%li.message{:id => post.id}
= link_to (image_tag post.image.url(:small_thumb)), photo_path(post)
= person_image_tag(post.person)
%span.from
= link_to_person post.person
%b posted a new photo
%br
= link_to (image_tag post.image.url(:small_thumb)), object_path(post)
%div.time
= link_to(how_long_ago(post), status_message_path(post))
\--
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
= render "comments/comments", :post => post

View file

@ -1,8 +1,9 @@
- title "Photo"
%p
%strong Photo:
= image_tag @photo.image.url
= image_tag @photo.image.url
%h4= "comments (#{@photo.comments.count})"
= render "comments/comments", :post => @photo
%p
= link_to "Destroy", @photo, :confirm => 'Are you sure?', :method => :delete

View file

@ -1,14 +0,0 @@
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
%span.from
= link_to post.person.real_name, post.person
= auto_link post.message
%div.time
= link_to(how_long_ago(post), status_message_path(post))
\--
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
= render "comments/comments", :post => post
- if mine?(post)
.destroy_link
= link_to 'Delete', status_message_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true

View file

@ -7,7 +7,7 @@
= auto_link post.message
%div.time
= link_to(how_long_ago(post), status_message_path(post))
= link_to(how_long_ago(post), object_path(post))
\--
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
= render "comments/comments", :post => post

View file

@ -8,6 +8,9 @@
%strong Owner:
= @status_message.person.real_name
%h4= "comments (#{@status_message.comments.count})"
= render "comments/comments", :post => @status_message
%p
= link_to "Destroy", @status_message, :confirm => 'Are you sure?', :method => :delete
|

View file

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

View file

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

View file

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

View file

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

View file

@ -5,6 +5,7 @@ include RequestsHelper
describe RequestsHelper do
describe "profile" 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'}
url = diaspora_url('http://tom.joindiaspora.com/')

View file

@ -127,8 +127,8 @@ describe "parser in application helper" 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_remote = Request.new(:_id => request.id)#
request_remote = Request.new
request_remote.destination_url = @user.url
request_remote.callback_url = @user.url
request_remote.person = @person

View file

@ -1,19 +1,39 @@
require File.dirname(__FILE__) + '/../spec_helper'
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
photo = Photo.new
fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
file = File.open(fixture_name)
photo = Photo.new(:person => @user)
file = File.open(@fixture_name)
photo.image = file
photo.save.should == true
binary = photo.image.read
fixture_binary = File.open(fixture_name).read
fixture_binary = File.open(@fixture_name).read
binary.should == fixture_binary
end
it 'should create thumbnails' do
pending('need to figure this out... tearing issue')
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

View file

@ -42,11 +42,18 @@ end
end
def stub_signature_verification
Post.any_instance.stubs(:verify_creator_signature).returns(true)
StatusMessage.any_instance.stubs(:verify_creator_signature).returns(true)
Blog.any_instance.stubs(:verify_creator_signature).returns(true)
Bookmark.any_instance.stubs(:verify_creator_signature).returns(true)
Comment.any_instance.stubs(:verify_creator_signature).returns(true)
post_models = []
get_models.each{ |model|
constant_model = model.camelize.constantize
if constant_model == Post || constant_model.superclass == Post
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)
Person.any_instance.stubs(:remove_key).returns(true)
User.any_instance.stubs(:remove_key).returns(true)
@ -54,5 +61,12 @@ end
def unstub_mocha_stubs
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

View file

@ -100,8 +100,7 @@ describe 'user encryption' do
it 'should verify a remote signature' do
message = Factory.build(:status_message, :person => @person)
message.creator_signature = GPGME.sign(message.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person.key]})
message.creator_signature = message.send(:sign_with_key,@person.key)
message.save(:validate => false)
message.verify_creator_signature.should be true
end
@ -109,16 +108,14 @@ describe 'user encryption' do
it 'should know if the signature is from the wrong person' do
message = Factory.build(:status_message, :person => @person)
message.save(:validate => false)
message.creator_signature = GPGME.sign(message.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person.key]})
message.creator_signature = message.send(:sign_with_key,@person.key)
message.person = @user
message.verify_creator_signature.should be false
end
it 'should know if the signature is for the wrong text' do
message = Factory.build(:status_message, :person => @person)
message.creator_signature = GPGME.sign(message.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person.key]})
message.creator_signature = message.send(:sign_with_key,@person.key)
message.message = 'I love VENISON'
message.save(:validate => false)
message.verify_creator_signature.should be false
@ -133,8 +130,7 @@ describe 'user encryption' do
end
it 'A message with an invalid signature should be rejected' do
message = Factory.build(:status_message, :person => @person)
message.creator_signature = GPGME.sign(message.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@user.key]})
message.creator_signature = message.send(:sign )
message.save
xml = Post.build_xml_for([message])
message.destroy
@ -147,10 +143,9 @@ describe 'user encryption' do
describe 'comments' do
before do
@remote_message = Factory.build(:status_message, :person => @person)
@remote_message.creator_signature = GPGME.sign(@remote_message.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person.key]})
@remote_message.creator_signature = @remote_message.send(:sign_with_key,@person.key)
@remote_message.save
@message = Factory.create(:status_message, :person => @user)
end
it 'should attach the creator signature if the user is commenting' do
@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
message = Factory.create(:status_message, :person => @user)
@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
end
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.creator_signature = GPGME.sign(comment.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person2.key]})
comment.creator_signature = comment.send(:sign_with_key,@person2.key)
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
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.creator_signature = GPGME.sign(comment.signable_string, nil,
{:mode => GPGME::SIG_MODE_DETACH, :armor => true, :signers => [@person2.key]})
comment.creator_signature = comment.send(:sign_with_key,@person2.key)
comment.verify_creator_signature.should be true
comment.verify_post_creator_signature.should be false
comment.save.should be false
end
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