Skip to content
Extraits de code Groupes Projets
Valider b6a912dd rédigé par ilya's avatar ilya
Parcourir les fichiers

slowly getting specs to pass on with the new api

parent 4ce4ce19
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -170,8 +170,9 @@ class User
end
def push_to_people(post, people)
salmon = salmon(post)
people.each{|person|
salmon(post, :to => person)
push_to_person( person, salmon.xml_for( person ))
}
end
......@@ -182,10 +183,8 @@ class User
end
def salmon( post, opts = {} )
salmon = Salmon::SalmonSlap.create(self, post.to_diaspora_xml)
push_to_person( opts[:to], salmon.to_xml)
salmon
def salmon( post )
Salmon::SalmonSlap.create(self, post.to_diaspora_xml)
end
######## Commenting ########
......@@ -217,7 +216,7 @@ class User
push_to_people comment, people_in_aspects(aspects_with_post(comment.post.id))
elsif owns? comment
comment.save
salmon comment, :to => comment.post.person
push_to_people comment, [comment.post.person]
end
end
......
......@@ -22,7 +22,7 @@ module Diaspora
aspect.requests << request
aspect.save
salmon request, :to => desired_friend
push_to_people request, [desired_friend]
end
request
end
......@@ -80,7 +80,7 @@ module Diaspora
def unfriend(bad_friend)
Rails.logger.info("#{self.real_name} is unfriending #{bad_friend.inspect}")
retraction = Retraction.for(self)
salmon( retraction, :to => bad_friend)
push_to_people retraction, [bad_friend]
remove_friend(bad_friend)
end
......
......@@ -3,7 +3,7 @@ module Diaspora
module Receiving
def receive_salmon ciphertext
cleartext = decrypt( ciphertext)
salmon = Salmon::SalmonSlap.parse cleartext
salmon = Salmon::SalmonSlap.parse cleartext, self
if salmon.verified_for_key?(salmon.author.public_key)
Rails.logger.info("data in salmon: #{salmon.parsed_data}")
self.receive(salmon.parsed_data)
......
......@@ -62,9 +62,7 @@ module Salmon
### Header ##
decrypted_header = user.decrypt(doc.search('encrypted_header').text)
puts decrypted_header
header_doc = Nokogiri::XML(decrypted_header)
puts header_doc.inspect
slap.aes_key = header_doc.search('aes_key').text
slap.iv = header_doc.search('iv').text
......@@ -88,20 +86,6 @@ module Salmon
slap
end
def to_xml
xml =<<ENTRY
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'>
<author>
<name>#{@author.real_name}</name>
<uri>acct:#{@author.diaspora_handle}</uri>
</author>
#{@magic_sig.to_xml}
</entry>
ENTRY
end
def xml_for person
xml =<<ENTRY
<?xml version='1.0' encoding='UTF-8'?>
......@@ -119,14 +103,14 @@ ENTRY
def decrypted_header
header =<<HEADER
<header>
<decrypted_header>
<iv>#{iv}</iv>
<aes_key>#{aes_key}</aes_key>
<author>
<name>#{@author.real_name}</name>
<uri>acct:#{@author.diaspora_handle}</uri>
</author>
</header>
</decrypted_header>
HEADER
end
......
......@@ -64,55 +64,38 @@ describe Salmon do
end
it 'contains the original data' do
parsed_salmon.parsed_data.should == post.to_diaspora_xml
end
end
describe '#author' do
before do
stub_success("tom@tom.joindiaspora.com")
end
context 'round trip' do
before do
@sent_salmon = Salmon::SalmonSlap.create(user, post.to_diaspora_xml)
@parsed_salmon =
stub_success("tom@tom.joindiaspora.com")
end
it 'should verify the signature on a roundtrip' do
it 'should reference a local author' do
parsed_salmon.author.should == user.person
end
@sent_salmon.magic_sig.data.should == @parsed_salmon.magic_sig.data
it 'should reference a remote author' do
parsed_salmon.author_email = 'tom@tom.joindiaspora.com'
parsed_salmon.author.public_key.should_not be_nil
end
@sent_salmon.magic_sig.sig.should == @parsed_salmon.magic_sig.sig
@sent_salmon.magic_sig.signable_string.should == @parsed_salmon.magic_sig.signable_string
@parsed_salmon.verified_for_key?(OpenSSL::PKey::RSA.new(user.exported_key)).should be true
@sent_salmon.verified_for_key?(OpenSSL::PKey::RSA.new(user.exported_key)).should be true
it 'should fail to reference a nonexistent remote author' do
parsed_salmon.author_email = 'idsfug@difgubhpsduh.rgd'
proc {
Redfinger.stub(:finger).and_return(nil) #Redfinger returns nil when there is no profile
parsed_salmon.author.real_name}.should raise_error /No webfinger profile found/
end
end
it 'should return the data so it can be "received"' do
xml = post.to_diaspora_xml
@parsed_salmon.parsed_data.should == xml
it 'verifies the signature for the sender' do
parsed_salmon.verified_for_key?(user.public_key).should be true
end
it 'should reference a local author' do
@parsed_salmon.author.should == user.person
it 'contains the original data' do
parsed_salmon.parsed_data.should == post.to_diaspora_xml
end
it 'should reference a remote author' do
@parsed_salmon.author_email = 'tom@tom.joindiaspora.com'
@parsed_salmon.author.public_key.should_not be_nil
end
end
it 'should fail to reference a nonexistent remote author' do
@parsed_salmon.author_email = 'idsfug@difgubhpsduh.rgd'
proc {
Redfinger.stub(:finger).and_return(nil) #Redfinger returns nil when there is no profile
@parsed_salmon.author.real_name}.should raise_error /No webfinger profile found/
end
end
end
......@@ -173,11 +173,12 @@ describe User do
describe 'salmon' do
before do
@post = @user.post :status_message, :message => "hello", :to => @aspect.id
@salmon = @user.salmon( @post, :to => @user2.person )
@salmon = @user.salmon( @post )
end
it 'should receive a salmon for a post' do
@user2.receive_salmon( @user2.person.encrypt(@salmon.to_xml) )
puts @salmon.inspect
@user2.receive_salmon( @salmon.xml_for @user2.person )
@user2.visible_post_ids.include?(@post.id).should be true
end
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter