webmention-verification 5.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f857c41d6b22400c2fe19dd21a170dd7309d20bb34a6e2c23d6aad50894e44f6
4
- data.tar.gz: 938305729f91102b6c7c8d372975e12a0724be00a43313cd1a715affcc9e9fbf
3
+ metadata.gz: 3d920d91622406f373a8b74d0169383d3d847a6e534da19ecaf6a230078c1bcf
4
+ data.tar.gz: dc29ab3a43d77d48e6b6852a3fe884ab7a1af8e7ba0a63d36ac61207168f92a5
5
5
  SHA512:
6
- metadata.gz: 7b67afd1e2f1397439a465eba1cc9d639c959888e82b64de83fb85273bff2eb0ec0623103377504970a269948e214d5db117a938f7d7eb6d90bc24a991444654
7
- data.tar.gz: 000c06f6b3951d487c8b5bbfd7a36e63be5bda7cf1c3d104861814bacd3088830b7e1c439ecb5cf93f4d7fd393bf527f7424fc4c7c8eb9ba15dbf329ac6c4d6d
6
+ metadata.gz: 8d0efb2c62c2d8b1e854e1251f7f5552731352e8864599b87694e08b223088c8e8c891be1622e34a87775ba371cd990c4b9601092582b33fc9010cc585ef8820
7
+ data.tar.gz: 2ef8ae0f3bae0825d2cae1fb24ae890095c6855b6ab2fc65ed822fb8ab4c531b82a91f49004aba0e307bdc02ae20c65b6679cfc56705231f020b8de75c4b7850
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.0 / 2022-05-03
4
+
5
+ - Move/rename BaseVerifier to Verifier class (6965e98)
6
+ - Remove addressable dependency (38a004e)
7
+ - Raise Webmention::Verification::SSLError on SSL errors (be9d922)
8
+ - Update ~~Addressable and~~ Nokogiri dependency constraints (822b7ae)
9
+ - **Breaking change:** Update minimum supported Ruby to 2.6 (07a7c5e)
10
+ - Update development Ruby version to 2.6.10 (d67d583)
11
+ - Remove Reek (b10b648)
12
+
3
13
  ## 5.0.0 / 2021-06-08
4
14
 
5
15
  - Add `Webmention::Verification::Client#inspect` method (361c437)
data/CONTRIBUTING.md CHANGED
@@ -8,9 +8,9 @@ There are a couple ways you can help improve webmention-verification-ruby:
8
8
 
9
9
  ## Getting Started
10
10
 
11
- webmention-verification-ruby is developed using Ruby 2.5.9 and is additionally tested against Ruby 2.6, 2.7, and 3.0 using [CircleCI](https://app.circleci.com/pipelines/github/jgarber623/webmention-verification-ruby).
11
+ webmention-verification-ruby is developed using Ruby 2.6.10 and is additionally tested against Ruby 2.7, 3.0, and 3.1 using [GitHub Actions](https://github.com/jgarber623/webmention-verification-ruby/actions).
12
12
 
13
- Before making changes to webmention-verification-ruby, you'll want to install Ruby 2.5.9. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm). Once you've installed Ruby 2.5.9 using your method of choice, install the project's gems by running:
13
+ Before making changes to webmention-verification-ruby, you'll want to install Ruby 2.6.10. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm). Once you've installed Ruby 2.6.10 using your method of choice, install the project's gems by running:
14
14
 
15
15
  ```sh
16
16
  bundle install
data/README.md CHANGED
@@ -4,20 +4,20 @@
4
4
 
5
5
  [![Gem](https://img.shields.io/gem/v/webmention-verification.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/webmention-verification)
6
6
  [![Downloads](https://img.shields.io/gem/dt/webmention-verification.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/webmention-verification)
7
- [![Build](https://img.shields.io/circleci/build/github/jgarber623/webmention-verification-ruby?logo=circleci&style=for-the-badge)](https://app.circleci.com/pipelines/github/jgarber623/webmention-verification-ruby)
7
+ [![Build](https://img.shields.io/github/workflow/status/jgarber623/webmention-verification-ruby/CI?logo=github&style=for-the-badge)](https://github.com/jgarber623/webmention-verification-ruby/actions/workflows/ci.yml)
8
8
  [![Maintainability](https://img.shields.io/codeclimate/maintainability/jgarber623/webmention-verification-ruby.svg?logo=code-climate&style=for-the-badge)](https://codeclimate.com/github/jgarber623/webmention-verification-ruby)
9
9
  [![Coverage](https://img.shields.io/codeclimate/c/jgarber623/webmention-verification-ruby.svg?logo=code-climate&style=for-the-badge)](https://codeclimate.com/github/jgarber623/webmention-verification-ruby/code)
10
10
 
11
11
  ## Key Features
12
12
 
13
13
  - Compliant with [Section 3.2.2](https://www.w3.org/TR/webmention/#webmention-verification) of [the W3C's Webmention Recommendation](https://www.w3.org/TR/webmention/).
14
- - Supports Ruby 2.5 and newer.
14
+ - Supports Ruby 2.6 and newer.
15
15
 
16
16
  ## Getting Started
17
17
 
18
- Before installing and using webmention-verification-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.5 (or newer) installed. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm).
18
+ Before installing and using webmention-verification-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.6 (or newer) installed. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm).
19
19
 
20
- webmention-verification-ruby is developed using Ruby 2.5.9 and is additionally tested against Ruby 2.6, 2.7, and 3.0 using [CircleCI](https://app.circleci.com/pipelines/github/jgarber623/webmention-verification-ruby).
20
+ webmention-verification-ruby is developed using Ruby 2.6.10 and is additionally tested against Ruby 2.7, 3.0, and 3.1 using [GitHub Actions](https://github.com/jgarber623/webmention-verification-ruby/actions).
21
21
 
22
22
  ## Installation
23
23
 
@@ -69,8 +69,8 @@ client = Webmention::Verification::Client.new(source, target)
69
69
  puts client.source # => 'https://source.example.com/post/100'
70
70
  puts client.target # => 'https://target.example.com/post/100'
71
71
 
72
- puts client.source_uri # => #<Addressable::URI>
73
- puts client.target_uri # => #<Addressable::URI>
72
+ puts client.source_uri # => #<HTTP::URI>
73
+ puts client.target_uri # => #<HTTP::URI>
74
74
 
75
75
  puts client.response # => #<HTTP::Response>
76
76
 
@@ -148,6 +148,10 @@ From [httprb/http](https://github.com/httprb/http):
148
148
 
149
149
  - `Webmention::Verification::HttpError`
150
150
 
151
+ From the Ruby Standard Library's [`OpenSSL::SSL::SSLError`](https://ruby-doc.org/stdlib-2.6.10/libdoc/openssl/rdoc/OpenSSL/SSL/SSLError.html):
152
+
153
+ - `Webmention::Verification::SSLError`
154
+
151
155
  webmention-verification-ruby will also raise a `Webmention::Verification::UnsupportedMimeTypeError` when encountering an `HTTP::Response` instance with an unsupported MIME type.
152
156
 
153
157
  ## Contributing
@@ -1,13 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webmention
2
4
  module Verification
3
5
  class Client
4
6
  HTTP_CLIENT_HEADERS = {
5
- accept: '*/*',
7
+ accept: '*/*',
6
8
  user_agent: 'Webmention Verification Client (https://rubygems.org/gems/webmention-verification)'
7
9
  }.freeze
8
10
 
11
+ @registered_verifiers = {}
12
+
13
+ class << self
14
+ attr_reader :registered_verifiers
15
+ end
16
+
9
17
  attr_reader :source, :target
10
18
 
19
+ def self.register_verifier(klass)
20
+ klass.mime_types.each { |mime_type| @registered_verifiers[mime_type] = klass }
21
+ end
22
+
11
23
  # Create a client used to determine whether or not source URI links to target URI.
12
24
  #
13
25
  # @example
@@ -28,51 +40,61 @@ module Webmention
28
40
  @target = target.to_str
29
41
  @options = options
30
42
 
31
- raise ArgumentError, 'source must be an absolute URI (e.g. https://example.com/post/100)' unless source_uri.absolute?
32
- raise ArgumentError, 'target must be an absolute URI (e.g. https://example.com/post/100)' unless target_uri.absolute?
43
+ message = 'must be an absolute URI (e.g. https://example.com/post/100)'
44
+
45
+ raise ArgumentError, "source #{message}" unless absolute?(source_uri)
46
+ raise ArgumentError, "target #{message}" unless absolute?(target_uri)
33
47
  end
34
48
 
35
49
  # @return [String]
36
50
  def inspect
37
- format(%(#<#{self.class.name}:%#0x source: #{source.inspect} target: #{target.inspect} options: #{@options.inspect}>), object_id)
51
+ "#<#{self.class.name}:#{format('%#0x', object_id)} " \
52
+ "source: #{source.inspect} " \
53
+ "target: #{target.inspect} " \
54
+ "options: #{@options.inspect}>"
38
55
  end
39
56
 
40
57
  # @return [HTTP::Response]
41
- # @raise [Webmention::Verification::ConnectionError, Webmention::Verification::TimeoutError, Webmention::Verification::TooManyRedirectsError]
58
+ # @raise [Webmention::Verification::HttpError, Webmention::Verification::SSLError]
42
59
  def response
43
60
  @response ||= HTTP.follow.headers(HTTP_CLIENT_HEADERS).timeout(connect: 10, read: 10).get(source_uri)
44
- rescue HTTP::Error => exception
45
- raise HttpError, exception
61
+ rescue HTTP::Error => e
62
+ raise HttpError, e
63
+ rescue OpenSSL::SSL::SSLError => e
64
+ raise SSLError, e
46
65
  end
47
66
 
48
- # @return [Addressable::URI]
67
+ # @return [HTTP::URI]
49
68
  # @raise [Webmention::Verification::InvalidURIError]
50
69
  def source_uri
51
- @source_uri ||= Addressable::URI.parse(source)
52
- rescue Addressable::URI::InvalidURIError => exception
53
- raise InvalidURIError, exception
70
+ @source_uri ||= HTTP::URI.parse(source)
71
+ rescue Addressable::URI::InvalidURIError => e
72
+ raise InvalidURIError, e
54
73
  end
55
74
 
56
- # @return [Addressable::URI]
75
+ # @return [HTTP::URI]
57
76
  # @raise [Webmention::Verification::InvalidURIError]
58
77
  def target_uri
59
- @target_uri ||= Addressable::URI.parse(target)
60
- rescue Addressable::URI::InvalidURIError => exception
61
- raise InvalidURIError, exception
78
+ @target_uri ||= HTTP::URI.parse(target)
79
+ rescue Addressable::URI::InvalidURIError => e
80
+ raise InvalidURIError, e
62
81
  end
63
82
 
64
83
  # @return [Boolean]
65
84
  # @raise [Webmention::Verification::UnsupportedMimeTypeError]
66
85
  def verified?
67
- raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{response.mime_type}" unless verifier_for_mime_type
68
-
69
- verifier_for_mime_type.new(response, target, **@options).verified?
86
+ self.class
87
+ .registered_verifiers[response.mime_type]
88
+ .new(response, target, **@options)
89
+ .verified?
90
+ rescue NoMethodError
91
+ raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{response.mime_type}"
70
92
  end
71
93
 
72
94
  private
73
95
 
74
- def verifier_for_mime_type
75
- @verifier_for_mime_type ||= Verifiers.registered[response.mime_type]
96
+ def absolute?(uri)
97
+ uri.http? || uri.https?
76
98
  end
77
99
  end
78
100
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webmention
2
4
  module Verification
3
- class BaseVerifier
5
+ class Verifier
4
6
  class << self
5
7
  attr_reader :mime_types
6
8
  end
@@ -9,8 +11,6 @@ module Webmention
9
11
  @response = response
10
12
  @target = target.to_str
11
13
  @options = options
12
-
13
- raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{response.mime_type}" unless self.class.mime_types.include?(response.mime_type)
14
14
  end
15
15
 
16
16
  def results
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webmention
2
4
  module Verification
3
5
  module Verifiers
4
- class HtmlVerifier < BaseVerifier
6
+ class HtmlVerifier < Verifier
5
7
  @mime_types = ['text/html']
6
8
 
7
- Verifiers.register(self)
9
+ Client.register_verifier(self)
8
10
 
9
11
  HTML_ATTRIBUTE_MAP = {
10
- cite: %w[blockquote del ins q],
11
- data: %w[object],
12
- href: %w[a area],
13
- poster: %w[video],
14
- src: %w[audio embed img source track video],
15
- srcset: %w[img source]
12
+ 'cite' => %w[blockquote del ins q],
13
+ 'data' => %w[object],
14
+ 'href' => %w[a area],
15
+ 'poster' => %w[video],
16
+ 'src' => %w[audio embed img source track video],
17
+ 'srcset' => %w[img source]
16
18
  }.freeze
17
19
 
18
20
  private
@@ -26,7 +28,7 @@ module Webmention
26
28
  end
27
29
 
28
30
  def search_doc(attribute, elements)
29
- regexp = attribute == :srcset ? srcset_attribute_regexp : target_regexp
31
+ regexp = attribute == 'srcset' ? srcset_attribute_regexp : target_regexp
30
32
 
31
33
  doc.css(*elements.map { |element| "#{element}[#{attribute}]" }).find_all do |node|
32
34
  node[attribute].match?(regexp)
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webmention
2
4
  module Verification
3
5
  module Verifiers
4
- class JsonVerifier < BaseVerifier
6
+ class JsonVerifier < Verifier
5
7
  @mime_types = ['application/json']
6
8
 
7
- Verifiers.register(self)
9
+ Client.register_verifier(self)
8
10
 
9
11
  private
10
12
 
@@ -28,7 +30,6 @@ module Webmention
28
30
 
29
31
  private
30
32
 
31
- # :reek:TooManyStatements { max_statements: 6 }
32
33
  def build_results(comparator, object, matches = [])
33
34
  return matches unless object.is_a?(Enumerable)
34
35
 
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webmention
2
4
  module Verification
3
5
  module Verifiers
4
- class PlaintextVerifier < BaseVerifier
6
+ class PlaintextVerifier < Verifier
5
7
  @mime_types = ['text/plain']
6
8
 
7
- Verifiers.register(self)
9
+ Client.register_verifier(self)
8
10
 
9
11
  private
10
12
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webmention
2
4
  module Verification
3
- VERSION = '5.0.0'.freeze
5
+ VERSION = '6.0.0'
4
6
  end
5
7
  end
@@ -1,21 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
- require 'addressable/uri'
4
5
  require 'http'
5
6
  require 'nokogiri'
6
7
 
7
- require 'webmention/verification/version'
8
- require 'webmention/verification/exceptions'
8
+ require_relative 'verification/version'
9
9
 
10
- require 'webmention/verification/client'
11
- require 'webmention/verification/verifiers'
12
- require 'webmention/verification/verifiers/base_verifier'
13
- require 'webmention/verification/verifiers/html_verifier'
14
- require 'webmention/verification/verifiers/json_verifier'
15
- require 'webmention/verification/verifiers/plaintext_verifier'
10
+ require_relative 'verification/client'
11
+ require_relative 'verification/verifier'
12
+ require_relative 'verification/verifiers/html_verifier'
13
+ require_relative 'verification/verifiers/json_verifier'
14
+ require_relative 'verification/verifiers/plaintext_verifier'
16
15
 
17
16
  module Webmention
18
17
  module Verification
18
+ class Error < StandardError; end
19
+ class ArgumentError < Error; end
20
+ class HttpError < Error; end
21
+ class InvalidURIError < Error; end
22
+ class SSLError < Error; end
23
+ class UnsupportedMimeTypeError < Error; end
24
+
19
25
  # Determine whether or not source URI links to target URI.
20
26
  #
21
27
  # @example
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/webmention/verification/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
6
+ spec.required_ruby_version = '>= 2.6', '< 4'
5
7
 
6
8
  spec.name = 'webmention-verification'
7
9
  spec.version = Webmention::Verification::VERSION
@@ -19,10 +21,12 @@ Gem::Specification.new do |spec|
19
21
 
20
22
  spec.require_paths = ['lib']
21
23
 
22
- spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
23
- spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
24
+ spec.metadata = {
25
+ 'bug_tracker_uri' => "#{spec.homepage}/issues",
26
+ 'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
27
+ 'rubygems_mfa_required' => 'true'
28
+ }
24
29
 
25
- spec.add_runtime_dependency 'addressable', '~> 2.7'
26
30
  spec.add_runtime_dependency 'http', '~> 5.0'
27
- spec.add_runtime_dependency 'nokogiri', '~> 1.11'
31
+ spec.add_runtime_dependency 'nokogiri', '~> 1.13'
28
32
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmention-verification
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-09 00:00:00.000000000 Z
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: addressable
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.7'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.7'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: http
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +30,14 @@ dependencies:
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '1.11'
33
+ version: '1.13'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '1.11'
40
+ version: '1.13'
55
41
  description: Verify a received webmention.
56
42
  email:
57
43
  - jason@sixtwothree.org
@@ -65,9 +51,7 @@ files:
65
51
  - README.md
66
52
  - lib/webmention/verification.rb
67
53
  - lib/webmention/verification/client.rb
68
- - lib/webmention/verification/exceptions.rb
69
- - lib/webmention/verification/verifiers.rb
70
- - lib/webmention/verification/verifiers/base_verifier.rb
54
+ - lib/webmention/verification/verifier.rb
71
55
  - lib/webmention/verification/verifiers/html_verifier.rb
72
56
  - lib/webmention/verification/verifiers/json_verifier.rb
73
57
  - lib/webmention/verification/verifiers/plaintext_verifier.rb
@@ -78,8 +62,9 @@ licenses:
78
62
  - MIT
79
63
  metadata:
80
64
  bug_tracker_uri: https://github.com/jgarber623/webmention-verification-ruby/issues
81
- changelog_uri: https://github.com/jgarber623/webmention-verification-ruby/blob/v5.0.0/CHANGELOG.md
82
- post_install_message:
65
+ changelog_uri: https://github.com/jgarber623/webmention-verification-ruby/blob/v6.0.0/CHANGELOG.md
66
+ rubygems_mfa_required: 'true'
67
+ post_install_message:
83
68
  rdoc_options: []
84
69
  require_paths:
85
70
  - lib
@@ -87,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
72
  requirements:
88
73
  - - ">="
89
74
  - !ruby/object:Gem::Version
90
- version: '2.5'
75
+ version: '2.6'
91
76
  - - "<"
92
77
  - !ruby/object:Gem::Version
93
78
  version: '4'
@@ -97,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
82
  - !ruby/object:Gem::Version
98
83
  version: '0'
99
84
  requirements: []
100
- rubygems_version: 3.2.16
101
- signing_key:
85
+ rubygems_version: 3.3.12
86
+ signing_key:
102
87
  specification_version: 4
103
88
  summary: Verify a received webmention.
104
89
  test_files: []
@@ -1,13 +0,0 @@
1
- module Webmention
2
- module Verification
3
- class Error < StandardError; end
4
-
5
- class ArgumentError < Error; end
6
-
7
- class HttpError < Error; end
8
-
9
- class InvalidURIError < Error; end
10
-
11
- class UnsupportedMimeTypeError < Error; end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Webmention
2
- module Verification
3
- module Verifiers
4
- def self.register(klass)
5
- klass.mime_types.each { |mime_type| registered[mime_type] = klass }
6
- end
7
-
8
- def self.registered
9
- @registered ||= {}
10
- end
11
- end
12
- end
13
- end