Commit 31d6c40d05b265eef544834eb4b02240fa4a3739

Authored by Alessandro Beltrão
1 parent 865242b1

Finishing webfinger server

app/api/federation/webfinger.rb
... ... @@ -41,31 +41,29 @@ end
41 41  
42 42 def acct_hash
43 43 rails = Rails::Server.new
44   - acct = Hash.new{|hash, key| hash[key] =
45   - Hash.new{|hash, key| hash[key] = Array.new}}
46   -
47   - person = Person.find_by_identifier(extract_person_identifier)
  44 + acct = Hash.new{|hash, key| hash[key] = Hash.new{|hash, key| hash[key] = Array.new}}
48 45 url = rails.options[:Host] + ':' + rails.options[:Port].to_s + '/'
49   -
50   - acct[:subject] = params[:resource]
51   - acct[:alias] = url + person.identifier
52   - acct[:properties][:identifier] = person.identifier
53   - acct[:properties][:created_at] = person.created_at
54   - for blog in person.blogs do
55   - acct[:links][:rel] << url + 'rel/' + blog.path
56   - acct[:links][:href] << url + person.identifier + '/' + blog.path
57   - end
58   -
59   - for galleries in person.articles.galleries do
60   - acct[:links][:rel] << url + 'rel/' + galleries.path
61   - acct[:links][:href] << url + person.identifier + '/' + galleries.path
62   - end
63   -
64   - acct[:titles][:name] = person.name
65   -
66   - if acct[:properties].nil?
  46 + person = Person.find_by_identifier(extract_person_identifier)
  47 +
  48 + if person.nil?
67 49 Rails.logger.error 'Person not found'
68 50 not_found!
  51 + else
  52 + acct[:subject] = params[:resource]
  53 + acct[:alias] = url + person.identifier
  54 + acct[:properties][:identifier] = person.identifier
  55 + acct[:properties][:created_at] = person.created_at
  56 + for blog in person.blogs do
  57 + acct[:links][:rel] << url + 'rel/' + blog.path
  58 + acct[:links][:href] << url + person.identifier + '/' + blog.path
  59 + end
  60 +
  61 + for galleries in person.articles.galleries do
  62 + acct[:links][:rel] << url + 'rel/' + galleries.path
  63 + acct[:links][:href] << url + person.identifier + '/' + galleries.path
  64 + end
  65 +
  66 + acct[:titles][:name] = person.name
69 67 end
70 68 acct
71 69 end
... ...
test/api/federation/webfinger_test.rb
... ... @@ -4,7 +4,8 @@ class WebfingerTest &lt; ActiveSupport::TestCase
4 4 def setup
5 5 Domain.create(name: 'example.com')
6 6 Environment.default.domains << Domain.last
7   - login_api
  7 + User.create(login: 'ze', email: 'ze@localdomain.localdomain',
  8 + password: 'zeze', password_confirmation: 'zeze')
8 9 end
9 10  
10 11 should 'return correct user via webfinger url' do
... ... @@ -22,7 +23,6 @@ class WebfingerTest &lt; ActiveSupport::TestCase
22 23  
23 24 should 'return correct article via webfinger url' do
24 25 a = fast_create(Article, name: 'my article', profile_id: 1)
25   - a.save
26 26 get ".well-known/webfinger?resource=http://example.com/article/id/#{a.id}"
27 27 webfinger = JSON.parse(last_response.body)
28 28 assert_equal 200, last_response.status
... ...