Compare commits

...

14 Commits

Author SHA1 Message Date
dependabot[bot] d013213138
Bump rake from 12.0.0 to 12.3.3 (#14)
Bumps [rake](https://github.com/ruby/rake) from 12.0.0 to 12.3.3.
- [Release notes](https://github.com/ruby/rake/releases)
- [Changelog](https://github.com/ruby/rake/blob/master/History.rdoc)
- [Commits](https://github.com/ruby/rake/compare/v12.0.0...v12.3.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-03-19 18:21:48 +01:00
Eugen Rochko 4f585464ba
Update gempush.yml 2020-01-12 15:31:29 +01:00
Eugen Rochko 62d296bb98
Bump version to 2.1.1 (#12)
* Bump version to 2.1.1

* Update README.md
2020-01-12 15:25:22 +01:00
Eugen Rochko 4c57f5978d
Create gempush.yml 2020-01-12 14:03:26 +01:00
dependabot[bot] d0f59cb65d Bump nokogiri from 1.8.5 to 1.10.5 (#11)
Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.8.5 to 1.10.5.
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.8.5...v1.10.5)

Signed-off-by: dependabot[bot] <support@github.com>
2019-11-14 13:48:16 +01:00
Tom Scott 2deb9da0ab Upgrade to HTTP.rb v4 (#9)
This allows Goldfinger to run against the HTTP gem v4.x, by updating the
`HTTP.timeout` syntax used in `Goldfinger::Request`.
2019-01-14 09:23:20 +00:00
Eugen Rochko 1fca7e670e Update dependencies and bump to 2.1.0 2018-01-23 05:23:16 +01:00
MIYAGI Hikaru d5f16ebeca Enable to pass options to HTTP.rb, Allow insecure request (#6)
* Enable to pass options to HTTP.rb, Allow insecure request

* Move SSL option to the hash

* fix a bug
2018-01-22 00:11:46 +01:00
Eugen Rochko 114c45f62d Bump version to 2.0.1 2017-08-05 14:51:57 +02:00
Yamagishi Kazutoshi 29dce59043 Cast HTTP response body for JSON to string (regression from #4) (#5)
Oj uses `readpartial` instead of `to_s` if the value given for the arguments has a `readpartial` method.
Also, HTTP.rb splits the response if `Transfer-Encoding: chunked` is returned in the HTTP headers.

Will use `to_s` like `JSON.parse` which was used previously.
2017-08-04 14:05:28 +02:00
Eugen Rochko 13d8b032fd Update dependencies, do not mask HTTP/OpenSSL exceptions, do not fallback to HTTP (#4)
if HTTPS is not available
2017-07-19 23:36:11 +02:00
Eugen Rochko 36434d836e No longer compatible with Ruby 2.0 2017-05-09 14:59:44 +02:00
Eugen Rochko b6eeb547b3 Update readme links 2017-05-09 14:57:48 +02:00
Eugen Rochko cf17716d4c Update dependencies and bump to 1.2.1 2017-05-09 14:56:21 +02:00
14 changed files with 250 additions and 119 deletions

41
.github/workflows/gempush.yml vendored Normal file
View File

@ -0,0 +1,41 @@
name: Ruby Gem
on:
push:
tags:
- v*
jobs:
build:
name: Build + Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
version: 2.6.x
- name: Publish to GPR
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
env:
GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
OWNER: tootsuite
- name: Publish to RubyGems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push *.gem
env:
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}

100
.rubocop.yml Normal file
View File

@ -0,0 +1,100 @@
AllCops:
TargetRubyVersion: 2.3
Exclude:
- 'spec/**/*'
- 'bin/*'
- 'Rakefile'
- 'vendor/**/*'
Bundler/OrderedGems:
Enabled: false
Layout/AccessModifierIndentation:
EnforcedStyle: indent
Layout/EmptyLineAfterMagicComment:
Enabled: false
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: space
Metrics/AbcSize:
Max: 100
Metrics/BlockNesting:
Max: 3
Metrics/ClassLength:
CountComments: false
Max: 200
Metrics/CyclomaticComplexity:
Max: 15
Metrics/LineLength:
AllowURI: true
Enabled: false
Metrics/MethodLength:
CountComments: false
Max: 55
Metrics/ModuleLength:
CountComments: false
Max: 200
Metrics/ParameterLists:
Max: 4
CountKeywordArgs: true
Metrics/PerceivedComplexity:
Max: 10
Rails:
Enabled: true
Rails/HasAndBelongsToMany:
Enabled: false
Rails/SkipsModelValidations:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Style/CollectionMethods:
Enabled: true
PreferredMethods:
find_all: 'select'
Style/Documentation:
Enabled: false
Style/DoubleNegation:
Enabled: true
Style/FrozenStringLiteralComment:
Enabled: true
Style/GuardClause:
Enabled: false
Style/Lambda:
Enabled: false
Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%i': '()'
'%w': '()'
Style/PerlBackrefs:
AutoCorrect: false
Style/RegexpLiteral:
Enabled: false
Style/SymbolArray:
Enabled: false
Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: 'comma'

View File

@ -1,2 +1 @@
2.2.4
2.5.0

View File

@ -1,11 +1,12 @@
language: ruby
cache: bundler
notifications:
email: false
rvm:
- 2.0.0
- 2.1
- 2.2
- ruby-head
- 2.3.1
- 2.4.1
bundler_args: --without development --retry=3 --jobs=3

View File

@ -1,64 +1,71 @@
PATH
remote: .
specs:
goldfinger (1.2.0)
addressable (~> 2.4)
http (~> 2.0)
nokogiri (~> 1.6)
goldfinger (2.1.1)
addressable (~> 2.5)
http (~> 4.0)
nokogiri (~> 1.8)
oj (~> 3.0)
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
coderay (1.1.1)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
domain_name (0.5.20170404)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
ffi (1.12.2)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
fuubar (2.2.0)
rspec-core (~> 3.0)
ruby-progressbar (~> 1.4)
hashdiff (0.3.2)
http (2.2.1)
hashdiff (0.3.4)
http (4.3.0)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 1.0.1)
http_parser.rb (~> 0.6.0)
http-form_data (~> 2.2)
http-parser (~> 1.2.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http-form_data (1.0.1)
http_parser.rb (0.6.0)
http-form_data (2.2.0)
http-parser (1.2.1)
ffi-compiler (>= 1.0, < 2.0)
method_source (0.8.2)
mini_portile2 (2.1.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
mini_portile2 (2.4.0)
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
oj (3.10.2)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
public_suffix (2.0.5)
rake (12.0.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
public_suffix (3.0.3)
rake (12.3.3)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
ruby-progressbar (1.8.1)
safe_yaml (1.0.4)
slop (3.6.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
unf_ext (0.0.7.6)
webmock (3.0.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
@ -68,7 +75,7 @@ PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.3)
bundler (~> 1.15)
fuubar
goldfinger!
pry (>= 0.10.3)
@ -77,4 +84,4 @@ DEPENDENCIES
webmock
BUNDLED WITH
1.13.0
1.16.1

View File

@ -1,15 +1,16 @@
Goldfinger, a Webfinger client for Ruby
Goldfinger, a WebFinger client for Ruby
=======================================
[![Gem Version](http://img.shields.io/gem/v/goldfinger.svg)][gem]
[![Build Status](http://img.shields.io/travis/Gargron/goldfinger.svg)][travis]
[![Dependency Status](http://img.shields.io/gemnasium/Gargron/goldfinger.svg)][gemnasium]
[![Build Status](http://img.shields.io/travis/tootsuite/goldfinger.svg)][travis]
[gem]: https://rubygems.org/gems/goldfinger
[travis]: https://travis-ci.org/Gargron/goldfinger
[gemnasium]: https://gemnasium.com/Gargron/goldfinger
[travis]: https://travis-ci.org/tootsuite/goldfinger
A Webfinger client for Ruby. Supports `application/xrd+xml` and `application/jrd+json` responses. Raises `Goldfinger::NotFoundError` on failure to fetch the Webfinger or XRD data, or `Goldfinger::SSLError` if something is wrong with the HTTPS connection it uses.
A WebFinger client for Ruby. Supports `application/xrd+xml` and `application/jrd+json` responses. Raises `Goldfinger::NotFoundError` on failure to fetch the Webfinger or XRD data, can also raise `HTTP:Error` or `OpenSSL::SSL::SSLError` if something is wrong with the HTTPS connection it uses.
- **Does not** fall back to HTTP if HTTPS is not available
- **Does** check host-meta XRD, but *only* if the standard WebFinger path yielded no result
## Installation
@ -30,4 +31,4 @@ A Webfinger client for Ruby. Supports `application/xrd+xml` and `application/jrd
## RFC support
The official Webfinger RFC is [7033](https://tools.ietf.org/html/rfc7033).
The official WebFinger RFC is [7033](https://tools.ietf.org/html/rfc7033).

View File

@ -1,20 +1,23 @@
# frozen_string_literal: true
Gem::Specification.new do |s|
s.name = 'goldfinger'
s.version = '1.2.0'
s.version = '2.1.1'
s.platform = Gem::Platform::RUBY
s.required_ruby_version = '>= 2.0.0'
s.required_ruby_version = '>= 2.3.0'
s.date = '2016-02-17'
s.summary = "A Webfinger utility for Ruby"
s.description = "A Webfinger utility for Ruby"
s.authors = ["Eugen Rochko"]
s.summary = 'A Webfinger utility for Ruby'
s.description = 'A Webfinger utility for Ruby'
s.authors = ['Eugen Rochko']
s.email = 'eugen@zeonfederated.com'
s.files = `git ls-files lib LICENSE README.md`.split($RS)
s.homepage = 'https://github.com/Gargron/goldfinger'
s.homepage = 'https://github.com/tootsuite/goldfinger'
s.licenses = ['MIT']
s.add_dependency('http', '~> 2.0')
s.add_dependency('addressable', '~> 2.4')
s.add_dependency('nokogiri', '~> 1.6')
s.add_dependency('http', '~> 4.0')
s.add_dependency('addressable', '~> 2.5')
s.add_dependency('nokogiri', '~> 1.8')
s.add_dependency('oj', '~> 3.0')
s.add_development_dependency('bundler', '~> 1.3')
s.add_development_dependency('bundler', '~> 1.15')
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'goldfinger/request'
require 'goldfinger/link'
require 'goldfinger/result'
@ -11,16 +13,14 @@ module Goldfinger
class NotFoundError < Error
end
class SSLError < Error
end
# Returns result for the Webfinger query
#
# @raise [Goldfinger::NotFoundError] Error raised when the Webfinger resource could not be retrieved
# @raise [Goldfinger::SSLError] Error raised when there was a SSL error when fetching the resource
# @param uri [String] A full resource identifier in the format acct:user@example.com
# @param opts [Hash] Options passed to HTTP.rb client
# @return [Goldfinger::Result]
def self.finger(uri)
Goldfinger::Client.new(uri).finger
def self.finger(uri, opts = {})
Goldfinger::Client.new(uri, opts).finger
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'addressable'
require 'nokogiri'
@ -5,29 +7,19 @@ module Goldfinger
class Client
include Goldfinger::Utils
def initialize(uri)
def initialize(uri, opts = {})
@uri = uri
@ssl = opts.delete(:ssl) { true }
@scheme = @ssl ? 'https' : 'http'
@opts = opts
end
def finger
ssl = true
response = perform_get(standard_url, @opts)
begin
response = perform_get(standard_url(ssl))
return finger_from_template if response.code != 200
return finger_from_template if response.code != 200
Goldfinger::Result.new(response)
rescue HTTP::Error
raise Goldfinger::NotFoundError unless ssl
ssl = false
retry
end
rescue HTTP::Error
raise Goldfinger::NotFoundError
rescue OpenSSL::SSL::SSLError
raise Goldfinger::SSLError
Goldfinger::Result.new(response)
rescue Addressable::URI::InvalidURIError
raise Goldfinger::NotFoundError, 'Invalid URI'
end
@ -35,32 +27,23 @@ module Goldfinger
private
def finger_from_template
ssl = true
begin
template = perform_get(url(ssl))
rescue HTTP::Error
raise Goldfinger::NotFoundError unless ssl
ssl = false
retry
end
template = perform_get(url, @opts)
raise Goldfinger::NotFoundError, 'No host-meta on the server' if template.code != 200
response = perform_get(url_from_template(template.body))
response = perform_get(url_from_template(template.body), @opts)
raise Goldfinger::NotFoundError, 'No such user on the server' if response.code != 200
Goldfinger::Result.new(response)
end
def url(ssl = true)
"http#{'s' if ssl}://#{domain}/.well-known/host-meta"
def url
"#{@scheme}://#{domain}/.well-known/host-meta"
end
def standard_url(ssl = true)
"http#{'s' if ssl}://#{domain}/.well-known/webfinger?resource=#{@uri}"
def standard_url
"#{@scheme}://#{domain}/.well-known/webfinger?resource=#{@uri}"
end
def url_from_template(template)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Goldfinger
# @!attribute [r] href
# @return [String] The href the link points to

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'http'
require 'addressable'
@ -16,7 +18,7 @@ module Goldfinger
private
def http_client
HTTP.timeout(:per_operation, write: 60, connect: 20, read: 60).follow
HTTP.timeout(write: 60, connect: 20, read: 60).follow
end
end
end

View File

@ -1,13 +1,23 @@
# frozen_string_literal: true
require 'oj'
module Goldfinger
# @!attribute [r] subject
# @return [String] URI that identifies the entity that the JRD describes.
# @!attribute [r] aliases
# @return [Array] Zero or more URI strings that identify the same entity as the "subject" URI.
class Result
MIME_TYPES = [
'application/jrd+json',
'application/json',
'application/xrd+xml',
'application/xml',
'text/xml'
'text/xml',
].freeze
attr_reader :subject, :aliases
def initialize(response)
@mime_type = response.mime_type
@body = response.body
@ -19,20 +29,6 @@ module Goldfinger
parse
end
# The value of the "subject" member is a URI that identifies the entity
# that the JRD describes.
# @return [String]
def subject
@subject
end
# The "aliases" array is an array of zero or more URI strings that
# identify the same entity as the "subject" URI.
# @return [Array]
def aliases
@aliases
end
# The "properties" object comprises zero or more name/value pairs whose
# names are URIs (referred to as "property identifiers") and whose
# values are strings or nil.
@ -78,7 +74,7 @@ module Goldfinger
end
def parse_json
json = JSON.parse(@body)
json = Oj.load(@body.to_s, mode: :null)
@subject = json['subject']
@aliases = json['aliases'] || []
@ -94,7 +90,7 @@ module Goldfinger
xml = Nokogiri::XML(@body)
@subject = xml.at_xpath('//xmlns:Subject').content
@aliases = xml.xpath('//xmlns:Alias').map { |a| a.content }
@aliases = xml.xpath('//xmlns:Alias').map(&:content)
properties = xml.xpath('/xmlns:XRD/xmlns:Property')
properties.each { |prop| @properties[prop.attribute('type').value] = prop.attribute('nil') ? nil : prop.content }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Goldfinger
module Utils
def perform_get(path, options = {})

View File

@ -27,14 +27,8 @@ describe Goldfinger::Client do
subject { Goldfinger::Client.new('acct:gargron@quitter.no') }
it 'returns a result' do
expect(subject.finger).to be_instance_of Goldfinger::Result
end
it 'performs two HTTP requests' do
subject.finger
expect(a_request(:get, 'https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no')).to have_been_made.once
expect(a_request(:get, 'http://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no')).to have_been_made.once
it 'raises an error' do
expect { subject.finger }.to raise_error HTTP::Error
end
end
end
@ -51,7 +45,7 @@ describe Goldfinger::Client do
subject { Goldfinger::Client.new('acct:gargron@quitter.no') }
it 'raises an error' do
expect { subject.finger }.to raise_error(Goldfinger::NotFoundError)
expect { subject.finger }.to raise_error(HTTP::Error)
end
end
end