/
salmon_salmon_spec.rb
58 lines (40 loc) · 1.87 KB
/
salmon_salmon_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright (c) 2010, Disapora Inc. This file is
# licensed under the Affero General Public License version 3. See
# the COPYRIGHT file.
require File.dirname(__FILE__) + '/../spec_helper'
describe Salmon do
before do
@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
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
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