mirror of https://github.com/mastodon/goldfinger
Adding tests
This commit is contained in:
parent
724f0c6a80
commit
fd04a39022
2
Gemfile
2
Gemfile
|
@ -1,5 +1,7 @@
|
||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
gem 'pry'
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'rspec', '>= 3.0'
|
gem 'rspec', '>= 3.0'
|
||||||
gem 'nyan-cat-formatter'
|
gem 'nyan-cat-formatter'
|
||||||
|
|
|
@ -10,6 +10,7 @@ GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
addressable (2.4.0)
|
addressable (2.4.0)
|
||||||
|
coderay (1.1.0)
|
||||||
crack (0.4.3)
|
crack (0.4.3)
|
||||||
safe_yaml (~> 1.0.0)
|
safe_yaml (~> 1.0.0)
|
||||||
diff-lcs (1.2.5)
|
diff-lcs (1.2.5)
|
||||||
|
@ -25,11 +26,16 @@ GEM
|
||||||
domain_name (~> 0.5)
|
domain_name (~> 0.5)
|
||||||
http-form_data (1.0.1)
|
http-form_data (1.0.1)
|
||||||
http_parser.rb (0.6.0)
|
http_parser.rb (0.6.0)
|
||||||
|
method_source (0.8.2)
|
||||||
mini_portile2 (2.0.0)
|
mini_portile2 (2.0.0)
|
||||||
nokogiri (1.6.7.2)
|
nokogiri (1.6.7.2)
|
||||||
mini_portile2 (~> 2.0.0.rc2)
|
mini_portile2 (~> 2.0.0.rc2)
|
||||||
nyan-cat-formatter (0.11)
|
nyan-cat-formatter (0.11)
|
||||||
rspec (>= 2.99, >= 2.14.2, < 4)
|
rspec (>= 2.99, >= 2.14.2, < 4)
|
||||||
|
pry (0.10.1)
|
||||||
|
coderay (~> 1.1.0)
|
||||||
|
method_source (~> 0.8.1)
|
||||||
|
slop (~> 3.4)
|
||||||
rspec (3.4.0)
|
rspec (3.4.0)
|
||||||
rspec-core (~> 3.4.0)
|
rspec-core (~> 3.4.0)
|
||||||
rspec-expectations (~> 3.4.0)
|
rspec-expectations (~> 3.4.0)
|
||||||
|
@ -44,6 +50,7 @@ GEM
|
||||||
rspec-support (~> 3.4.0)
|
rspec-support (~> 3.4.0)
|
||||||
rspec-support (3.4.1)
|
rspec-support (3.4.1)
|
||||||
safe_yaml (1.0.4)
|
safe_yaml (1.0.4)
|
||||||
|
slop (3.6.0)
|
||||||
unf (0.1.4)
|
unf (0.1.4)
|
||||||
unf_ext
|
unf_ext
|
||||||
unf_ext (0.0.7.2)
|
unf_ext (0.0.7.2)
|
||||||
|
@ -59,5 +66,6 @@ DEPENDENCIES
|
||||||
bundler (~> 1.3)
|
bundler (~> 1.3)
|
||||||
goldfinger!
|
goldfinger!
|
||||||
nyan-cat-formatter
|
nyan-cat-formatter
|
||||||
|
pry
|
||||||
rspec (>= 3.0)
|
rspec (>= 3.0)
|
||||||
webmock
|
webmock
|
||||||
|
|
|
@ -29,12 +29,13 @@ module Goldfinger
|
||||||
|
|
||||||
def parse_json
|
def parse_json
|
||||||
json = JSON.parse(@body)
|
json = JSON.parse(@body)
|
||||||
json['links'].each { |link| @links[link['rel']] = link['href'] }
|
json['links'].each { |link| @links[link['rel']] = Hash[link.keys.map { |key| [key.to_sym, link[key]] }] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_xml
|
def parse_xml
|
||||||
xml = Nokogiri::XML(@body)
|
xml = Nokogiri::XML(@body)
|
||||||
xml.xpath('//xmlns:Link', xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0').each { |link| @links[link.attribute('rel').value] = link.attribute('href').value }
|
links = xml.xpath('//xmlns:Link', xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0')
|
||||||
|
links.each { |link| @links[link.attribute('rel').value] = Hash[link.attributes.keys.map { |key| [key.to_sym, link.attribute(key).value] }] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
|
<Link rel="lrdd" type="application/jrd+json" template="https://quitter.no/.well-known/webfinger?resource={uri}"/>
|
||||||
|
<Link rel="lrdd" type="application/json" template="https://quitter.no/.well-known/webfinger?resource={uri}"/>
|
||||||
|
<Link rel="lrdd" type="application/xrd+xml" template="https://quitter.no/.well-known/webfinger?resource={uri}"/>
|
||||||
|
<Link rel="http://apinamespace.org/oauth/access_token" href="https://quitter.no/api/oauth/access_token"/>
|
||||||
|
<Link rel="http://apinamespace.org/oauth/request_token" href="https://quitter.no/api/oauth/request_token"/>
|
||||||
|
<Link rel="http://apinamespace.org/oauth/authorize" href="https://quitter.no/api/oauth/authorize"/>
|
||||||
|
</XRD>
|
|
@ -0,0 +1 @@
|
||||||
|
{"subject":"acct:gargron@quitter.no","aliases":["https:\/\/quitter.no\/user\/7477","https:\/\/quitter.no\/gargron"],"links":[{"rel":"http:\/\/webfinger.net\/rel\/profile-page","type":"text\/html","href":"https:\/\/quitter.no\/gargron"},{"rel":"http:\/\/gmpg.org\/xfn\/11","type":"text\/html","href":"https:\/\/quitter.no\/gargron"},{"rel":"describedby","type":"application\/rdf+xml","href":"https:\/\/quitter.no\/gargron\/foaf"},{"rel":"http:\/\/apinamespace.org\/atom","type":"application\/atomsvc+xml","href":"https:\/\/quitter.no\/api\/statusnet\/app\/service\/gargron.xml"},{"rel":"http:\/\/apinamespace.org\/twitter","href":"https:\/\/quitter.no\/api\/"},{"rel":"http:\/\/specs.openid.net\/auth\/2.0\/provider","href":"https:\/\/quitter.no\/gargron"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/quitter.no\/api\/statuses\/user_timeline\/7477.atom"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.1ZBkHTavLvxH3FzlKv4O6WtlILKRFfNami3_Rcu8EuogtXSYiS-bB6hElZfUCSHbC4uLemOA34PEhz__CDMozax1iI_t8dzjDnh1x0iFSup7pSfW9iXk_WU3Dm74yWWW2jildY41vWgrEstuQ1dJ8vVFfSJ9T_tO4c-T9y8vDI8=.AQAB"},{"rel":"salmon","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-replies","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-mention","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/quitter.no\/main\/ostatussub?profile={uri}"}]}
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
|
<Subject>acct:gargron@quitter.no</Subject>
|
||||||
|
<Alias>https://quitter.no/user/7477</Alias>
|
||||||
|
<Alias>https://quitter.no/gargron</Alias>
|
||||||
|
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="https://quitter.no/gargron"/>
|
||||||
|
<Link rel="http://gmpg.org/xfn/11" type="text/html" href="https://quitter.no/gargron"/>
|
||||||
|
<Link rel="describedby" type="application/rdf+xml" href="https://quitter.no/gargron/foaf"/>
|
||||||
|
<Link rel="http://apinamespace.org/atom" type="application/atomsvc+xml" href="https://quitter.no/api/statusnet/app/service/gargron.xml"/>
|
||||||
|
<Link rel="http://apinamespace.org/twitter" href="https://quitter.no/api/"/>
|
||||||
|
<Link rel="http://specs.openid.net/auth/2.0/provider" href="https://quitter.no/gargron"/>
|
||||||
|
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="https://quitter.no/api/statuses/user_timeline/7477.atom"/>
|
||||||
|
<Link rel="magic-public-key" href="data:application/magic-public-key,RSA.1ZBkHTavLvxH3FzlKv4O6WtlILKRFfNami3_Rcu8EuogtXSYiS-bB6hElZfUCSHbC4uLemOA34PEhz__CDMozax1iI_t8dzjDnh1x0iFSup7pSfW9iXk_WU3Dm74yWWW2jildY41vWgrEstuQ1dJ8vVFfSJ9T_tO4c-T9y8vDI8=.AQAB"/>
|
||||||
|
<Link rel="salmon" href="https://quitter.no/main/salmon/user/7477"/>
|
||||||
|
<Link rel="http://salmon-protocol.org/ns/salmon-replies" href="https://quitter.no/main/salmon/user/7477"/>
|
||||||
|
<Link rel="http://salmon-protocol.org/ns/salmon-mention" href="https://quitter.no/main/salmon/user/7477"/>
|
||||||
|
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="https://quitter.no/main/ostatussub?profile={uri}"/>
|
||||||
|
</XRD>
|
|
@ -1,5 +1,14 @@
|
||||||
describe Goldfinger::Client do
|
describe Goldfinger::Client do
|
||||||
describe '#finger' do
|
describe '#finger' do
|
||||||
pending
|
before do
|
||||||
|
stub_request(:get, 'https://quitter.no/.well-known/host-meta').to_return(body: fixture('quitter.no_.well-known_host-meta'))
|
||||||
|
stub_request(:get, 'https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no').to_return(body: fixture('quitter.no_.well-known_webfinger.json'))
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { Goldfinger::Client.new('acct:gargron@quitter.no') }
|
||||||
|
|
||||||
|
it 'returns a result' do
|
||||||
|
expect(subject.finger).to be_instance_of Goldfinger::Result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
describe Goldfinger::Request do
|
describe Goldfinger::Request do
|
||||||
describe '#perform' do
|
describe '#perform' do
|
||||||
pending
|
before do
|
||||||
|
stub_request(:get, 'example.com').to_return(body: 'OK')
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { Goldfinger::Request.new(:get, 'http://example.com').perform }
|
||||||
|
|
||||||
|
it 'returns the body' do
|
||||||
|
expect(subject.last.to_s).to eql 'OK'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,41 @@
|
||||||
describe Goldfinger::Result do
|
describe Goldfinger::Result do
|
||||||
describe '#links' do
|
context 'application/xrd+xml' do
|
||||||
pending
|
let(:headers) { h = HTTP::Headers.new; h.set(HTTP::Headers::CONTENT_TYPE, 'application/xrd+xml'); h }
|
||||||
|
let(:body) { File.read(fixture_path('quitter.no_.well-known_webfinger.xml')) }
|
||||||
|
|
||||||
|
subject { Goldfinger::Result.new(headers, body) }
|
||||||
|
|
||||||
|
describe '#links' do
|
||||||
|
it 'returns a non-empty array' do
|
||||||
|
expect(subject.links).to be_instance_of Array
|
||||||
|
expect(subject.links).to_not be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#link' do
|
||||||
|
it 'returns a value for a given rel' do
|
||||||
|
expect(subject.link('http://webfinger.net/rel/profile-page')[:href]).to eql 'https://quitter.no/gargron'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#link' do
|
context 'application/jrd+json' do
|
||||||
pending
|
let(:headers) { h = HTTP::Headers.new; h.set(HTTP::Headers::CONTENT_TYPE, 'application/jrd+json'); h }
|
||||||
end
|
let(:body) { File.read(fixture_path('quitter.no_.well-known_webfinger.json')) }
|
||||||
|
|
||||||
describe '#parse_xml' do
|
subject { Goldfinger::Result.new(headers, body) }
|
||||||
pending
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#parse_json' do
|
describe '#links' do
|
||||||
pending
|
it 'returns a non-empty array' do
|
||||||
|
expect(subject.links).to be_instance_of Array
|
||||||
|
expect(subject.links).to_not be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#link' do
|
||||||
|
it 'returns a value for a given rel' do
|
||||||
|
expect(subject.link('http://webfinger.net/rel/profile-page')[:href]).to eql 'https://quitter.no/gargron'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
describe Goldfinger::Utils do
|
|
||||||
pending
|
|
||||||
end
|
|
|
@ -1,5 +1,6 @@
|
||||||
require 'goldfinger'
|
require 'goldfinger'
|
||||||
require 'webmock/rspec'
|
require 'webmock/rspec'
|
||||||
|
require 'pry'
|
||||||
|
|
||||||
WebMock.disable_net_connect!
|
WebMock.disable_net_connect!
|
||||||
|
|
||||||
|
@ -14,3 +15,11 @@ RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fixture_path(path)
|
||||||
|
File.join(File.expand_path('../fixtures', __FILE__), path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fixture(path)
|
||||||
|
File.new(fixture_path(path))
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue