diff --git a/Changelog.md b/Changelog.md index 247c73535..9608a68b6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ * Extract StatusMessageService from StatusMessagesController [#6280](https://github.com/diaspora/diaspora/pull/6280) * Refactor HomeController#toggle\_mobile [#6260](https://github.com/diaspora/diaspora/pull/6260) * Extract CommentService from CommentsController [#6307](https://github.com/diaspora/diaspora/pull/6307) +* Extract user/profile discovery into the diaspora\_federation-rails gem [#6310](https://github.com/diaspora/diaspora/pull/6310) ## Bug fixes * Fix indentation and a link title on the default home page [#6212](https://github.com/diaspora/diaspora/pull/6212) diff --git a/app/models/person.rb b/app/models/person.rb index e24b4af21..a242af670 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -265,32 +265,6 @@ class Person < ActiveRecord::Base where(guid: guid, closed_account: false).where.not(owner: nil).take end - def self.create_from_webfinger(profile, hcard) - return nil if profile.nil? || !profile.valid_diaspora_profile? - new_person = Person.new - new_person.serialized_public_key = profile.public_key - new_person.guid = profile.guid - new_person.diaspora_handle = profile.account - new_person.url = profile.seed_location - - #hcard_profile = HCard.find profile.hcard.first[:href] - ::Logging::Logger[self].info "event=webfinger_marshal valid=#{new_person.valid?} " \ - "target=#{new_person.diaspora_handle}" - new_person.assign_new_profile_from_hcard(hcard) - new_person.save! - new_person.profile.save! - new_person - end - - def assign_new_profile_from_hcard(hcard) - self.profile = Profile.new(:first_name => hcard[:given_name], - :last_name => hcard[:family_name], - :image_url => hcard[:photo], - :image_url_medium => hcard[:photo_medium], - :image_url_small => hcard[:photo_small], - :searchable => hcard[:searchable]) - end - def remote? owner_id.nil? end diff --git a/config/initializers/load_libraries.rb b/config/initializers/load_libraries.rb index f0dfd8c0c..86d701d33 100644 --- a/config/initializers/load_libraries.rb +++ b/config/initializers/load_libraries.rb @@ -14,13 +14,10 @@ require 'diaspora' require 'direction_detector' require 'email_inviter' require 'evil_query' -require 'h_card' require 'hydra_wrapper' require 'postzord' require 'publisher' require 'pubsubhubbub' require 'salmon' require 'stream' -require 'webfinger' -require 'webfinger_profile' require 'account_deleter' diff --git a/lib/h_card.rb b/lib/h_card.rb deleted file mode 100644 index 2fda6aa2e..000000000 --- a/lib/h_card.rb +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -module HCard - def self.parse(doc) - { - given_name: doc.css(".given_name").text, - family_name: doc.css(".family_name").text, - url: doc.css("#pod_location").text, - photo: doc.css(".entity_photo .photo[src]").attribute("src").text, - photo_small: doc.css(".entity_photo_small .photo[src]").attribute("src").text, - photo_medium: doc.css(".entity_photo_medium .photo[src]").attribute("src").text, - searchable: doc.css(".searchable").text == "true" - } - end - - def self.build(raw_hcard) - parse Nokogiri::HTML(raw_hcard) - end -end diff --git a/lib/webfinger.rb b/lib/webfinger.rb deleted file mode 100644 index 5c28a4e90..000000000 --- a/lib/webfinger.rb +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright (c) 2010-2012, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -class Webfinger - include Diaspora::Logging - - attr_accessor :host_meta_xrd, :webfinger_profile_xrd, - :webfinger_profile, :hcard, :hcard_xrd, :person, - :account, :ssl - - def initialize(account) - self.account = account - self.ssl = true - end - - - def fetch - return person if existing_person_with_profile? - create_or_update_person_from_webfinger_profile! - end - - def self.in_background(account, opts={}) - Workers::FetchWebfinger.perform_async(account) - end - - #everything below should be private I guess - def account=(str) - @account = str.strip.gsub('acct:','').to_s.downcase - end - - def get(url) - logger.info "Getting: #{url} for #{account}" - begin - res = Faraday.get(url) - unless res.success? - raise "Failed to fetch #{url}: #{res.status}" - end - res.body - rescue OpenSSL::SSL::SSLError => e - logger.error "Failed to fetch #{url}: SSL setup invalid" - raise e - rescue => e - logger.error "Failed to fetch: #{url} for #{account}; #{e.message}" - raise e - end - end - - def existing_person_with_profile? - cached_person.present? && cached_person.profile.present? - end - - def cached_person - self.person ||= Person.by_account_identifier(account) - end - - def create_or_update_person_from_webfinger_profile! - logger.info "webfingering #{account}, it is not known or needs updating" - if person #update my profile please - person.assign_new_profile_from_hcard(self.hcard) - else - person = make_person_from_webfinger - end - logger.info "successfully webfingered #{@account}" if person - person - end - - #this tries the xrl url with https first, then falls back to http - def host_meta_xrd - begin - get(host_meta_url) - rescue => e - if self.ssl - self.ssl = false - retry - else - raise "there was an error getting the xrd from account #{@account}: #{e.message}" - end - end - end - - - def hcard - @hcard ||= HCard.build(hcard_xrd) - end - - def webfinger_profile - @webfinger_profile ||= WebfingerProfile.new(account, webfinger_profile_xrd) - end - - def hcard_url - self.webfinger_profile.hcard - end - - def webfinger_profile_url - doc = Nokogiri::XML(self.host_meta_xrd) - return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0" - swizzle doc.search('Link').find{|x| x['rel']=='lrdd'}['template'] - end - - def webfinger_profile_xrd - @webfinger_profile_xrd ||= get(webfinger_profile_url) - logger.warn "#{@account} doesn't exists anymore" if @webfinger_profile_xrd == false - @webfinger_profile_xrd - end - - def hcard_xrd - @hcard_xrd ||= get(hcard_url) - end - - def make_person_from_webfinger - Person.create_from_webfinger(webfinger_profile, hcard) unless webfinger_profile_xrd == false - end - - def host_meta_url - domain = account.split('@')[1] - "http#{'s' if self.ssl}://#{domain}/.well-known/host-meta" - end - - def swizzle(template) - template.gsub('{uri}', account) - end -end diff --git a/lib/webfinger_profile.rb b/lib/webfinger_profile.rb deleted file mode 100644 index 44259e200..000000000 --- a/lib/webfinger_profile.rb +++ /dev/null @@ -1,53 +0,0 @@ -class WebfingerProfile - include Diaspora::Logging - - attr_accessor :webfinger_profile, :account, :links, :hcard, :guid, :public_key, :seed_location - - def initialize(account, webfinger_profile) - @account = account - @webfinger_profile = webfinger_profile - @links = {} - set_fields - end - - def valid_diaspora_profile? - !(@webfinger_profile.nil? || @account.nil? || @links.nil? || @hcard.nil? || - @guid.nil? || @public_key.nil? || @seed_location.nil? ) - end - - private - - def set_fields - doc = Nokogiri::XML.parse(webfinger_profile) - doc.remove_namespaces! - - account_string = doc.css('Subject').text.gsub('acct:', '').strip - - raise "account in profile(#{account_string}) and account requested (#{@account}) do not match" if account_string != @account - - doc.css('Link').each do |l| - rel = text_of_attribute(l, 'rel') - href = text_of_attribute(l, 'href') - @links[rel] = href - case rel - when "http://microformats.org/profile/hcard" - @hcard = href - when "http://joindiaspora.com/guid" - @guid = href - when "http://joindiaspora.com/seed_location" - @seed_location = href - end - end - - begin - pubkey = text_of_attribute( doc.at('Link[rel=diaspora-public-key]'), 'href') - @public_key = Base64.decode64 pubkey - rescue => e - logger.warn "event=invalid_profile identifier=#{@account}" - end - end - - def text_of_attribute(doc, attr) - doc.attribute(attr) ? doc.attribute(attr).text : nil - end -end diff --git a/spec/controllers/diaspora_federation_controller_spec.rb b/spec/controllers/diaspora_federation_controller_spec.rb deleted file mode 100644 index 8799220ee..000000000 --- a/spec/controllers/diaspora_federation_controller_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require "spec_helper" - -# this is temporarily needed for fixture generation -# TODO: remove this after the parsing is also in the diaspora_federation gem -describe DiasporaFederation do - routes { DiasporaFederation::Engine.routes } - - let(:fixture_path) { Rails.root.join("spec", "fixtures") } - - describe DiasporaFederation::WebfingerController, type: :controller do - it "generates the host_meta fixture", fixture: true do - get :host_meta - expect(response).to be_success - expect(response.body).to match(/webfinger/) - save_fixture(response.body, "host-meta", fixture_path) - end - - it "generates the webfinger fixture", fixture: true do - post :legacy_webfinger, "q" => alice.person.diaspora_handle - expect(response).to be_success - save_fixture(response.body, "webfinger", fixture_path) - end - end - - describe DiasporaFederation::HCardController, type: :controller do - it "generates the hCard fixture", fixture: true do - post :hcard, "guid" => alice.person.guid.to_s - expect(response).to be_success - save_fixture(response.body, "hcard", fixture_path) - end - end -end diff --git a/spec/fixtures/evan_hcard b/spec/fixtures/evan_hcard deleted file mode 100644 index 8944ef1e3..000000000 --- a/spec/fixtures/evan_hcard +++ /dev/null @@ -1,72 +0,0 @@ - - -
-
- -
-

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.
- -
-
-
-
-
- -
- diff --git a/spec/fixtures/finger_xrd b/spec/fixtures/finger_xrd deleted file mode 100644 index 5ede32d74..000000000 --- a/spec/fixtures/finger_xrd +++ /dev/null @@ -1,11 +0,0 @@ - - - acct:tom@tom.joindiaspora.com - "http://tom.joindiaspora.com/" - - - - - - - diff --git a/spec/fixtures/hcard_response b/spec/fixtures/hcard_response deleted file mode 100644 index 302c02430..000000000 --- a/spec/fixtures/hcard_response +++ /dev/null @@ -1,64 +0,0 @@ - -
-

Alexander Hamiltom

-
-
-

User profile

-
-
Nickname
-
- Alexander Hamiltom -
-
-
-
First name
-
- Alexander -
-
-
-
Family name
-
- Hamiltom -
-
-
-
Full name
-
- Alexander Hamiltom -
-
-
-
URL
-
- http://localhost:3000/ -
-
-
-
Photo
-
- -
-
-
-
Photo
-
- -
-
-
-
Photo
-
- -
-
-
-
Searchable
-
- false -
-
-
-
-
- diff --git a/spec/fixtures/host_xrd b/spec/fixtures/host_xrd deleted file mode 100644 index ca2d3b5fc..000000000 --- a/spec/fixtures/host_xrd +++ /dev/null @@ -1,7 +0,0 @@ - - - - Resource Descriptor - - diff --git a/spec/fixtures/nonseed_finger_xrd b/spec/fixtures/nonseed_finger_xrd deleted file mode 100644 index b26e7d15d..000000000 --- a/spec/fixtures/nonseed_finger_xrd +++ /dev/null @@ -1,15 +0,0 @@ - - acct:evan@status.net - acct:evan@evan.status.net - http://evan.status.net/user/1 - - - - - - - - - - - diff --git a/spec/helper_methods.rb b/spec/helper_methods.rb index e0df90faa..ad4371a34 100644 --- a/spec/helper_methods.rb +++ b/spec/helper_methods.rb @@ -19,46 +19,6 @@ module HelperMethods :receiving => true) end - def stub_success(address = 'abc@example.com', opts = {}) - 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 opts[:diaspora] || host.include?("diaspora") - 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 - File.open(File.dirname(__FILE__) + '/fixtures/host_xrd').read - end - - def finger_xrd - File.open(File.dirname(__FILE__) + '/fixtures/finger_xrd').read - end - - def hcard_response - File.open(File.dirname(__FILE__) + '/fixtures/hcard_response').read - end - - def nonseed_finger_xrd - File.open(File.dirname(__FILE__) + '/fixtures/nonseed_finger_xrd').read - end - - def evan_hcard - File.open(File.dirname(__FILE__) + '/fixtures/evan_hcard').read - end - def uploaded_photo fixture_filename = 'button.png' fixture_name = File.join(File.dirname(__FILE__), 'fixtures', fixture_filename) diff --git a/spec/lib/h_card_spec.rb b/spec/lib/h_card_spec.rb deleted file mode 100644 index d4197c0b4..000000000 --- a/spec/lib/h_card_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require "spec_helper" - -describe HCard do - it "should parse an hcard" do - raw_hcard = hcard_response - hcard = HCard.build raw_hcard - expect(hcard[:family_name].include?("Hamiltom")).to be true - expect(hcard[:given_name].include?("Alex")).to be true - expect(hcard[:photo].include?("thumb_large")).to be true - expect(hcard[:photo_medium].include?("thumb_medium")).to be true - expect(hcard[:photo_small].include?("thumb_small")).to be true - expect(hcard[:url]).to eq("http://localhost:3000/") - expect(hcard[:searchable]).to eq(false) - end - - it "should parse an hcard with searchable true" do - raw_hcard = hcard_response.sub("false", "true") - hcard = HCard.build raw_hcard - expect(hcard[:family_name].include?("Hamiltom")).to be true - expect(hcard[:given_name].include?("Alex")).to be true - expect(hcard[:photo].include?("thumb_large")).to be true - expect(hcard[:photo_medium].include?("thumb_medium")).to be true - expect(hcard[:photo_small].include?("thumb_small")).to be true - expect(hcard[:url]).to eq("http://localhost:3000/") - expect(hcard[:searchable]).to eq(true) - end - - it "should parse an hcard with empty searchable" do - raw_hcard = hcard_response.sub("false", "") - hcard = HCard.build raw_hcard - expect(hcard[:family_name].include?("Hamiltom")).to be true - expect(hcard[:given_name].include?("Alex")).to be true - expect(hcard[:photo].include?("thumb_large")).to be true - expect(hcard[:photo_medium].include?("thumb_medium")).to be true - expect(hcard[:photo_small].include?("thumb_small")).to be true - expect(hcard[:url]).to eq("http://localhost:3000/") - expect(hcard[:searchable]).to eq(false) - end -end diff --git a/spec/lib/webfinger_profile_spec.rb b/spec/lib/webfinger_profile_spec.rb deleted file mode 100644 index 51991f084..000000000 --- a/spec/lib/webfinger_profile_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'spec_helper' - -describe WebfingerProfile do - let(:webfinger_profile){File.open(Rails.root.join("spec", "fixtures", "finger_xrd")).read.strip} - let(:not_diaspora_webfinger){File.open(Rails.root.join("spec", "fixtures", "nonseed_finger_xrd")).read.strip} - - let(:account){"tom@tom.joindiaspora.com"} - let(:profile){ WebfingerProfile.new(account, webfinger_profile) } - - context "parsing a diaspora profile" do - - describe '#valid_diaspora_profile?' do - it 'should check all of the required fields' do - expect(manual_nil_check(profile)).to eq(profile.valid_diaspora_profile?) - end - end - - describe '#set_fields' do - it 'should check to make sure it has a the right webfinger profile' do - expect{ WebfingerProfile.new("nottom@tom.joindiaspora.com", webfinger_profile)}.to raise_error - end - - it 'should handle a non-diaspora profile without blowing up' do - expect{ WebfingerProfile.new("evan@status.net", not_diaspora_webfinger)}.not_to raise_error - end - - [:links, :hcard, :guid, :seed_location, :public_key].each do |field| - it 'should sets the #{field} field' do - expect(profile.send(field)).to be_present - end - end - end - end - - def manual_nil_check(profile) - profile.instance_variables.each do |var| - var = var.to_s.gsub('@', '') - return false if profile.send(var).nil? == true - end - true - end -end diff --git a/spec/lib/webfinger_spec.rb b/spec/lib/webfinger_spec.rb deleted file mode 100644 index c3515bebe..000000000 --- a/spec/lib/webfinger_spec.rb +++ /dev/null @@ -1,221 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' - -describe Webfinger do - let(:host_meta_xrd) { File.open(Rails.root.join('spec', 'fixtures', 'host-meta.fixture.html')).read } - let(:webfinger_xrd) { File.open(Rails.root.join('spec', 'fixtures', 'webfinger.fixture.html')).read } - let(:hcard_xml) { File.open(Rails.root.join('spec', 'fixtures', 'hcard.fixture.html')).read } - let(:account){'foo@bar.com'} - let(:account_in_fixtures){"alice@localhost:9887"} - let(:finger){Webfinger.new(account)} - let(:host_meta_url){"http://#{AppConfig.pod_uri.authority}/webfinger?q="} - - describe '#intialize' do - it 'sets account ' do - n = Webfinger.new("mbs348@gmail.com") - expect(n.account).not_to be nil - end - - it "downcases account and strips whitespace, and gsub 'acct:'" do - n = Webfinger.new("acct:BIGBOY@Example.Org ") - expect(n.account).to eq('bigboy@example.org') - end - - it 'should set ssl as the default' do - foo = Webfinger.new(account) - expect(foo.ssl).to be true - end - end - - describe '.in_background' do - it 'enqueues a Workers::FetchWebfinger job' do - expect(Workers::FetchWebfinger).to receive(:perform_async).with(account) - Webfinger.in_background(account) - end - end - - describe '#fetch' do - it 'works' do - finger = Webfinger.new(account_in_fixtures) - allow(finger).to receive(:host_meta_xrd).and_return(host_meta_xrd) - allow(finger).to receive(:hcard_xrd).and_return(hcard_xml) - allow(finger).to receive(:webfinger_profile_xrd).and_return(webfinger_xrd) - person = finger.fetch - expect(person).to be_valid - expect(person).to be_a Person - end - - end - - describe '#get' do - it 'makes a request and grabs the body' do - url ="https://bar.com/.well-known/host-meta" - stub_request(:get, url). - to_return(:status => 200, :body => host_meta_xrd) - - expect(finger.get(url)).to eq(host_meta_xrd) - end - - it 'follows redirects' do - redirect_url = "http://whereami.whatisthis/host-meta" - - stub_request(:get, "https://bar.com/.well-known/host-meta"). - to_return(:status => 302, :headers => { 'Location' => redirect_url }) - - stub_request(:get, redirect_url). - to_return(:status => 200, :body => host_meta_xrd) - - finger.host_meta_xrd - - expect(a_request(:get, redirect_url)).to have_been_made - end - - it 'raises on 404' do - url ="https://bar.com/.well-known/host-meta" - stub_request(:get, url). - to_return(:status => 404, :body => nil) - - expect { - expect(finger.get(url)).to eq(false) - }.to raise_error - end - end - - describe 'existing_person_with_profile?' do - it 'returns true if cached_person is present and has a profile' do - expect(finger).to receive(:cached_person).twice.and_return(FactoryGirl.create(:person)) - expect(finger.existing_person_with_profile?).to be true - end - - it 'returns false if it has no person' do - allow(finger).to receive(:cached_person).and_return false - expect(finger.existing_person_with_profile?).to be false - end - - it 'returns false if the person has no profile' do - p = FactoryGirl.create(:person) - p.profile = nil - allow(finger).to receive(:cached_person).and_return(p) - expect(finger.existing_person_with_profile?).to be false - end - end - - describe 'cached_person' do - it 'sets the person by looking up the account from Person.by_account_identifier' do - person = double - expect(Person).to receive(:by_account_identifier).with(account).and_return(person) - expect(finger.cached_person).to eq(person) - expect(finger.person).to eq(person) - end - end - - - describe 'create_or_update_person_from_webfinger_profile!' do - context 'with a cached_person' do - it 'calls Person#assign_new_profile_from_hcard with the fetched hcard' do - finger.hcard_xrd = hcard_xml - allow(finger).to receive(:person).and_return(bob.person) - expect(bob.person).to receive(:assign_new_profile_from_hcard).with(finger.hcard) - finger.create_or_update_person_from_webfinger_profile! - end - end - - context 'with no cached person' do - it 'sets person based on make_person_from_webfinger' do - allow(finger).to receive(:person).and_return(nil) - expect(finger).to receive(:make_person_from_webfinger) - finger.create_or_update_person_from_webfinger_profile! - end - end - end - - describe '#host_meta_xrd' do - it 'calls #get with host_meta_url' do - allow(finger).to receive(:host_meta_url).and_return('meta') - expect(finger).to receive(:get).with('meta') - finger.host_meta_xrd - end - - it 'should retry with ssl off a second time' do - expect(finger).to receive(:get).and_raise(StandardError) - expect(finger).to receive(:get) - finger.host_meta_xrd - expect(finger.ssl).to be false - end - end - - describe '#hcard' do - it 'calls HCard.build' do - allow(finger).to receive(:hcard_xrd).and_return(hcard_xml) - expect(HCard).to receive(:build).with(hcard_xml).and_return true - expect(finger.hcard).not_to be_nil - end - end - - describe '#webfinger_profile' do - it 'constructs a new WebfingerProfile object' do - allow(finger).to receive(:webfinger_profile_xrd).and_return(webfinger_xrd) - expect(WebfingerProfile).to receive(:new).with(account, webfinger_xrd) - finger.webfinger_profile - end - end - - describe '#webfinger_profile_url' do - it 'returns the llrd link for a valid host meta' do - allow(finger).to receive(:host_meta_xrd).and_return(host_meta_xrd) - expect(finger.webfinger_profile_url).not_to be_nil - end - - it 'returns nil if no link is found' do - allow(finger).to receive(:host_meta_xrd).and_return(nil) - expect(finger.webfinger_profile_url).to be_nil - end - end - - describe '#webfinger_profile_xrd' do - it 'calls #get with the hcard_url' do - allow(finger).to receive(:hcard_url).and_return("url") - expect(finger).to receive(:get).with("url") - finger.hcard_xrd - end - end - - describe '#make_person_from_webfinger' do - it 'with an hcard and a webfinger_profile, it calls Person.create_from_webfinger' do - allow(finger).to receive(:hcard).and_return("hcard") - allow(finger).to receive(:webfinger_profile_xrd).and_return("webfinger_profile_xrd") - allow(finger).to receive(:webfinger_profile).and_return("webfinger_profile") - expect(Person).to receive(:create_from_webfinger).with("webfinger_profile", "hcard") - finger.make_person_from_webfinger - end - - it 'with an false xrd it does not call Person.create_from_webfinger' do - allow(finger).to receive(:webfinger_profile_xrd).and_return(false) - expect(Person).not_to receive(:create_from_webfinger) - finger.make_person_from_webfinger - end - end - - - - describe '#host_meta_url' do - it 'should return canonical host-meta url for http' do - finger.ssl = false - expect(finger.host_meta_url).to eq("http://bar.com/.well-known/host-meta") - end - - it 'can return the https version' do - expect(finger.host_meta_url).to eq("https://bar.com/.well-known/host-meta") - end - end - - describe 'swizzle' do - it 'gsubs out {uri} for the account' do - string = "{uri} is the coolest" - expect(finger.swizzle(string)).to eq("#{finger.account} is the coolest") - end - end -end