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