Commit 8e4458d15ba4eb9adbd5f6ae382b04c4c7d53651
1 parent
ec98aeed
Exists in
federation_webfinger
and in
1 other branch
Writing tests for webfinger entry point
Showing
2 changed files
with
21 additions
and
13 deletions
Show diff stats
lib/noosfero/api/federation/webfinger.rb
@@ -27,8 +27,8 @@ def valid_domain? | @@ -27,8 +27,8 @@ def valid_domain? | ||
27 | domain = params[:resource].split("@")[1] | 27 | domain = params[:resource].split("@")[1] |
28 | environment.domains.map(&:name).include? domain | 28 | environment.domains.map(&:name).include? domain |
29 | else | 29 | else |
30 | - #please validate domain with http | ||
31 | - false | 30 | + domain = params[:resource].split("/")[2] |
31 | + environment.domains.map(&:name).include? domain | ||
32 | end | 32 | end |
33 | end | 33 | end |
34 | 34 | ||
@@ -44,16 +44,16 @@ def acct_hash | @@ -44,16 +44,16 @@ def acct_hash | ||
44 | end | 44 | end |
45 | 45 | ||
46 | def extract_person_identifier | 46 | def extract_person_identifier |
47 | - person = params[:resource].split("@")[0].split(":")[1] | 47 | + params[:resource].split("@")[0].split(":")[1] |
48 | end | 48 | end |
49 | 49 | ||
50 | def valid_uri?(url) | 50 | def valid_uri?(url) |
51 | uri = URI.parse(url) | 51 | uri = URI.parse(url) |
52 | uri.kind_of?(URI::HTTP) | 52 | uri.kind_of?(URI::HTTP) |
53 | - rescue URI::BadURIError | ||
54 | - "URI is valid, bad usage is not" | ||
55 | - rescue URI::InvalidURIError | ||
56 | - "invalid URI" | 53 | + rescue URI::BadURIError => ex |
54 | + Rails.logger.error "Bad URI Error: #{ex}" | ||
55 | + rescue URI::InvalidURIError => ex | ||
56 | + Rails.logger.error "Invalid URI Error: #{ex}" | ||
57 | end | 57 | end |
58 | 58 | ||
59 | def uri_hash | 59 | def uri_hash |
@@ -62,7 +62,6 @@ def uri_hash | @@ -62,7 +62,6 @@ def uri_hash | ||
62 | entity = entity_exists?(params[:resource]) | 62 | entity = entity_exists?(params[:resource]) |
63 | id = params[:resource].split('/').last.to_i | 63 | id = params[:resource].split('/').last.to_i |
64 | uri[:properties] = entity.classify.constantize.find(id) | 64 | uri[:properties] = entity.classify.constantize.find(id) |
65 | - puts uri.inspect | ||
66 | uri | 65 | uri |
67 | end | 66 | end |
68 | 67 | ||
@@ -70,7 +69,6 @@ def entity_exists?(uri) | @@ -70,7 +69,6 @@ def entity_exists?(uri) | ||
70 | possible_entity = uri.split('/') | 69 | possible_entity = uri.split('/') |
71 | possible_entity.map! {|entity| "#{entity}s"} | 70 | possible_entity.map! {|entity| "#{entity}s"} |
72 | ( ActiveRecord::Base.connection.tables & possible_entity ).first | 71 | ( ActiveRecord::Base.connection.tables & possible_entity ).first |
73 | - rescue ActiveRecord::RecordNotFound | ||
74 | - false | 72 | + rescue ActiveRecord::RecordNotFound => ex |
73 | + Rails.logger.error "Entity not found on records: #{ex}" | ||
75 | end | 74 | end |
76 | - |
test/api/federation/webfinger_test.rb
@@ -3,10 +3,20 @@ require_relative '../test_helper' | @@ -3,10 +3,20 @@ require_relative '../test_helper' | ||
3 | class WebfingerTest < ActiveSupport::TestCase | 3 | class WebfingerTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | + login_api | ||
6 | end | 7 | end |
7 | 8 | ||
8 | - should 'list tasks of environment' do | ||
9 | - assert_equal true, true | 9 | + should 'return correct user via webfinger url' do |
10 | + get '.well-known/webfinger?resource=acct%3Aze%40example.com' | ||
11 | + webfinger = JSON.parse(last_response.body) | ||
12 | + assert_equal 200, last_response.status | ||
13 | + assert_equal webfinger['subject'], 'acct:ze@example.com' | ||
10 | end | 14 | end |
11 | 15 | ||
16 | + should 'return correct article via webfinger url' do | ||
17 | + get '.well-known/webfinger?resource=http://example.com/article/id/1' | ||
18 | + webfinger = JSON.parse(last_response.body) | ||
19 | + assert_equal 200, last_response.status | ||
20 | + assert_equal webfinger['subject'], 'http://example.com/article/id/1' | ||
21 | + end | ||
12 | end | 22 | end |