remove more unused code and cleanup

This commit is contained in:
Benjamin Neff 2016-06-14 03:29:16 +02:00
parent 2476b74dbe
commit 03123f1c4d
32 changed files with 71 additions and 528 deletions

View file

@ -25,7 +25,7 @@ class PostsController < ApplicationController
render locals: {post: post} render locals: {post: post}
} }
format.mobile { render locals: {post: post} } format.mobile { render locals: {post: post} }
format.xml { render xml: Diaspora::Federation.xml(Diaspora::Federation::Entities.post(post)) } format.xml { render xml: DiasporaFederation::Salmon::XmlPayload.pack(Diaspora::Federation::Entities.post(post)) }
format.json { render json: PostPresenter.new(post, current_user) } format.json { render json: PostPresenter.new(post, current_user) }
end end
end end

View file

@ -18,9 +18,11 @@ class Comment < ActiveRecord::Base
belongs_to :commentable, :touch => true, :polymorphic => true belongs_to :commentable, :touch => true, :polymorphic => true
alias_attribute :post, :commentable alias_attribute :post, :commentable
belongs_to :author, :class_name => 'Person' alias_attribute :parent, :commentable
belongs_to :author, class_name: "Person"
delegate :name, to: :author, prefix: true delegate :name, to: :author, prefix: true
delegate :diaspora_handle, to: :author
delegate :comment_email_subject, to: :parent delegate :comment_email_subject, to: :parent
delegate :author_name, to: :parent, prefix: true delegate :author_name, to: :parent, prefix: true
@ -36,10 +38,6 @@ class Comment < ActiveRecord::Base
self.text.strip! unless self.text.nil? self.text.strip! unless self.text.nil?
end end
after_save do
self.post.touch
end
after_commit :on => :create do after_commit :on => :create do
self.parent.update_comments_counter self.parent.update_comments_counter
end end
@ -50,26 +48,10 @@ class Comment < ActiveRecord::Base
participation.unparticipate! if participation.present? participation.unparticipate! if participation.present?
end end
def diaspora_handle def diaspora_handle=(nh)
self.author.diaspora_handle
end
def diaspora_handle= nh
self.author = Person.find_or_fetch_by_identifier(nh) self.author = Person.find_or_fetch_by_identifier(nh)
end end
def parent_class
Post
end
def parent
self.post
end
def parent= parent
self.post = parent
end
def message def message
@message ||= Diaspora::MessageRenderer.new text @message ||= Diaspora::MessageRenderer.new text
end end
@ -85,7 +67,6 @@ class Comment < ActiveRecord::Base
def initialize(person, target, text) def initialize(person, target, text)
@text = text @text = text
@dispatcher_opts = {additional_subscribers: target.comments_authors.where.not(id: person.id)}
super(person, target) super(person, target)
end end

View file

@ -6,7 +6,8 @@ class Conversation < ActiveRecord::Base
has_many :participants, :class_name => 'Person', :through => :conversation_visibilities, :source => :person has_many :participants, :class_name => 'Person', :through => :conversation_visibilities, :source => :person
has_many :messages, -> { order('created_at ASC') } has_many :messages, -> { order('created_at ASC') }
belongs_to :author, :class_name => 'Person' belongs_to :author, class_name: "Person"
delegate :diaspora_handle, to: :author
validate :max_participants validate :max_participants
validate :local_recipients validate :local_recipients
@ -32,11 +33,7 @@ class Conversation < ActiveRecord::Base
self.participants - [self.author] self.participants - [self.author]
end end
def diaspora_handle def diaspora_handle=(nh)
self.author.diaspora_handle
end
def diaspora_handle= nh
self.author = Person.find_or_fetch_by_identifier(nh) self.author = Person.find_or_fetch_by_identifier(nh)
end end
@ -58,10 +55,11 @@ class Conversation < ActiveRecord::Base
end end
def participant_handles def participant_handles
self.participants.map{|p| p.diaspora_handle}.join(";") participants.map(&:diaspora_handle).join(";")
end end
def participant_handles= handles
handles.split(';').each do |handle| def participant_handles=(handles)
handles.split(";").each do |handle|
participants << Person.find_or_fetch_by_identifier(handle) participants << Person.find_or_fetch_by_identifier(handle)
end end
end end

View file

@ -1,55 +1,29 @@
class NotVisibleError < RuntimeError; end
class Message < ActiveRecord::Base class Message < ActiveRecord::Base
include Diaspora::Federated::Base include Diaspora::Federated::Base
include Diaspora::Guid include Diaspora::Guid
include Diaspora::Relayable include Diaspora::Relayable
belongs_to :author, :class_name => 'Person' belongs_to :author, class_name: "Person"
belongs_to :conversation, :touch => true belongs_to :conversation, touch: true
delegate :diaspora_handle, to: :author
delegate :name, to: :author, prefix: true delegate :name, to: :author, prefix: true
alias_attribute :parent, :conversation
validates :text, :presence => true validates :text, :presence => true
validate :participant_of_parent_conversation validate :participant_of_parent_conversation
after_create do # don't use 'after_commit' here since there is a call to 'save!' def diaspora_handle=(nh)
# inside, which would cause an infinite recursion
#sign comment as commenter
self.author_signature = self.sign_with_key(self.author.owner.encryption_key) if self.author.owner
self.save!
self
end
def diaspora_handle
self.author.diaspora_handle
end
def diaspora_handle= nh
self.author = Person.find_or_fetch_by_identifier(nh) self.author = Person.find_or_fetch_by_identifier(nh)
end end
def conversation_guid def conversation_guid=(guid)
self.conversation.guid
end
def conversation_guid= guid
if cnv = Conversation.find_by_guid(guid) if cnv = Conversation.find_by_guid(guid)
self.conversation_id = cnv.id self.conversation_id = cnv.id
end end
end end
def parent_class
Conversation
end
def parent
self.conversation
end
def parent= parent
self.conversation = parent
end
def increase_unread(user) def increase_unread(user)
if vis = ConversationVisibility.where(:conversation_id => self.conversation_id, :person_id => user.person.id).first if vis = ConversationVisibility.where(:conversation_id => self.conversation_id, :person_id => user.person.id).first
vis.unread += 1 vis.unread += 1
@ -62,8 +36,9 @@ class Message < ActiveRecord::Base
end end
private private
def participant_of_parent_conversation def participant_of_parent_conversation
if self.parent && !self.parent.participants.include?(self.author) if conversation && !conversation.participants.include?(author)
errors[:base] << "Author is not participating in the conversation" errors[:base] << "Author is not participating in the conversation"
else else
true true

View file

@ -3,7 +3,6 @@
# the COPYRIGHT file. # the COPYRIGHT file.
class Person < ActiveRecord::Base class Person < ActiveRecord::Base
include Encryptor::Public
include Diaspora::Guid include Diaspora::Guid
# NOTE API V1 to be extracted # NOTE API V1 to be extracted

View file

@ -6,35 +6,20 @@ class PollParticipation < ActiveRecord::Base
belongs_to :poll belongs_to :poll
belongs_to :poll_answer, counter_cache: :vote_count belongs_to :poll_answer, counter_cache: :vote_count
belongs_to :author, :class_name => 'Person', :foreign_key => :author_id belongs_to :author, class_name: "Person"
delegate :diaspora_handle, to: :author
alias_attribute :parent, :poll
validates :poll_answer, presence: true
validate :not_already_participated validate :not_already_participated
def parent_class def poll_answer_guid=(new_poll_answer_guid)
Poll self.poll_answer_id = PollAnswer.where(guid: new_poll_answer_guid).ids.first
end end
def parent def diaspora_handle=(nh)
self.poll
end
def poll_answer_guid
poll_answer.guid
end
def poll_answer_guid= new_poll_answer_guid
self.poll_answer = PollAnswer.where(:guid => new_poll_answer_guid).first
end
def parent= parent
self.poll = parent
end
def diaspora_handle
self.author.diaspora_handle
end
def diaspora_handle= nh
self.author = Person.find_or_fetch_by_identifier(nh) self.author = Person.find_or_fetch_by_identifier(nh)
end end

View file

@ -3,7 +3,6 @@
# the COPYRIGHT file. # the COPYRIGHT file.
class User < ActiveRecord::Base class User < ActiveRecord::Base
include Encryptor::Private
include Connecting include Connecting
include Querying include Querying
include SocialActions include SocialActions

View file

@ -29,10 +29,6 @@ module User::SocialActions
end end
end end
def build_comment(options={})
Comment::Generator.new(self, options.delete(:post), options.delete(:text)).build(options)
end
def build_conversation(opts={}) def build_conversation(opts={})
Conversation.new do |c| Conversation.new do |c|
c.author = self.person c.author = self.person

View file

@ -6,28 +6,8 @@ module Workers
class Base class Base
include Sidekiq::Worker include Sidekiq::Worker
sidekiq_options backtrace: (bt = AppConfig.environment.sidekiq.backtrace.get) && bt.to_i, sidekiq_options backtrace: (bt = AppConfig.environment.sidekiq.backtrace.get) && bt.to_i,
retry: (rt = AppConfig.environment.sidekiq.retry.get) && rt.to_i retry: (rt = AppConfig.environment.sidekiq.retry.get) && rt.to_i
include Diaspora::Logging include Diaspora::Logging
# In the long term we need to eliminate the cause of these
def suppress_annoying_errors(&block)
yield
rescue Diaspora::ContactRequiredUnlessRequest,
Diaspora::RelayableObjectWithoutParent,
# Friendica seems to provoke these
Diaspora::AuthorXMLAuthorMismatch,
# We received a private object to our public endpoint, again something
# Friendica seems to provoke
Diaspora::NonPublic,
Diaspora::XMLNotParseable => e
logger.warn "error on receive: #{e.class}"
rescue ActiveRecord::RecordInvalid => e
logger.warn "failed to save received object: #{e.record.errors.full_messages}"
raise e unless [
"already been taken",
"is ignored by the post author"
].any? {|reason| e.message.include? reason }
end
end end
end end

View file

@ -14,32 +14,5 @@ module Workers
Diaspora::Federation::Dispatcher.build(user, object, opts).dispatch Diaspora::Federation::Dispatcher.build(user, object, opts).dispatch
rescue ActiveRecord::RecordNotFound # The target got deleted before the job was run rescue ActiveRecord::RecordNotFound # The target got deleted before the job was run
end end
def add_additional_subscribers(object, object_class_name, opts)
if AppConfig.relay.outbound.send? &&
object_class_name == "StatusMessage" &&
object.respond_to?(:public?) && object.public?
handle_relay(opts)
end
if opts[:additional_subscribers].present?
opts[:additional_subscribers] = Person.where(id: opts[:additional_subscribers])
end
end
def handle_relay(opts)
relay_person = Person.find_by diaspora_handle: AppConfig.relay.outbound.handle.to_s
if relay_person
add_person_to_subscribers(opts, relay_person)
else
# Skip this message for relay and just queue a webfinger fetch for the relay handle
Workers::FetchWebfinger.perform_async(AppConfig.relay.outbound.handle)
end
end
def add_person_to_subscribers(opts, person)
opts[:additional_subscribers] ||= []
opts[:additional_subscribers] << person.id
end
end end
end end

View file

@ -1,46 +0,0 @@
module Diaspora
module Encryptable
include Diaspora::Logging
# Check that signature is a correct signature of #signable_string by person
#
# @param [String] signature The signature to be verified.
# @param [Person] person The signer.
# @return [Boolean]
def verify_signature(signature, person)
if person.nil?
logger.warn "event=verify_signature status=abort reason=no_person guid=#{guid}"
return false
elsif person.public_key.nil?
logger.warn "event=verify_signature status=abort reason=no_key guid=#{guid}"
return false
elsif signature.nil?
logger.warn "event=verify_signature status=abort reason=no_signature guid=#{guid}"
return false
end
validity = person.public_key.verify OpenSSL::Digest::SHA256.new, Base64.decode64(signature), signable_string
logger.info "event=verify_signature status=complete guid=#{guid} validity=#{validity}"
validity
end
# @param [OpenSSL::PKey::RSA] key An RSA key
# @return [String] A Base64 encoded signature of #signable_string with key
def sign_with_key(key)
sig = Base64.strict_encode64(key.sign( OpenSSL::Digest::SHA256.new, signable_string ))
logger.info "event=sign_with_key status=complete guid=#{guid}"
sig
end
# @return [Array<String>] The ROXML attrs other than author_signature and parent_author_signature.
def signable_accessors
[]
end
# @return [String] Defaults to the ROXML attrs which are not signatures.
def signable_string
signable_accessors.collect{ |accessor|
(self.send accessor.to_sym).to_s
}.join(';')
end
end
end

View file

@ -16,26 +16,4 @@ module Diaspora
# that prevents further execution # that prevents further execution
class NotMine < StandardError class NotMine < StandardError
end end
# Received a message without having a contact
class ContactRequiredUnlessRequest < StandardError
end
# Got a relayable (comment, like etc.) without having the parent
class RelayableObjectWithoutParent < StandardError
end
# After building an object the author doesn't match the one in the
# original XML message
class AuthorXMLAuthorMismatch < StandardError
end
# Tried to fetch a post but it was deleted, not valid
# or the remote end doesn't support post fetching
class PostNotFetchable < StandardError
end
# Error while parsing an received message and got nil
class XMLNotParseable < StandardError
end
end end

View file

@ -1,10 +1,5 @@
module Diaspora module Diaspora
module Federation module Federation
# @deprecated
def self.xml(entity)
DiasporaFederation::Salmon::XmlPayload.pack(entity)
end
# Raised, if author is ignored by the relayable parent author # Raised, if author is ignored by the relayable parent author
class AuthorIgnored < RuntimeError class AuthorIgnored < RuntimeError
end end

View file

@ -53,9 +53,9 @@ module Diaspora
DiasporaFederation::Entities::Comment.new( DiasporaFederation::Entities::Comment.new(
author: comment.diaspora_handle, author: comment.diaspora_handle,
guid: comment.guid, guid: comment.guid,
parent_guid: comment.parent_guid, parent_guid: comment.post.guid,
text: comment.text, text: comment.text,
parent: related_entity(comment.parent) parent: related_entity(comment.post)
) )
end end
@ -82,10 +82,10 @@ module Diaspora
DiasporaFederation::Entities::Like.new( DiasporaFederation::Entities::Like.new(
author: like.diaspora_handle, author: like.diaspora_handle,
guid: like.guid, guid: like.guid,
parent_guid: like.parent_guid, parent_guid: like.target.guid,
positive: like.positive, positive: like.positive,
parent_type: like.parent.class.base_class.to_s, parent_type: like.target.class.base_class.to_s,
parent: related_entity(like.parent) parent: related_entity(like.target)
) )
end end
@ -103,9 +103,9 @@ module Diaspora
guid: message.guid, guid: message.guid,
text: message.text, text: message.text,
created_at: message.created_at, created_at: message.created_at,
parent_guid: message.parent_guid, parent_guid: message.conversation.guid,
conversation_guid: message.parent_guid, conversation_guid: message.conversation.guid,
parent: related_entity(message.parent) parent: related_entity(message.conversation)
) )
end end
@ -113,9 +113,9 @@ module Diaspora
DiasporaFederation::Entities::Participation.new( DiasporaFederation::Entities::Participation.new(
author: participation.diaspora_handle, author: participation.diaspora_handle,
guid: participation.guid, guid: participation.guid,
parent_guid: participation.parent_guid, parent_guid: participation.target.guid,
parent_type: participation.parent.class.base_class.to_s, parent_type: participation.target.class.base_class.to_s,
parent: related_entity(participation.parent) parent: related_entity(participation.target)
) )
end end
@ -153,9 +153,9 @@ module Diaspora
DiasporaFederation::Entities::PollParticipation.new( DiasporaFederation::Entities::PollParticipation.new(
author: poll_participation.diaspora_handle, author: poll_participation.diaspora_handle,
guid: poll_participation.guid, guid: poll_participation.guid,
parent_guid: poll_participation.parent_guid, parent_guid: poll_participation.poll.guid,
poll_answer_guid: poll_participation.poll_answer.guid, poll_answer_guid: poll_participation.poll_answer.guid,
parent: related_entity(poll_participation.parent) parent: related_entity(poll_participation.poll)
) )
end end

View file

@ -4,12 +4,8 @@
module Diaspora module Diaspora
module Relayable module Relayable
include Encryptable
def self.included(model) def self.included(model)
model.class_eval do model.class_eval do
attr_writer :parent_author_signature
validates_associated :parent validates_associated :parent
validates :author, :presence => true validates :author, :presence => true
validate :author_is_not_ignored validate :author_is_not_ignored
@ -20,7 +16,6 @@ module Diaspora
after_commit :on => :create do after_commit :on => :create do
parent.touch(:interacted_at) if parent.respond_to?(:interacted_at) parent.touch(:interacted_at) if parent.respond_to?(:interacted_at)
end end
end end
end end
@ -33,22 +28,6 @@ module Diaspora
errors.add(:author_id, "This relayable author is ignored by the post author") errors.add(:author_id, "This relayable author is ignored by the post author")
end end
# @return [Boolean] true
def relayable?
true
end
# @return [String]
def parent_guid
return nil unless parent.present?
self.parent.guid
end
def parent_guid= new_parent_guid
@parent_guid = new_parent_guid
self.parent = parent_class.where(guid: new_parent_guid).first
end
# @return [Array<Person>] # @return [Array<Person>]
def subscribers def subscribers
if parent.author.local? if parent.author.local?
@ -58,44 +37,9 @@ module Diaspora
end end
end end
def initialize_signatures
#sign relayable as model creator
self.author_signature = self.sign_with_key(author.owner.encryption_key)
end
def parent_author_signature
unless parent.blank? || parent.author.owner.nil?
@parent_author_signature = sign_with_key(parent.author.owner.encryption_key)
end
@parent_author_signature
end
# @return [Boolean]
def verify_parent_author_signature
verify_signature(self.parent_author_signature, self.parent.author)
end
# @return [Boolean]
def signature_valid?
verify_signature(self.author_signature, self.author)
end
# @abstract # @abstract
# @return [Class]
def parent_class
raise NotImplementedError.new('you must override parent_class in order to enable relayable on this model')
end
# @abstract
# @return An instance of Relayable#parent_class
def parent def parent
raise NotImplementedError.new('you must override parent in order to enable relayable on this model') raise NotImplementedError.new('you must override parent in order to enable relayable on this model')
end end
# @abstract
# @param parent An instance of Relayable#parent_class
def parent= parent
raise NotImplementedError.new('you must override parent= in order to enable relayable on this model')
end
end end
end end

View file

@ -1,62 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Encryptor
module Public
def encrypt cleartext
aes_key = gen_aes_key
ciphertext = aes_encrypt(cleartext, aes_key)
encrypted_key = encrypt_aes_key aes_key
cipher_hash = {:aes_key => encrypted_key, :ciphertext => ciphertext}
Base64.strict_encode64( cipher_hash.to_json )
end
def gen_aes_key
cipher = OpenSSL::Cipher.new('AES-256-CBC')
key = cipher.random_key
iv = cipher.random_iv
{'key' => Base64.strict_encode64(key), 'iv' => Base64.strict_encode64(iv)}
end
def aes_encrypt(txt, key)
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt
cipher.key = Base64.decode64 key['key']
cipher.iv = Base64.decode64 key['iv']
ciphertext = ''
ciphertext << cipher.update(txt)
ciphertext << cipher.final
Base64.strict_encode64(ciphertext)
end
def encrypt_aes_key key
Base64.strict_encode64(public_key.public_encrypt( key.to_json ))
end
end
module Private
def decrypt cipher_json
json = JSON.parse(Base64.decode64 cipher_json)
aes_key = get_aes_key json['aes_key']
aes_decrypt(json['ciphertext'], aes_key)
end
def get_aes_key encrypted_key
clear_key = encryption_key.private_decrypt( Base64.decode64 encrypted_key )
JSON::parse(clear_key)
end
def aes_decrypt(ciphertext, key)
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.decrypt
cipher.key = Base64.decode64 key['key']
cipher.iv = Base64.decode64 key['iv']
txt = ''
txt << cipher.update(Base64.decode64 ciphertext)
txt << cipher.final
txt
end
end
end

View file

@ -27,11 +27,7 @@ module Federated
end end
def build(options={}) def build(options={})
options.merge!(relayable_options) self.class.federated_class.new(options.merge(relayable_options).merge(author_id: @user.person.id))
relayable = self.class.federated_class.new(options.merge(:author_id => @user.person.id))
relayable.set_guid
relayable.initialize_signatures
relayable
end end
protected protected

View file

@ -7,31 +7,18 @@ module Federated
include Diaspora::Relayable include Diaspora::Relayable
belongs_to :target, :polymorphic => true belongs_to :target, polymorphic: true
belongs_to :author, :class_name => 'Person' belongs_to :author, class_name: "Person"
#end crazy ordering issues
validates_uniqueness_of :target_id, :scope => [:target_type, :author_id] delegate :diaspora_handle, to: :author
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
def diaspora_handle alias_attribute :parent, :target
self.author.diaspora_handle
end validates :target_id, uniqueness: {scope: %i(target_type author_id)}
validates :target, presence: true # should be in relayable (pending on fixing Message)
def diaspora_handle=(nh) def diaspora_handle=(nh)
self.author = Person.find_or_fetch_by_identifier(nh) self.author = Person.find_or_fetch_by_identifier(nh)
end end
def parent_class
self.target_type.constantize
end
def parent
self.target
end
def parent= parent
self.target = parent
end
end end
end end

View file

@ -78,7 +78,8 @@ describe PostsController, type: :controller do
it "responds with diaspora xml if format is xml" do it "responds with diaspora xml if format is xml" do
get :show, id: public.guid, format: :xml get :show, id: public.guid, format: :xml
expect(response.body).to eq(Diaspora::Federation.xml(Diaspora::Federation::Entities.post(public)).to_xml) expected_xml = DiasporaFederation::Salmon::XmlPayload.pack(Diaspora::Federation::Entities.post(public)).to_xml
expect(response.body).to eq(expected_xml)
end end
end end

View file

@ -285,7 +285,7 @@ FactoryGirl.define do
factory(:conversation) do factory(:conversation) do
association(:author, factory: :person) association(:author, factory: :person)
sequence(:subject) { |n| "conversation ##{n}" } sequence(:subject) {|n| "conversation ##{n}" }
after(:build) do |c| after(:build) do |c|
c.participants << c.author c.participants << c.author
@ -308,14 +308,6 @@ FactoryGirl.define do
after(:build) {|m| m.conversation.participants << m.author } after(:build) {|m| m.conversation.participants << m.author }
end end
factory(:message_with_conversation, parent: :message) do
after(:build) do |msg|
c = FactoryGirl.build(:conversation)
c.participants << msg.author
msg.conversation_id = c.id
end
end
#templates #templates
factory(:status_with_photo_backdrop, :parent => :status_message_with_photo) factory(:status_with_photo_backdrop, :parent => :status_message_with_photo)

View file

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the InvitationCodesHelper. For example:
#
# describe InvitationCodesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe InvitationCodesHelper, :type => :helper do
skip "add some examples to (or delete) #{__FILE__}"
end

View file

@ -1,29 +0,0 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe Diaspora::Encryptable do
before do
@comment = FactoryGirl.create(:comment, :author => bob.person)
end
describe '#sign_with_key' do
it 'signs the object with RSA256 signature' do
sig = @comment.sign_with_key bob.encryption_key
expect(bob.public_key.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(sig), @comment.signable_string)).to be true
end
end
describe '#verify_signature' do
it 'verifies SHA256 signatures' do
sig = @comment.sign_with_key bob.encryption_key
expect(@comment.verify_signature(sig, bob.person)).to be true
end
it 'does not verify the fallback after rollout window' do
sig = Base64.strict_encode64(bob.encryption_key.sign( "SHA", @comment.signable_string ))
expect(@comment.verify_signature(sig, bob.person)).to be false
end
end
end

View file

@ -2,11 +2,11 @@
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require 'spec_helper' require "spec_helper"
describe Diaspora::Federated::Base do describe Diaspora::Federated::Base do
describe '#subscribers' do describe "#subscribers" do
it 'throws an error if the including module does not redefine it' do it "throws an error if the including module does not redefine it" do
class Foo class Foo
include Diaspora::Federated::Base include Diaspora::Federated::Base
end end

View file

@ -1,21 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe 'user encryption' do
before do
@user = alice
@aspect = @user.aspects.first
end
describe 'encryption' do
it 'should encrypt a string' do
string = "Secretsauce"
ciphertext = @user.person.encrypt string
expect(ciphertext.include?(string)).to be false
expect(@user.decrypt(ciphertext)).to eq(string)
end
end
end

View file

@ -23,16 +23,6 @@ describe Message, :type => :model do
expect(message).not_to be_valid expect(message).not_to be_valid
end end
describe '#before_create' do
it 'signs the message' do
expect(@message.author_signature).not_to be_blank
end
it 'signs the message author if author of conversation' do
expect(@message.parent_author_signature).not_to be_blank
end
end
describe 'it is relayable' do describe 'it is relayable' do
before do before do
@local_luke, @local_leia, @remote_raphael = set_up_friends @local_luke, @local_leia, @remote_raphael = set_up_friends

View file

@ -17,7 +17,7 @@ describe PollParticipation, :type => :model do
2.times do |run| 2.times do |run|
bob.participate_in_poll!(@status, @poll.poll_answers.first) bob.participate_in_poll!(@status, @poll.poll_answers.first)
end end
}.to raise_error }.to raise_error ActiveRecord::RecordInvalid
end end
it 'allows a one time participation in a poll' do it 'allows a one time participation in a poll' do

View file

@ -241,14 +241,15 @@ describe Post, :type => :model do
end end
end end
describe 'Likeable#update_likes_counter' do describe "Likeable#update_likes_counter" do
before do before do
@post = bob.post :status_message, :text => "hello", :to => 'all' @post = bob.post(:status_message, text: "hello", public: true)
bob.like!(@post) bob.like!(@post)
end end
it 'does not update updated_at' do
old_time = Time.zone.now - 10000 it "does not update updated_at" do
Post.where(:id => @post.id).update_all(:updated_at => old_time) old_time = Time.zone.now - 100
Post.where(id: @post.id).update_all(updated_at: old_time)
expect(@post.reload.updated_at.to_i).to eq(old_time.to_i) expect(@post.reload.updated_at.to_i).to eq(old_time.to_i)
@post.update_likes_counter @post.update_likes_counter
expect(@post.reload.updated_at.to_i).to eq(old_time.to_i) expect(@post.reload.updated_at.to_i).to eq(old_time.to_i)

View file

@ -79,7 +79,7 @@ describe User::SocialActions, :type => :model do
it "does not allow multiple likes" do it "does not allow multiple likes" do
alice.like!(@status) alice.like!(@status)
likes = @status.likes likes = @status.likes
expect { alice.like!(@status) }.to raise_error expect { alice.like!(@status) }.to raise_error ActiveRecord::RecordInvalid
expect(@status.reload.likes).to eq(likes) expect(@status.reload.likes).to eq(likes)
end end

View file

@ -482,12 +482,6 @@ describe User, :type => :model do
it "does not preserve case" do it "does not preserve case" do
expect(User.find_for_database_authentication(:username => alice.username.upcase)).to eq(alice) expect(User.find_for_database_authentication(:username => alice.username.upcase)).to eq(alice)
end end
it 'errors out when passed a non-hash' do
expect {
User.find_for_database_authentication(alice.username)
}.to raise_error
end
end end
describe '#update_profile' do describe '#update_profile' do

View file

@ -54,28 +54,6 @@ shared_examples_for "it is relayable" do
end end
end end
context 'encryption' do
describe '#parent_author_signature' do
it 'should sign the object if the user is the post author' do
expect(@object_by_parent_author.verify_parent_author_signature).to be true
end
it 'should verify a object made on a remote post by a different contact' do
@object_by_recipient.author_signature = @object_by_recipient.send(:sign_with_key, @local_leia.encryption_key)
@object_by_recipient.parent_author_signature = @object_by_recipient.send(:sign_with_key, @local_luke.encryption_key)
expect(@object_by_recipient.verify_parent_author_signature).to be true
end
end
describe '#author_signature' do
it 'should sign as the object author' do
expect(@object_on_remote_parent.signature_valid?).to be true
expect(@object_by_parent_author.signature_valid?).to be true
expect(@object_by_recipient.signature_valid?).to be true
end
end
end
context 'propagation' do context 'propagation' do
describe '#receive' do describe '#receive' do
it 'dispatches when the person receiving is the parent author' do it 'dispatches when the person receiving is the parent author' do

View file

@ -37,4 +37,8 @@ class User
p p
end end
end end
def build_comment(options={})
Comment::Generator.new(self, options.delete(:post), options.delete(:text)).build(options)
end
end end

View file

@ -1,4 +1,4 @@
require 'spec_helper' require "spec_helper"
describe Workers::DeferredDispatch do describe Workers::DeferredDispatch do
it "handles non existing records gracefully" do it "handles non existing records gracefully" do
@ -6,34 +6,4 @@ describe Workers::DeferredDispatch do
described_class.new.perform(alice.id, "Comment", 0, {}) described_class.new.perform(alice.id, "Comment", 0, {})
}.to_not raise_error }.to_not raise_error
end end
describe "#social relay functionality" do
let(:message) { FactoryGirl.create(:status_message, author: alice.person, public: true) }
before do
skip # TODO
AppConfig.relay.outbound.send = true
end
it "triggers fetch of relay handle" do
allow(Person).to receive(:find_by).and_return(nil)
expect(Workers::FetchWebfinger).to receive(:perform_async)
described_class.new.perform(alice.id, "StatusMessage", message.id, {})
end
it "triggers post to relay" do
relay_person = FactoryGirl.create(:person, diaspora_handle: AppConfig.relay.outbound.handle)
opts = {"additional_subscribers" => [relay_person], "services" => []}
allow(Person).to receive(:find_by).and_return(relay_person)
postzord = double
allow(Postzord::Dispatcher).to receive(:build).with(any_args).and_return(postzord)
allow(postzord).to receive(:post)
allow(Person).to receive(:where).and_return([relay_person])
expect(Postzord::Dispatcher).to receive(:build).with(alice, message, opts)
described_class.new.perform(alice.id, "StatusMessage", message.id, {})
end
end
end end