From 7640065d6883b9855ae5259ef765d1fa757853cc Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Thu, 24 Jun 2010 21:52:06 +0800 Subject: [PATCH 01/17] Update rest-client dependency --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 6de76e6..319f5e7 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,7 @@ begin gem.email = "michael@intridea.com" gem.homepage = "http://github.com/mbleigh/redfinger" gem.authors = ["Michael Bleigh"] - gem.add_dependency "rest-client" + gem.add_dependency "rest-client", ">= 1.5.0" gem.add_dependency "nokogiri", ">= 1.4.0" gem.add_dependency "hashie" gem.add_development_dependency "rspec", ">= 1.2.9" From 3f12bb1b4d378f738fbb9c9edcfe5b5fa0950b9a Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Thu, 24 Jun 2010 21:52:10 +0800 Subject: [PATCH 02/17] Version bump to 0.0.4 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index bcab45a..81340c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.3 +0.0.4 From 59fd1da0c54a29d53aadf9cc188c869a9c6daf48 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Thu, 24 Jun 2010 21:52:13 +0800 Subject: [PATCH 03/17] Regenerated gemspec for version 0.0.4 --- redfinger.gemspec | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/redfinger.gemspec b/redfinger.gemspec index c70a6c0..3d69cf8 100644 --- a/redfinger.gemspec +++ b/redfinger.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{redfinger} - s.version = "0.0.3" + s.version = "0.0.4" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Michael Bleigh"] - s.date = %q{2010-02-13} + s.date = %q{2010-06-24} s.description = %q{A Ruby Webfinger client} s.email = %q{michael@intridea.com} s.extra_rdoc_files = [ @@ -37,7 +37,7 @@ Gem::Specification.new do |s| s.homepage = %q{http://github.com/mbleigh/redfinger} s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.5} + s.rubygems_version = %q{1.3.6} s.summary = %q{A Ruby WebFinger client.} s.test_files = [ "spec/redfinger/client_spec.rb", @@ -50,20 +50,20 @@ Gem::Specification.new do |s| s.specification_version = 3 if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 1.5.0"]) s.add_runtime_dependency(%q, [">= 1.4.0"]) s.add_runtime_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 1.2.9"]) s.add_development_dependency(%q, [">= 0"]) else - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 1.5.0"]) s.add_dependency(%q, [">= 1.4.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 1.2.9"]) s.add_dependency(%q, [">= 0"]) end else - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 1.5.0"]) s.add_dependency(%q, [">= 1.4.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 1.2.9"]) From 1200c463336475bac45a1193bf9ea46b4d1b3539 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Thu, 24 Jun 2010 21:54:18 +0800 Subject: [PATCH 04/17] Version bump to 0.0.5 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 81340c7..bbdeab6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.4 +0.0.5 From 05b0fbbabad5e8a27755bc3d69d6389eb008129f Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Thu, 24 Jun 2010 21:54:19 +0800 Subject: [PATCH 05/17] Regenerated gemspec for version 0.0.5 --- redfinger.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redfinger.gemspec b/redfinger.gemspec index 3d69cf8..e3086c2 100644 --- a/redfinger.gemspec +++ b/redfinger.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{redfinger} - s.version = "0.0.4" + s.version = "0.0.5" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Michael Bleigh"] From 088386f183f517eb0f156945faac068a62462afa Mon Sep 17 00:00:00 2001 From: Blaine Cook Date: Sat, 7 Aug 2010 18:13:41 +0800 Subject: [PATCH 06/17] Default to acct-less addresses, fall back to addresses with acct scheme. --- lib/redfinger/client.rb | 21 +++++++++++++++------ lib/redfinger/finger.rb | 4 ++-- spec/redfinger/client_spec.rb | 8 ++------ spec/spec_helper.rb | 5 ++--- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/redfinger/client.rb b/lib/redfinger/client.rb index cf44fa6..529dd6f 100644 --- a/lib/redfinger/client.rb +++ b/lib/redfinger/client.rb @@ -7,13 +7,17 @@ class Client attr_accessor :account, :domain, :uri_template def initialize(email, uri_template = nil) - self.account = urify(email) + self.account = normalize(email) self.domain = account.split('@').last end def finger self.uri_template ||= retrieve_template_from_xrd - Finger.new RestClient.get(swizzle).body + begin + return Finger.new self.account, RestClient.get(swizzle).body + rescue RestClient::ResourceNotFound + return Finger.new self.account, RestClient.get(swizzle(account_with_scheme)).body + end end def xrd_url(ssl = true) @@ -22,7 +26,8 @@ def xrd_url(ssl = true) private - def swizzle + def swizzle(account = nil) + account ||= self.account uri_template.gsub '{uri}', URI.escape(self.account) end @@ -47,9 +52,13 @@ def retrieve_template_from_xrd(ssl = true) end end - def urify(email) - email = "acct:#{email}" unless email.include?("acct:") - email + def normalize(email) + email.sub! /^acct:/, '' + email.downcase + end + + def account_with_scheme + "acct:" + account end end end diff --git a/lib/redfinger/finger.rb b/lib/redfinger/finger.rb index 1b4dda9..a6123ae 100644 --- a/lib/redfinger/finger.rb +++ b/lib/redfinger/finger.rb @@ -5,9 +5,9 @@ module Redfinger # special helpers that are availale to pull specific types # of URLs, see Redfinger::LinkHelpers class Finger - def initialize(xml) # :nodoc: + def initialize(subject, xml) # :nodoc: @doc = Nokogiri::XML::Document.parse(xml) - @subject = @doc.at_css('Subject').content + @subject = subject end # All of the links provided by the Webfinger response. diff --git a/spec/redfinger/client_spec.rb b/spec/redfinger/client_spec.rb index d3a8261..e9ddf8b 100644 --- a/spec/redfinger/client_spec.rb +++ b/spec/redfinger/client_spec.rb @@ -4,12 +4,8 @@ class HaltSuccessError < StandardError; end describe Redfinger::Client do describe '#new' do - it 'should add acct: if it is not in URI form' do - Redfinger::Client.new('abc@example.com').account.should == 'acct:abc@example.com' - end - - it 'should not add acct: if it is already in URI form' do - Redfinger::Client.new('acct:abc@example.com').account.should == 'acct:abc@example.com' + it 'should remove acct: if it is already in URI form' do + Redfinger::Client.new('acct:abc@example.com').account.should == 'abc@example.com' end it 'should set the domain to whatevers after the @ sign' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f001bdb..2743d60 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,7 +29,6 @@ def finger_xrd <<-XML - acct:abc@example.com http://www.google.com/profiles/abc @@ -43,9 +42,9 @@ def finger_xrd XML end -def stub_success +def stub_success(address = 'abc@example.com') stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => 200, :body => host_xrd) - stub_request(:get, /webfinger\/\?q=.*/).to_return(:status => 200, :body => finger_xrd) + stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd) end Spec::Runner.configure do |config| From 995aebd1d31bdb9a728d53c55ba3c85216c97284 Mon Sep 17 00:00:00 2001 From: Blaine Cook Date: Sat, 7 Aug 2010 18:14:36 +0800 Subject: [PATCH 07/17] Update handling of host-meta to reflect most recent spec (no hm:Host) --- lib/redfinger/client.rb | 5 +---- spec/redfinger/client_spec.rb | 5 ----- spec/spec_helper.rb | 6 +----- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/redfinger/client.rb b/lib/redfinger/client.rb index 529dd6f..4400892 100644 --- a/lib/redfinger/client.rb +++ b/lib/redfinger/client.rb @@ -33,15 +33,12 @@ def swizzle(account = nil) def retrieve_template_from_xrd(ssl = true) doc = Nokogiri::XML::Document.parse(RestClient.get(xrd_url(ssl)).body) - if doc.namespaces["xmlns:hm"] != "http://host-meta.net/xrd/1.0" + if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0" # it's probably not finger, let's try without ssl # http://code.google.com/p/webfinger/wiki/WebFingerProtocol # says first ssl should be tried then without ssl, should fix issue #2 doc = Nokogiri::XML::Document.parse(RestClient.get(xrd_url(false)).body) end - unless doc.at_xpath('.//hm:Host').content == self.domain - raise Redfinger::SecurityException, "The XRD document's host did not match the account's host." - end doc.at('Link[rel=lrdd]').attribute('template').value rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound diff --git a/spec/redfinger/client_spec.rb b/spec/redfinger/client_spec.rb index e9ddf8b..f110c06 100644 --- a/spec/redfinger/client_spec.rb +++ b/spec/redfinger/client_spec.rb @@ -41,11 +41,6 @@ class HaltSuccessError < StandardError; end stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => 200, :body => host_xrd) Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd).should == 'http://example.com/webfinger/?q={uri}' end - - it 'should raise a SecurityException if there is a host mismatch' do - stub_request(:get, 'https://franklin.com/.well-known/host-meta').to_return(:status => 200, :body => host_xrd) - lambda{Redfinger::Client.new('acct:abc@franklin.com').send(:retrieve_template_from_xrd)}.should raise_error(Redfinger::SecurityException) - end end describe '#finger' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2743d60..33ee678 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,11 +12,7 @@ def host_xrd <<-XML - - - - example.com + Resource Descriptor From 0343831fe3fbaeacae048e1b3ffa0dd20fc2a5d1 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Tue, 10 Aug 2010 22:55:14 +0800 Subject: [PATCH 08/17] Version bump to 0.0.6 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index bbdeab6..1750564 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.5 +0.0.6 From 3201b069d0b475da1adebb5c606884da300992c2 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Tue, 10 Aug 2010 22:55:14 +0800 Subject: [PATCH 09/17] Regenerated gemspec for version 0.0.6 --- redfinger.gemspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/redfinger.gemspec b/redfinger.gemspec index e3086c2..d6972da 100644 --- a/redfinger.gemspec +++ b/redfinger.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{redfinger} - s.version = "0.0.5" + s.version = "0.0.6" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Michael Bleigh"] - s.date = %q{2010-06-24} + s.date = %q{2010-08-10} s.description = %q{A Ruby Webfinger client} s.email = %q{michael@intridea.com} s.extra_rdoc_files = [ @@ -37,7 +37,7 @@ Gem::Specification.new do |s| s.homepage = %q{http://github.com/mbleigh/redfinger} s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.6} + s.rubygems_version = %q{1.3.7} s.summary = %q{A Ruby WebFinger client.} s.test_files = [ "spec/redfinger/client_spec.rb", @@ -49,7 +49,7 @@ Gem::Specification.new do |s| current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [">= 1.5.0"]) s.add_runtime_dependency(%q, [">= 1.4.0"]) s.add_runtime_dependency(%q, [">= 0"]) From f4e85aab31007c942440bf13aa58d5b0cc125d7e Mon Sep 17 00:00:00 2001 From: Max Ogden Date: Tue, 16 Nov 2010 08:46:14 +0800 Subject: [PATCH 10/17] try http if servers throw 403s on https --- lib/redfinger/client.rb | 2 +- spec/redfinger/client_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/redfinger/client.rb b/lib/redfinger/client.rb index 4400892..0ef09e7 100644 --- a/lib/redfinger/client.rb +++ b/lib/redfinger/client.rb @@ -41,7 +41,7 @@ def retrieve_template_from_xrd(ssl = true) end doc.at('Link[rel=lrdd]').attribute('template').value - rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound + rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound, RestClient::Forbidden if ssl retrieve_template_from_xrd(false) else diff --git a/spec/redfinger/client_spec.rb b/spec/redfinger/client_spec.rb index f110c06..9f9dc36 100644 --- a/spec/redfinger/client_spec.rb +++ b/spec/redfinger/client_spec.rb @@ -25,6 +25,12 @@ class HaltSuccessError < StandardError; end stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) end + + it 'should make an HTTP request if the server throws a 403 forbidden on the HTTPS request' do + stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => [403, "Forbidden"]) + stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) + lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) + end it 'should raise Redfinger::ResourceNotFound if HTTP fails as well' do stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ECONNREFUSED) From 61bccd85a13268ba3a8630fe12af409c83bce44d Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Mon, 7 Feb 2011 15:21:37 +0800 Subject: [PATCH 11/17] Update specs to run under RSpec 2.x, updated include WebMock to reference WebMock::API --- Rakefile | 11 +++-------- spec/spec_helper.rb | 8 ++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Rakefile b/Rakefile index 319f5e7..5076760 100644 --- a/Rakefile +++ b/Rakefile @@ -22,15 +22,10 @@ rescue LoadError puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" end -require 'spec/rake/spectask' -Spec::Rake::SpecTask.new(:spec) do |spec| - spec.libs << 'lib' << 'spec' - spec.spec_files = FileList['spec/**/*_spec.rb'] -end +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) -Spec::Rake::SpecTask.new(:rcov) do |spec| - spec.libs << 'lib' << 'spec' - spec.pattern = 'spec/**/*_spec.rb' +RSpec::Core::RakeTask.new(:rcov) do |spec| spec.rcov = true end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 33ee678..b9e1147 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,11 +3,11 @@ require 'rubygems' require 'redfinger' -require 'spec' -require 'spec/autorun' +require 'rspec' +require 'rspec/autorun' require 'webmock/rspec' -include WebMock +include WebMock::API def host_xrd <<-XML @@ -43,6 +43,6 @@ def stub_success(address = 'abc@example.com') stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd) end -Spec::Runner.configure do |config| +RSpec.configure do |config| end From 5e723515ee00c876dd00cf9a1f052257684cb520 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Mon, 7 Feb 2011 15:22:16 +0800 Subject: [PATCH 12/17] Fall back to HTTP if the HTTPS connection times out. --- lib/redfinger/client.rb | 2 +- spec/redfinger/client_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/redfinger/client.rb b/lib/redfinger/client.rb index 0ef09e7..fcf4ef0 100644 --- a/lib/redfinger/client.rb +++ b/lib/redfinger/client.rb @@ -41,7 +41,7 @@ def retrieve_template_from_xrd(ssl = true) end doc.at('Link[rel=lrdd]').attribute('template').value - rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound, RestClient::Forbidden + rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, RestClient::ResourceNotFound, RestClient::Forbidden if ssl retrieve_template_from_xrd(false) else diff --git a/spec/redfinger/client_spec.rb b/spec/redfinger/client_spec.rb index 9f9dc36..8c8c3c6 100644 --- a/spec/redfinger/client_spec.rb +++ b/spec/redfinger/client_spec.rb @@ -26,6 +26,12 @@ class HaltSuccessError < StandardError; end lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) end + it 'should make an HTTP request if the HTTPS request times out' do + stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ETIMEDOUT) + stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) + lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) + end + it 'should make an HTTP request if the server throws a 403 forbidden on the HTTPS request' do stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => [403, "Forbidden"]) stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) From 106320c0d51bfa2bf36e9aeee3b55a208cdf650e Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Mon, 7 Feb 2011 15:28:55 +0800 Subject: [PATCH 13/17] Allow setting of timeout and open_timeout on Redfinger::Client, which will be passed along to RestClient when making xrd requests. HTTP fallback on RestClient::RequestTimeout in addition to Errno::ETIMEDOUT --- lib/redfinger/client.rb | 15 ++++++++++++--- spec/redfinger/client_spec.rb | 8 +++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/redfinger/client.rb b/lib/redfinger/client.rb index fcf4ef0..61b0733 100644 --- a/lib/redfinger/client.rb +++ b/lib/redfinger/client.rb @@ -4,11 +4,14 @@ module Redfinger class Client - attr_accessor :account, :domain, :uri_template + attr_accessor :account, :domain, :uri_template, :xrd_timeout, :xrd_open_timeout def initialize(email, uri_template = nil) self.account = normalize(email) self.domain = account.split('@').last + + self.xrd_timeout = 10 + self.xrd_open_timeout = 5 end def finger @@ -32,7 +35,12 @@ def swizzle(account = nil) end def retrieve_template_from_xrd(ssl = true) - doc = Nokogiri::XML::Document.parse(RestClient.get(xrd_url(ssl)).body) + xrd_client = RestClient::Resource.new(xrd_url(ssl), + :timeout => self.xrd_timeout, + :open_timeout => self.xrd_open_timeout + ) + + doc = Nokogiri::XML::Document.parse(xrd_client.get.body) if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0" # it's probably not finger, let's try without ssl # http://code.google.com/p/webfinger/wiki/WebFingerProtocol @@ -41,7 +49,8 @@ def retrieve_template_from_xrd(ssl = true) end doc.at('Link[rel=lrdd]').attribute('template').value - rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, RestClient::ResourceNotFound, RestClient::Forbidden + rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, + RestClient::RequestTimeout, RestClient::ResourceNotFound, RestClient::Forbidden if ssl retrieve_template_from_xrd(false) else diff --git a/spec/redfinger/client_spec.rb b/spec/redfinger/client_spec.rb index 8c8c3c6..875f78b 100644 --- a/spec/redfinger/client_spec.rb +++ b/spec/redfinger/client_spec.rb @@ -26,12 +26,18 @@ class HaltSuccessError < StandardError; end lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) end - it 'should make an HTTP request if the HTTPS request times out' do + it 'should make an HTTP request if the HTTPS request times out in Net::HTTP' do stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ETIMEDOUT) stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) end + it 'should make an HTTP request if the HTTPS request times out in RestClient' do + stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(RestClient::RequestTimeout) + stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) + lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) + end + it 'should make an HTTP request if the server throws a 403 forbidden on the HTTPS request' do stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => [403, "Forbidden"]) stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) From 635050a6578c80f87e5c493d78a45518463b6185 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Mon, 7 Feb 2011 15:37:16 +0800 Subject: [PATCH 14/17] Create a new Redfinger::Link.from_xml(xml_link) method to avoid overriding Hashie::Mash#initialize (see intridea/hashie#14 for details) --- lib/redfinger/finger.rb | 2 +- lib/redfinger/link.rb | 10 ++++++---- lib/redfinger/link_helpers.rb | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/redfinger/finger.rb b/lib/redfinger/finger.rb index a6123ae..6ca4b42 100644 --- a/lib/redfinger/finger.rb +++ b/lib/redfinger/finger.rb @@ -12,7 +12,7 @@ def initialize(subject, xml) # :nodoc: # All of the links provided by the Webfinger response. def links - @links ||= @doc.css('Link').map{|l| Link.new(l)} + @links ||= @doc.css('Link').map{|l| Link.from_xml(l)} end def inspect # :nodoc: diff --git a/lib/redfinger/link.rb b/lib/redfinger/link.rb index 788f268..790b29c 100644 --- a/lib/redfinger/link.rb +++ b/lib/redfinger/link.rb @@ -3,10 +3,12 @@ module Redfinger class Link < Hashie::Mash - def initialize(xml_link) - self[:rel] = xml_link['rel'] - self[:href] = xml_link['href'] - self[:type] = xml_link['type'] + def self.from_xml(xml_link) + new_link = Link.new + new_link[:rel] = xml_link['rel'] + new_link[:href] = xml_link['href'] + new_link[:type] = xml_link['type'] + new_link end # Outputs the URL of the link, useful for using diff --git a/lib/redfinger/link_helpers.rb b/lib/redfinger/link_helpers.rb index 54d27b3..8c0f7de 100644 --- a/lib/redfinger/link_helpers.rb +++ b/lib/redfinger/link_helpers.rb @@ -25,7 +25,7 @@ def xfn protected def relmap(uri, substring=false) - @doc.css("Link[rel#{'^' if substring}=\"#{uri}\"]").map{|e| Link.new(e)} + @doc.css("Link[rel#{'^' if substring}=\"#{uri}\"]").map{|e| Link.from_xml(e)} end end end From aca639273b8b5294285c3a0ef61a673b3879f262 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Mon, 7 Feb 2011 15:48:27 +0800 Subject: [PATCH 15/17] Adds .rspec with some options. --- .rspec | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..27d79f4 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--colour +--format nested \ No newline at end of file From 6e644a39211664157145c4bab890ac7f7f4e0288 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Mon, 7 Feb 2011 15:48:34 +0800 Subject: [PATCH 16/17] Version bump to 0.1.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 1750564..6c6aa7c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.6 +0.1.0 \ No newline at end of file From 7fa03c7d62093b39297f9868bd12f97fbfd0227f Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Mon, 7 Feb 2011 15:48:37 +0800 Subject: [PATCH 17/17] Regenerate gemspec for version 0.1.0 --- redfinger.gemspec | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/redfinger.gemspec b/redfinger.gemspec index d6972da..decd057 100644 --- a/redfinger.gemspec +++ b/redfinger.gemspec @@ -1,52 +1,50 @@ # Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command +# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = %q{redfinger} - s.version = "0.0.6" + s.version = "0.1.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Michael Bleigh"] - s.date = %q{2010-08-10} + s.date = %q{2011-02-07} s.description = %q{A Ruby Webfinger client} s.email = %q{michael@intridea.com} s.extra_rdoc_files = [ "LICENSE", - "README.rdoc" + "README.rdoc" ] s.files = [ ".document", - ".gitignore", - "LICENSE", - "README.rdoc", - "Rakefile", - "VERSION", - "lib/redfinger.rb", - "lib/redfinger/client.rb", - "lib/redfinger/finger.rb", - "lib/redfinger/link.rb", - "lib/redfinger/link_helpers.rb", - "redfinger.gemspec", - "spec/redfinger/client_spec.rb", - "spec/redfinger_spec.rb", - "spec/spec.opts", - "spec/spec_helper.rb" + ".rspec", + "LICENSE", + "README.rdoc", + "Rakefile", + "VERSION", + "lib/redfinger.rb", + "lib/redfinger/client.rb", + "lib/redfinger/finger.rb", + "lib/redfinger/link.rb", + "lib/redfinger/link_helpers.rb", + "redfinger.gemspec", + "spec/redfinger/client_spec.rb", + "spec/redfinger_spec.rb", + "spec/spec.opts", + "spec/spec_helper.rb" ] s.homepage = %q{http://github.com/mbleigh/redfinger} - s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.7} + s.rubygems_version = %q{1.5.0} s.summary = %q{A Ruby WebFinger client.} s.test_files = [ "spec/redfinger/client_spec.rb", - "spec/redfinger_spec.rb", - "spec/spec_helper.rb" + "spec/redfinger_spec.rb", + "spec/spec_helper.rb" ] if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then