pwned 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1790330e2068217b48ba0929c4b2409dfecd939e76f7d231acc872ef9802320a
4
- data.tar.gz: afa13cc83a53df1be859a74876e00992b15eed757e571bec652168d85b3ab73e
3
+ metadata.gz: f4b8270eaf162b50ef112371c2e35dd41141dec39e4e11d5a76936119e2ca569
4
+ data.tar.gz: fdec9b67cc6465fa64062697253e6cf078ddb2b2deb71cf829a919dca7953f48
5
5
  SHA512:
6
- metadata.gz: 23482aeeab95bb130ba04f1fdc57f769282d78c7c4c56c594f15652c472ffce9573967d8a31d539548a325c85f54aa038d65bb023aded41352147ad9a906534e
7
- data.tar.gz: d31fb7ad5171adc4cc8ee28ed97d125fbd19c93bc68e65e7921076d1fb586748a1a4f12007e70cbfe6378e3c868effa756efaa08e627bfa82b2c73166e0b7dd1
6
+ metadata.gz: 7ec757852674e3e44ac71a71ed5c31d3503b5f0547871f940d56e8e2d8838b0b89e36742c0e10108f1c00fddc54016454d3ba77348cddd7be659d1ed4fdaf71a
7
+ data.tar.gz: 304b59ce60639f57c7a3a81c5e0f172dc8de9a2128018abe636be7f6d88074af59ac193d2538f86c298d4f8a537b0152bdcab6efb8cf4a27d5c6a13c64b9e311
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog for `Pwned`
2
2
 
3
- ## Ongoing [☰](https://github.com/philnash/pwned/compare/v2.0.2...master)
3
+ ## Ongoing [☰](https://github.com/philnash/pwned/compare/v2.2.0...master)
4
+
5
+ ## 2.3.0 (August 30, 2021) [☰](https://github.com/philnash/pwned/compare/v2.2.0...v2.3.0)
6
+
7
+ - Minor updates
8
+
9
+ - Restores `Net::HTTP` default behaviour to use environment supplied HTTP
10
+ proxy
11
+ - Adds `ignore_env_proxy` to ignore any proxies set in the environment
4
12
 
5
13
  ## 2.2.0 (March 27, 2021) [☰](https://github.com/philnash/pwned/compare/v2.1.0...v2.2.0)
6
14
 
data/README.md CHANGED
@@ -8,28 +8,31 @@ An easy, Ruby way to use the Pwned Passwords API.
8
8
 
9
9
  ## Table of Contents
10
10
 
11
- - [Pwned](#pwned)
12
- - [Table of Contents](#table-of-contents)
13
- - [About](#about)
14
- - [Installation](#installation)
15
- - [Usage](#usage)
16
- - [Plain Ruby](#plain-ruby)
17
- - [Advanced](#advanced)
18
- - [ActiveRecord Validator](#activerecord-validator)
19
- - [I18n](#i18n)
20
- - [Threshold](#threshold)
21
- - [Network Error Handling](#network-error-handling)
22
- - [Custom Request Options](#custom-request-options)
23
- - [Using Asynchronously](#using-asynchronously)
24
- - [Devise](#devise)
25
- - [Rodauth](#rodauth)
26
- - [Command line](#command-line)
27
- - [Unpwn](#unpwn)
28
- - [How Pwned is Pi?](#how-pwned-is-pi)
29
- - [Development](#development)
30
- - [Contributing](#contributing)
31
- - [License](#license)
32
- - [Code of Conduct](#code-of-conduct)
11
+ * [Table of Contents](#table-of-contents)
12
+ * [About](#about)
13
+ * [Installation](#installation)
14
+ * [Usage](#usage)
15
+ * [Plain Ruby](#plain-ruby)
16
+ * [Custom request options](#custom-request-options)
17
+ * [HTTP Headers](#http-headers)
18
+ * [HTTP Proxy](#http-proxy)
19
+ * [ActiveRecord Validator](#activerecord-validator)
20
+ * [I18n](#i18n)
21
+ * [Threshold](#threshold)
22
+ * [Network Error Handling](#network-error-handling)
23
+ * [Custom Request Options](#custom-request-options-1)
24
+ * [HTTP Headers](#http-headers-1)
25
+ * [HTTP Proxy](#http-proxy-1)
26
+ * [Using Asynchronously](#using-asynchronously)
27
+ * [Devise](#devise)
28
+ * [Rodauth](#rodauth)
29
+ * [Command line](#command-line)
30
+ * [Unpwn](#unpwn)
31
+ * [How Pwned is Pi?](#how-pwned-is-pi)
32
+ * [Development](#development)
33
+ * [Contributing](#contributing)
34
+ * [License](#license)
35
+ * [Code of Conduct](#code-of-conduct)
33
36
 
34
37
  ## About
35
38
 
@@ -105,13 +108,49 @@ Pwned.pwned_count("password")
105
108
  #=> 3303003
106
109
  ```
107
110
 
108
- #### Advanced
111
+ #### Custom request options
109
112
 
110
- You can set http request options to be used with `Net::HTTP.start` when making the request to the API. These options are
111
- documented in the [`Net::HTTP.start` documentation](http://ruby-doc.org/stdlib-2.6.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start). The `:headers` option defines defines HTTP headers. These headers must be string keys.
113
+ You can set http request options to be used with `Net::HTTP.start` when making the request to the API. These options are documented in the [`Net::HTTP.start` documentation](https://ruby-doc.org/stdlib-3.0.0/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start). For example:
112
114
 
113
115
  ```ruby
114
- password = Pwned::Password.new("password", headers: { 'User-Agent' => 'Super fun new user agent' }, read_timeout: 10)
116
+ password = Pwned::Password.new("password", read_timeout: 10)
117
+ ```
118
+
119
+ ##### HTTP Headers
120
+
121
+ The `:headers` option defines defines HTTP headers. These headers must be string keys.
122
+
123
+ ```ruby
124
+ password = Pwned::Password.new("password", headers: {
125
+ 'User-Agent' => 'Super fun new user agent'
126
+ })
127
+ ```
128
+
129
+ ##### HTTP Proxy
130
+
131
+ An HTTP proxy can be set using the `http_proxy` or `HTTP_PROXY` environment variable. This is the same way that `Net::HTTP` handles HTTP proxies if no proxy options are given. See [`URI::Generic#find_proxy`](https://ruby-doc.org/stdlib-3.0.1/libdoc/uri/rdoc/URI/Generic.html#method-i-find_proxy) for full details on how Ruby detects a proxy from the environment.
132
+
133
+ ```ruby
134
+ # Set in the environment
135
+ ENV["http_proxy"] = "https://username:password@example.com:12345"
136
+
137
+ # Will use the above proxy
138
+ password = Pwned::Password.new("password")
139
+ ```
140
+
141
+ You can specify a custom HTTP proxy with the `:proxy` option:
142
+
143
+ ```ruby
144
+ password = Pwned::Password.new(
145
+ "password",
146
+ proxy: "https://username:password@example.com:12345"
147
+ )
148
+ ```
149
+
150
+ If you don't want to set a proxy and you don't want a proxy to be inferred from the environment, set the `:ignore_env_proxy` key:
151
+
152
+ ```ruby
153
+ password = Pwned::Password.new("password", ignore_env_proxy: true)
115
154
  ```
116
155
 
117
156
  ### ActiveRecord Validator
@@ -181,20 +220,62 @@ end
181
220
 
182
221
  #### Custom Request Options
183
222
 
184
- You can configure network requests made from the validator using `:request_options` (see [Net::HTTP.start](http://ruby-doc.org/stdlib-2.6.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start) for the list of available options).
185
- In addition to these options, HTTP headers can be specified with the `:headers` key (e.g. `"User-Agent"`) and proxy can be specified with the `:proxy` key:
223
+ You can configure network requests made from the validator using `:request_options` (see [Net::HTTP.start](http://ruby-doc.org/stdlib-2.6.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start) for the list of available options).
186
224
 
187
225
  ```ruby
188
226
  validates :password, not_pwned: {
189
227
  request_options: {
190
228
  read_timeout: 5,
191
- open_timeout: 1,
192
- headers: { "User-Agent" => "Super fun user agent" },
229
+ open_timeout: 1
230
+ }
231
+ }
232
+ ```
233
+
234
+ In addition to these options, you can also set the following:
235
+
236
+ ##### HTTP Headers
237
+
238
+ HTTP headers can be specified with the `:headers` key (e.g. `"User-Agent"`)
239
+
240
+ ```ruby
241
+ validates :password, not_pwned: {
242
+ request_options: {
243
+ headers: { "User-Agent" => "Super fun user agent" }
244
+ }
245
+ }
246
+ ```
247
+
248
+ ##### HTTP Proxy
249
+
250
+ An HTTP proxy can be set using the `http_proxy` or `HTTP_PROXY` environment variable. This is the same way that `Net::HTTP` handles HTTP proxies if no proxy options are given. See [`URI::Generic#find_proxy`](https://ruby-doc.org/stdlib-3.0.1/libdoc/uri/rdoc/URI/Generic.html#method-i-find_proxy) for full details on how Ruby detects a proxy from the environment.
251
+
252
+ ```ruby
253
+ # Set in the environment
254
+ ENV["http_proxy"] = "https://username:password@example.com:12345"
255
+
256
+ validates :password, not_pwned: true
257
+ ```
258
+
259
+ You can specify a custom HTTP proxy with the `:proxy` key:
260
+
261
+ ```ruby
262
+ validates :password, not_pwned: {
263
+ request_options: {
193
264
  proxy: "https://username:password@example.com:12345"
194
265
  }
195
266
  }
196
267
  ```
197
268
 
269
+ If you don't want to set a proxy and you don't want a proxy to be inferred from the environment, set the `:ignore_env_proxy` key:
270
+
271
+ ```ruby
272
+ validates :password, not_pwned: {
273
+ request_options: {
274
+ ignore_env_proxy: true
275
+ }
276
+ }
277
+ ```
278
+
198
279
  ### Using Asynchronously
199
280
 
200
281
  You may have a use case for hashing the password in advance, and then making the call to the Pwned Passwords API later (for example if you want to enqueue a job without storing the plaintext password). To do this, you can hash the password with the `Pwned.hash_password` method and then initialize the `Pwned::HashPassword` class with the hash, like this:
@@ -205,6 +286,8 @@ hashed_password = Pwned.hash_password(password)
205
286
  Pwned::HashPassword.new(hashed_password, request_options).pwned?
206
287
  ```
207
288
 
289
+ The `Pwned::HashPassword` constructor takes all the same options as the regular `Pwned::Password` contructor.
290
+
208
291
  ### Devise
209
292
 
210
293
  If you are using [Devise](https://github.com/heartcombo/devise) I recommend you use the [devise-pwned_password extension](https://github.com/michaelbanfield/devise-pwned_password) which is now powered by this gem.
@@ -22,6 +22,9 @@ module Pwned
22
22
  # calling the API
23
23
  # @option request_options [Symbol] :headers ({ "User-Agent" => "Ruby Pwned::Password #{Pwned::VERSION}" })
24
24
  # HTTP headers to include in the request
25
+ # @option request_options [Symbol] :ignore_env_proxy (false) The library
26
+ # will try to infer an HTTP proxy from the `http_proxy` environment
27
+ # variable. If you do not want this behaviour, set this option to true.
25
28
  # @raise [TypeError] if the password is not a string.
26
29
  # @since 2.1.0
27
30
  def initialize(hashed_password, request_options={})
@@ -31,6 +34,7 @@ module Pwned
31
34
  @request_headers = Hash(request_options.delete(:headers))
32
35
  @request_headers = DEFAULT_REQUEST_HEADERS.merge(@request_headers)
33
36
  @request_proxy = URI(request_options.delete(:proxy)) if request_options.key?(:proxy)
37
+ @ignore_env_proxy = request_options.delete(:ignore_env_proxy) || false
34
38
  end
35
39
  end
36
40
  end
@@ -27,7 +27,9 @@ module Pwned
27
27
  # calling the API
28
28
  # @option request_options [Symbol] :headers ({ "User-Agent" => "Ruby Pwned::Password #{Pwned::VERSION}" })
29
29
  # HTTP headers to include in the request
30
- # @return [Boolean] Whether the password appears in the data breaches or not.
30
+ # @option request_options [Symbol] :ignore_env_proxy (false) The library
31
+ # will try to infer an HTTP proxy from the `http_proxy` environment
32
+ # variable. If you do not want this behaviour, set this option to true.
31
33
  # @raise [TypeError] if the password is not a string.
32
34
  # @since 1.1.0
33
35
  def initialize(password, request_options={})
@@ -38,6 +40,7 @@ module Pwned
38
40
  @request_headers = Hash(request_options.delete(:headers))
39
41
  @request_headers = DEFAULT_REQUEST_HEADERS.merge(@request_headers)
40
42
  @request_proxy = URI(request_options.delete(:proxy)) if request_options.key?(:proxy)
43
+ @ignore_env_proxy = request_options.delete(:ignore_env_proxy) || false
41
44
  end
42
45
  end
43
46
  end
@@ -65,7 +65,7 @@ module Pwned
65
65
 
66
66
  private
67
67
 
68
- attr_reader :request_options, :request_headers, :request_proxy
68
+ attr_reader :request_options, :request_headers, :request_proxy, :ignore_env_proxy
69
69
 
70
70
  def fetch_pwned_count
71
71
  for_each_response_line do |line|
@@ -108,10 +108,12 @@ module Pwned
108
108
  request.initialize_http_header(request_headers)
109
109
  request_options[:use_ssl] = true
110
110
 
111
+ environment_proxy = ignore_env_proxy ? nil : :ENV
112
+
111
113
  Net::HTTP.start(
112
114
  uri.host,
113
115
  uri.port,
114
- request_proxy&.host,
116
+ request_proxy&.host || environment_proxy,
115
117
  request_proxy&.port,
116
118
  request_proxy&.user,
117
119
  request_proxy&.password,
@@ -136,6 +138,5 @@ module Pwned
136
138
 
137
139
  yield last_line unless last_line.empty?
138
140
  end
139
-
140
141
  end
141
142
  end
data/lib/pwned/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module Pwned
4
4
  ##
5
5
  # The current version of the +pwned+ gem.
6
- VERSION = "2.2.0"
6
+ VERSION = "2.3.0"
7
7
  end
data/lib/pwned.rb CHANGED
@@ -35,6 +35,9 @@ module Pwned
35
35
  # calling the API
36
36
  # @option request_options [Symbol] :headers ({ "User-Agent" => "Ruby Pwned::Password #{Pwned::VERSION}" })
37
37
  # HTTP headers to include in the request
38
+ # @option request_options [Symbol] :ignore_env_proxy (false) The library
39
+ # will try to infer an HTTP proxy from the `http_proxy` environment
40
+ # variable. If you do not want this behaviour, set this option to true.
38
41
  # @return [Boolean] Whether the password appears in the data breaches or not.
39
42
  # @since 1.1.0
40
43
  def self.pwned?(password, request_options={})
@@ -53,6 +56,9 @@ module Pwned
53
56
  # calling the API
54
57
  # @option request_options [Symbol] :headers ({ "User-Agent" => "Ruby Pwned::Password #{Pwned::VERSION}" })
55
58
  # HTTP headers to include in the request
59
+ # @option request_options [Symbol] :ignore_env_proxy (false) The library
60
+ # will try to infer an HTTP proxy from the `http_proxy` environment
61
+ # variable. If you do not want this behaviour, set this option to true.
56
62
  # @return [Integer] The number of times the password has appeared in the data
57
63
  # breaches.
58
64
  # @since 1.1.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwned
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-27 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 3.2.3
144
+ rubygems_version: 3.1.2
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Tools to use the Pwned Passwords API.