started to refactor the salmon spec, changed data in to be parsed data
to be more clear
This commit is contained in:
parent
904143d100
commit
6eede48f9f
3 changed files with 60 additions and 44 deletions
|
|
@ -5,8 +5,8 @@ module Diaspora
|
|||
cleartext = decrypt( ciphertext)
|
||||
salmon = Salmon::SalmonSlap.parse cleartext
|
||||
if salmon.verified_for_key?(salmon.author.public_key)
|
||||
Rails.logger.info("data in salmon: #{salmon.data}")
|
||||
self.receive(salmon.data)
|
||||
Rails.logger.info("data in salmon: #{salmon.parsed_data}")
|
||||
self.receive(salmon.parsed_data)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ end
|
|||
module Salmon
|
||||
|
||||
class SalmonSlap
|
||||
attr_accessor :magic_sig, :author, :author_email, :data, :data_type, :sig
|
||||
attr_accessor :magic_sig, :author, :author_email, :parsed_data, :data_type, :sig
|
||||
def self.parse(xml)
|
||||
slap = self.new
|
||||
doc = Nokogiri::XML(xml)
|
||||
|
|
@ -50,7 +50,7 @@ module Salmon
|
|||
slap.magic_sig = MagicSigEnvelope.parse sig_doc
|
||||
|
||||
if 'base64url' == slap.magic_sig.encoding
|
||||
slap.data = decode64url(slap.magic_sig.data)
|
||||
slap.parsed_data = decode64url(slap.magic_sig.data)
|
||||
slap.sig = slap.magic_sig.sig
|
||||
else
|
||||
raise ArgumentError, "Magic Signature data must be encoded with base64url, was #{slap.magic_sig.encoding}"
|
||||
|
|
|
|||
|
|
@ -5,52 +5,68 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Salmon do
|
||||
before do
|
||||
let(:user){Factory.create :user}
|
||||
let(:post){ user.post :status_message, :message => "hi", :to => user.aspect(:name => "sdg").id }
|
||||
|
||||
@user = Factory.create :user
|
||||
@post = @user.post :status_message, :message => "hi", :to => @user.aspect(:name => "sdg").id
|
||||
@sent_salmon = Salmon::SalmonSlap.create(@user, @post.to_diaspora_xml)
|
||||
@parsed_salmon = Salmon::SalmonSlap.parse @sent_salmon.to_xml
|
||||
stub_success("tom@tom.joindiaspora.com")
|
||||
end
|
||||
describe '#create' do
|
||||
let!(:created_salmon) {Salmon::SalmonSlap.create(user, post.to_diaspora_xml)}
|
||||
|
||||
it 'should verify the signature on a roundtrip' do
|
||||
|
||||
@sent_salmon.magic_sig.data.should == @parsed_salmon.magic_sig.data
|
||||
|
||||
@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
|
||||
end
|
||||
|
||||
it 'should return the data so it can be "received"' do
|
||||
|
||||
xml = @post.to_diaspora_xml
|
||||
|
||||
@parsed_salmon.data.should == xml
|
||||
end
|
||||
|
||||
it 'should parse out the authors diaspora_handle' do
|
||||
@parsed_salmon.author_email.should == @user.person.diaspora_handle
|
||||
it 'has data in the magic envelope' do
|
||||
created_salmon.magic_sig.data.should_not be nil
|
||||
end
|
||||
|
||||
it 'has no parsed_data' do
|
||||
created_salmon.parsed_data.should be nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'should reference a local author' do
|
||||
@parsed_salmon.author.should == @user.person
|
||||
end
|
||||
context 'round trip' do
|
||||
before do
|
||||
@sent_salmon = Salmon::SalmonSlap.create(user, post.to_diaspora_xml)
|
||||
@parsed_salmon = Salmon::SalmonSlap.parse @sent_salmon.to_xml
|
||||
stub_success("tom@tom.joindiaspora.com")
|
||||
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
|
||||
|
||||
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
|
||||
it 'should verify the signature on a roundtrip' do
|
||||
|
||||
@sent_salmon.magic_sig.data.should == @parsed_salmon.magic_sig.data
|
||||
|
||||
@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
|
||||
end
|
||||
|
||||
it 'should return the data so it can be "received"' do
|
||||
|
||||
xml = post.to_diaspora_xml
|
||||
|
||||
@parsed_salmon.parsed_data.should == xml
|
||||
end
|
||||
|
||||
it 'should parse out the authors diaspora_handle' do
|
||||
@parsed_salmon.author_email.should == user.person.diaspora_handle
|
||||
|
||||
end
|
||||
|
||||
it 'should reference a local author' do
|
||||
@parsed_salmon.author.should == user.person
|
||||
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
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue