From 31d6c40d05b265eef544834eb4b02240fa4a3739 Mon Sep 17 00:00:00 2001 From: Alessandro Caetano Date: Wed, 1 Jun 2016 11:22:34 -0400 Subject: [PATCH] Finishing webfinger server --- app/api/federation/webfinger.rb | 42 ++++++++++++++++++++---------------------- test/api/federation/webfinger_test.rb | 4 ++-- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/app/api/federation/webfinger.rb b/app/api/federation/webfinger.rb index b9c1878..9e9aa6a 100644 --- a/app/api/federation/webfinger.rb +++ b/app/api/federation/webfinger.rb @@ -41,31 +41,29 @@ end def acct_hash rails = Rails::Server.new - acct = Hash.new{|hash, key| hash[key] = - Hash.new{|hash, key| hash[key] = Array.new}} - - person = Person.find_by_identifier(extract_person_identifier) + acct = Hash.new{|hash, key| hash[key] = Hash.new{|hash, key| hash[key] = Array.new}} url = rails.options[:Host] + ':' + rails.options[:Port].to_s + '/' - - acct[:subject] = params[:resource] - acct[:alias] = url + person.identifier - acct[:properties][:identifier] = person.identifier - acct[:properties][:created_at] = person.created_at - for blog in person.blogs do - acct[:links][:rel] << url + 'rel/' + blog.path - acct[:links][:href] << url + person.identifier + '/' + blog.path - end - - for galleries in person.articles.galleries do - acct[:links][:rel] << url + 'rel/' + galleries.path - acct[:links][:href] << url + person.identifier + '/' + galleries.path - end - - acct[:titles][:name] = person.name - - if acct[:properties].nil? + person = Person.find_by_identifier(extract_person_identifier) + + if person.nil? Rails.logger.error 'Person not found' not_found! + else + acct[:subject] = params[:resource] + acct[:alias] = url + person.identifier + acct[:properties][:identifier] = person.identifier + acct[:properties][:created_at] = person.created_at + for blog in person.blogs do + acct[:links][:rel] << url + 'rel/' + blog.path + acct[:links][:href] << url + person.identifier + '/' + blog.path + end + + for galleries in person.articles.galleries do + acct[:links][:rel] << url + 'rel/' + galleries.path + acct[:links][:href] << url + person.identifier + '/' + galleries.path + end + + acct[:titles][:name] = person.name end acct end diff --git a/test/api/federation/webfinger_test.rb b/test/api/federation/webfinger_test.rb index f6e3784..69f31ac 100644 --- a/test/api/federation/webfinger_test.rb +++ b/test/api/federation/webfinger_test.rb @@ -4,7 +4,8 @@ class WebfingerTest < ActiveSupport::TestCase def setup Domain.create(name: 'example.com') Environment.default.domains << Domain.last - login_api + User.create(login: 'ze', email: 'ze@localdomain.localdomain', + password: 'zeze', password_confirmation: 'zeze') end should 'return correct user via webfinger url' do @@ -22,7 +23,6 @@ class WebfingerTest < ActiveSupport::TestCase should 'return correct article via webfinger url' do a = fast_create(Article, name: 'my article', profile_id: 1) - a.save get ".well-known/webfinger?resource=http://example.com/article/id/#{a.id}" webfinger = JSON.parse(last_response.body) assert_equal 200, last_response.status -- libgit2 0.21.2