diff --git a/Gemfile b/Gemfile index c3d8c3477..91d26abd6 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,7 @@ group :test do gem 'database_cleaner' gem 'saucelabs-adapter', '= 0.8.12' gem 'selenium-rc' + gem 'webmock' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 673818fbe..a880b5803 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,6 +108,7 @@ GEM net-ssh (>= 2.0.14) net-ssh-gateway (>= 1.0.0) columnize (0.3.1) + crack (0.1.8) daemons (1.1.0) database_cleaner (0.5.2) diff-lcs (1.1.2) @@ -213,6 +214,9 @@ GEM tzinfo (0.3.23) warden (0.10.7) rack (>= 1.0.0) + webmock (1.3.5) + addressable (>= 2.1.1) + crack (>= 0.1.7) webrat (0.7.2.beta.1) nokogiri (>= 1.2.0) rack (>= 1.0) @@ -254,5 +258,6 @@ DEPENDENCIES selenium-rc sprinkle! thin + webmock webrat (= 0.7.2.beta.1) will_paginate (= 3.0.pre2) diff --git a/app/models/person.rb b/app/models/person.rb index b85b98264..b9fd85cc0 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -102,7 +102,7 @@ class Person rescue SocketError => e raise "Diaspora server for #{identifier} not found" if e.message =~ /Name or service not known/ end - raise "No diaspora user found at #{identifier}" unless f + raise "No webfinger profile found at #{identifier}" unless f Person.from_webfinger_profile(identifier, f ) end end diff --git a/app/views/publics/webfinger.erb b/app/views/publics/webfinger.erb index ab3e35087..f695c4c97 100644 --- a/app/views/publics/webfinger.erb +++ b/app/views/publics/webfinger.erb @@ -2,7 +2,7 @@ acct:<%=@person.email%> "<%= @person.url %>" - + diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb index 348916334..bb676cba8 100644 --- a/spec/controllers/requests_controller_spec.rb +++ b/spec/controllers/requests_controller_spec.rb @@ -25,9 +25,9 @@ describe RequestsController do render_views before do @user = Factory.create :user + stub_success("tom@tom.joindiaspora.com") + @tom = Redfinger.finger('tom@tom.joindiaspora.com') - @evan = Redfinger.finger('evan@status.net') - @max = Redfinger.finger('mbs348@gmail.com') sign_in :user, @user stub!(:current_user).and_return @user end diff --git a/spec/helpers/requests_helper_spec.rb b/spec/helpers/requests_helper_spec.rb index d879de6ae..2defd897c 100644 --- a/spec/helpers/requests_helper_spec.rb +++ b/spec/helpers/requests_helper_spec.rb @@ -25,16 +25,17 @@ include RequestsHelper describe RequestsHelper do before do + + stub_success("tom@tom.joindiaspora.com") + stub_success("evan@status.net") @tom = Redfinger.finger('tom@tom.joindiaspora.com') @evan = Redfinger.finger('evan@status.net') - @max = Redfinger.finger('mbs348@gmail.com') end describe "profile" do it 'should detect how to subscribe to a diaspora or webfinger profile' do subscription_mode(@tom).should == :friend subscription_mode(@evan).should == :none - subscription_mode(@max).should == :none end end end diff --git a/spec/lib/hcard_spec.rb b/spec/lib/hcard_spec.rb index 38048ab9c..c90d8cf0b 100644 --- a/spec/lib/hcard_spec.rb +++ b/spec/lib/hcard_spec.rb @@ -23,6 +23,7 @@ require File.dirname(__FILE__) + '/../../lib/hcard' describe HCard do it 'should retreive and parse an hcard' do + stub_success("tom@tom.joindiaspora.com") f = Redfinger.finger('tom@tom.joindiaspora.com') hcard = HCard.find f.hcard.first[:href] hcard[:family_name].include?("Hamiltom").should be true diff --git a/spec/lib/salmon_salmon_spec.rb b/spec/lib/salmon_salmon_spec.rb index f372a5e12..9a4fc475a 100644 --- a/spec/lib/salmon_salmon_spec.rb +++ b/spec/lib/salmon_salmon_spec.rb @@ -27,6 +27,7 @@ describe Salmon do @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 @@ -63,7 +64,9 @@ describe Salmon do it 'should fail to reference a nonexistent remote author' do @parsed_salmon.author_email = 'idsfug@difgubhpsduh.rgd' - proc {@parsed_salmon.author.real_name}.should raise_error /No diaspora user found/ + 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 diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index be6b536bb..a8760a8df 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -162,10 +162,14 @@ describe Person do end it 'should search by email exactly' do + + stub_success("tom@tom.joindiaspora.com") Person.by_webfinger(@friend_one.email).should == @friend_one end it 'should create a stub for a remote user' do + + stub_success("tom@tom.joindiaspora.com") tom = Person.by_webfinger('tom@tom.joindiaspora.com') tom.real_name.include?("Hamiltom").should be true end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index abc3ce1b5..b2428aa6e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,7 +25,12 @@ ENV["RAILS_ENV"] ||= 'test' require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails) require 'rspec/rails' require 'database_cleaner' +require 'webmock/rspec' + include Devise::TestHelpers +include WebMock + + # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. @@ -86,3 +91,196 @@ end reversed_request = user2.accept_friend_request( request.id, aspect2.id) user1.receive reversed_request.to_diaspora_xml end + + def stub_success(address = 'abc@example.com') + host = address.split('@')[1] + stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) + stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) + if host.include?("joindiaspora.com") + stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd) + stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response) + else + stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => nonseed_finger_xrd) + stub_request(:get, 'http://evan.status.net/hcard').to_return(:status => 200, :body => evan_hcard) + end + end + + def stub_failure(address = 'abc@example.com') + host = address.split('@')[1] + stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) + stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) + stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 500) + end + + def host_xrd + <<-XML + + + + Resource Descriptor + + + XML + end + + def finger_xrd + <<-XML + + + acct:tom@tom.joindiaspora.com + "http://tom.joindiaspora.com/" + + + + + + XML + end + + def hcard_response + <<-FOO +
+

Alexander Hamiltom

+
+
+

User profile

+
+
Nickname
+
+ Alexander Hamiltom +
+
+
+
Full name
+
+ Alexander +
+
+ +
+
Full name
+
+ Hamiltom +
+
+
+
Full name
+
+ Alexander Hamiltom +
+
+
+
URL
+
+ http://tom.joindiaspora.com/ +
+
+
+
Note
+
Diaspora is awesome! vi is better than emacs!
+
+
+
+ +
+ + FOO + end + + def nonseed_finger_xrd + <<-XML + + acct:evan@status.net + acct:evan@evan.status.net + http://evan.status.net/user/1 + + + + + + + + + + + + XML + end + + def evan_hcard + <<-HCARD + + +
+
+ +
+

Evan Prodromou

+ +
+
+

User profile

+
+
Photo
+
+ evan +
+ +
+
+
Nickname
+
+ evan +
+
+
+
Full name
+ +
+ Evan Prodromou +
+
+
+
Location
+
Montreal, QC, Canada
+
+
+ +
URL
+
+ http://evan.prodromou.name/ +
+
+
+
Note
+
Montreal hacker and entrepreneur. Founder of identi.ca, lead developer of StatusNet, CEO of StatusNet Inc.
+ +
+
+
+
+
+ +
+ + HCARD + + end