webfinger_test.rb
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require_relative '../test_helper'
class WebfingerTest < ActiveSupport::TestCase
def setup
Domain.create(name: 'example.com')
Environment.default.domains << Domain.last
User.create(login: 'ze', email: 'ze@localdomain.localdomain',
password: 'zeze', password_confirmation: 'zeze')
end
should 'return correct user via webfinger url' do
get '.well-known/webfinger?resource=acct%3Aze%40example.com'
webfinger = JSON.parse(last_response.body)
assert_equal 200, last_response.status
assert_equal webfinger['subject'], 'acct:ze@example.com'
end
should 'not return json when user not found' do
invalid_user = 'invalid_user_in_url'
get ".well-known/webfinger?resource=acct%3A#{invalid_user}%40example.com"
assert_equal 404, last_response.status
end
should 'return correct article via webfinger url' do
a = fast_create(Article, name: 'my article', profile_id: 1)
get ".well-known/webfinger?resource=http://example.com/article/id/#{a.id}"
webfinger = JSON.parse(last_response.body)
assert_equal 200, last_response.status
assert_equal webfinger['subject'], "http://example.com/article/id/#{a.id}"
end
should 'not return json when domain is invalid' do
invalid_domain = 'doest_not_exist.com'
get ".well-known/webfinger?resource=http://#{invalid_domain}/article/id/1"
assert_equal 404, last_response.status
end
should 'not return json when entity is not found' do
get '.well-known/webfinger?resource=http://example.com/article/id/999999'
assert_equal 404, last_response.status
end
should 'not return json when entity does not exist' do
get '.well-known/webfinger?resource=http://example.com/doest_not_exist/id/1'
assert_equal 404, last_response.status
end
should 'not return json when request is not http' do
not_http_url = 'kkttc://example.com/article/id/1'
get ".well-known/webfinger?resource=#{not_http_url}"
assert_equal 404, last_response.status
end
end