Rename EMWebfinger to Webfinger, clean up some related things
This commit is contained in:
parent
be00a2f1b3
commit
db0106f13c
12 changed files with 51 additions and 44 deletions
|
|
@ -116,14 +116,13 @@ class PeopleController < ApplicationController
|
|||
end
|
||||
end
|
||||
def webfinger(account, opts = {})
|
||||
finger = EMWebfinger.new(account)
|
||||
finger.on_person do |response|
|
||||
if response.class == Person
|
||||
finger = Webfinger.new(account)
|
||||
begin
|
||||
result = finger.fetch
|
||||
response.socket_to_uid(current_user.id, opts)
|
||||
else
|
||||
require File.join(Rails.root,'lib/diaspora/websocket')
|
||||
Diaspora::WebSocket.queue_to_user(current_user.id, {:class => 'people', :status => 'fail', :query => account, :response => response}.to_json)
|
||||
end
|
||||
rescue
|
||||
require File.join(Rails.root,'lib/diaspora/web_socket')
|
||||
Diaspora::WebSocket.queue_to_user(current_user.id, {:class => 'people', :status => 'fail', :query => account, :response => I18n.t('people.webfinger.fail')}.to_json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require File.join(Rails.root, 'lib/em-webfinger')
|
||||
require File.join(Rails.root, 'lib/webfinger')
|
||||
|
||||
class RequestsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class HandleValidator < ActiveModel::Validator
|
|||
end
|
||||
|
||||
class Comment
|
||||
require File.join(Rails.root, 'lib/diaspora/websocket')
|
||||
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
||||
require File.join(Rails.root, 'lib/youtube_titles')
|
||||
include YoutubeTitles
|
||||
include MongoMapper::Document
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class Person
|
|||
include MongoMapper::Document
|
||||
include ROXML
|
||||
include Encryptor::Public
|
||||
require File.join(Rails.root, 'lib/diaspora/websocket')
|
||||
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
||||
include Diaspora::Socketable
|
||||
|
||||
xml_accessor :_id
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
class Post
|
||||
require File.join(Rails.root, 'lib/encryptable')
|
||||
require File.join(Rails.root, 'lib/diaspora/websocket')
|
||||
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
||||
include MongoMapper::Document
|
||||
include ApplicationHelper
|
||||
include ROXML
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
||||
|
||||
en:
|
||||
|
||||
settings: "Settings"
|
||||
profile: "Profile"
|
||||
account: "Account"
|
||||
|
|
@ -302,6 +301,8 @@ en:
|
|||
add_contact: "add contact"
|
||||
index:
|
||||
results_for: "search results for"
|
||||
webfinger:
|
||||
fail: "Sorry, we couldn't find %{handle}."
|
||||
show:
|
||||
no_posts: "no posts to display!"
|
||||
incoming_request: "You have an incoming request from this person."
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
require File.join(Rails.root, 'lib/em-webfinger')
|
||||
require File.join(Rails.root, 'lib/webfinger')
|
||||
|
||||
module Diaspora
|
||||
module UserModules
|
||||
module Receiving
|
||||
def receive_salmon salmon_xml
|
||||
salmon = Salmon::SalmonSlap.parse salmon_xml, self
|
||||
webfinger = EMWebfinger.new(salmon.author_email)
|
||||
webfinger = Webfinger.new(salmon.author_email)
|
||||
begin
|
||||
salmon_author = webfinger.fetch
|
||||
rescue Exception => e
|
||||
Rails.logger.info("event=receive status=abort recipient=#{self.diaspora_handle} sender=#{salmon.author_email} reason='#{e.message}'")
|
||||
end
|
||||
|
||||
if salmon_author
|
||||
if salmon.verified_for_key?(salmon_author.public_key)
|
||||
self.receive(salmon.parsed_data, salmon_author)
|
||||
else
|
||||
Rails.logger.info("event=receive status=abort recipient=#{self.diaspora_handle} sender=#{salmon.author_email} reason='not_verified for key'")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def receive xml, salmon_author
|
||||
object = Diaspora::Parser.from_xml(xml)
|
||||
|
|
@ -41,7 +39,7 @@ module Diaspora
|
|||
return
|
||||
end
|
||||
|
||||
e = EMWebfinger.new(object.diaspora_handle)
|
||||
e = Webfinger.new(object.diaspora_handle)
|
||||
|
||||
begin
|
||||
person = e.fetch
|
||||
|
|
|
|||
|
|
@ -1,33 +1,35 @@
|
|||
require File.join(Rails.root, 'lib/hcard')
|
||||
require File.join(Rails.root, 'lib/webfinger_profile')
|
||||
|
||||
class EMWebfinger
|
||||
class Webfinger
|
||||
class WebfingerFailedError < RuntimeError; end
|
||||
TIMEOUT = 5
|
||||
REDIRECTS = 3
|
||||
OPTS = {:timeout => TIMEOUT, :redirects => REDIRECTS}
|
||||
def initialize(account)
|
||||
@account = account.strip.gsub('acct:','').to_s
|
||||
@ssl = true
|
||||
Rails.logger.info("event=EMWebfinger status=initialized target=#{account}")
|
||||
# Raise an error if identifier has a port number
|
||||
#raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
||||
# Raise an error if identifier is not a valid email (generous regexp)
|
||||
#raise "Identifier is invalid" if !(@account=~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)
|
||||
Rails.logger.info("event=webfinger status=initialized target=#{account}")
|
||||
end
|
||||
|
||||
def fetch
|
||||
person = Person.by_account_identifier(@account)
|
||||
if person
|
||||
Rails.logger.info("event=EMWebfinger status=local target=#{@account}")
|
||||
Rails.logger.info("event=webfinger status=success route=local target=#{@account}")
|
||||
return person
|
||||
else
|
||||
Rails.logger.info("event=EMWebfinger status=remote target=#{@account}")
|
||||
end
|
||||
|
||||
profile_url = get_xrd
|
||||
webfinger_profile = get_webfinger_profile(profile_url)
|
||||
fingered_person = make_person_from_webfinger(webfinger_profile)
|
||||
if fingered_person
|
||||
Rails.logger.info("event=webfinger status=success route=remote target=#{@account}")
|
||||
fingered_person
|
||||
else
|
||||
Rails.logger.info("event=webfinger status=failure route=remote target=#{@account}")
|
||||
raise WebfingerFailedError.new(@account)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
require File.dirname(__FILE__) + '/../lib/diaspora/websocket'
|
||||
require File.dirname(__FILE__) + '/../lib/diaspora/web_socket'
|
||||
|
||||
at_exit do
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -94,6 +94,13 @@ describe PeopleController do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#retrieve_remote' do
|
||||
it 'sockets a local user' do
|
||||
Diaspora::WebSocket.should_receive(:queue_to_user).with(user.id, anything)
|
||||
get :retrieve_remote, :diaspora_handle => user.diaspora_handle
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
context 'with a profile photo set' do
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -4,15 +4,15 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
require File.join(Rails.root, 'lib/em-webfinger')
|
||||
require File.join(Rails.root, 'lib/webfinger')
|
||||
|
||||
describe EMWebfinger do
|
||||
describe Webfinger do
|
||||
let(:user1) { make_user }
|
||||
let(:user2) { make_user }
|
||||
|
||||
let(:account) {"foo@tom.joindiaspora.com"}
|
||||
let(:person){ Factory(:person, :diaspora_handle => account)}
|
||||
let(:finger){EMWebfinger.new(account)}
|
||||
let(:finger){Webfinger.new(account)}
|
||||
|
||||
|
||||
let(:good_request) { FakeHttpRequest.new(:success)}
|
||||
|
|
@ -32,12 +32,12 @@ describe EMWebfinger do
|
|||
|
||||
describe '#intialize' do
|
||||
it 'sets account ' do
|
||||
n = EMWebfinger.new("mbs348@gmail.com")
|
||||
n = Webfinger.new("mbs348@gmail.com")
|
||||
n.instance_variable_get(:@account).should_not be nil
|
||||
end
|
||||
|
||||
it 'should set ssl as the default' do
|
||||
foo = EMWebfinger.new(account)
|
||||
foo = Webfinger.new(account)
|
||||
foo.instance_variable_get(:@ssl).should be true
|
||||
end
|
||||
end
|
||||
|
|
@ -83,13 +83,13 @@ describe EMWebfinger do
|
|||
RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml)
|
||||
#new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com")
|
||||
# http://tom.joindiaspora.com/.well-known/host-meta
|
||||
f = EMWebfinger.new("tom@tom.joindiaspora.com").fetch
|
||||
f = Webfinger.new("tom@tom.joindiaspora.com").fetch
|
||||
f.should be_valid
|
||||
|
||||
end
|
||||
|
||||
it 'should retry with http if https fails' do
|
||||
f = EMWebfinger.new("tom@tom.joindiaspora.com")
|
||||
f = Webfinger.new("tom@tom.joindiaspora.com")
|
||||
|
||||
diaspora_xrd.stub!(:body).and_return(diaspora_xrd)
|
||||
RestClient.should_receive(:get).twice.and_return(nil, diaspora_xrd)
|
||||
|
|
|
|||
Loading…
Reference in a new issue