-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dparpyani-dparpyani/proxy' into main
- Loading branch information
Showing
6 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,11 +182,16 @@ end | |
#### Custom Request Options | ||
|
||
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). | ||
In addition to these options, HTTP headers can be specified with the `:headers` key, e.g. `"User-Agent"`): | ||
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: | ||
|
||
```ruby | ||
validates :password, not_pwned: { | ||
request_options: { read_timeout: 5, open_timeout: 1, headers: { "User-Agent" => "Super fun user agent" } } | ||
request_options: { | ||
read_timeout: 5, | ||
open_timeout: 1, | ||
headers: { "User-Agent" => "Super fun user agent" }, | ||
proxy: "https://username:[email protected]:12345" | ||
} | ||
} | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,24 @@ def create_model(password) | |
with(headers: { "User-Agent" => "Super fun user agent" })). | ||
to have_been_made.once | ||
end | ||
|
||
it "allows the proxy to be set" do | ||
Model.validates :password, not_pwned: { | ||
request_options: { proxy: "https://username:[email protected]:12345" } | ||
} | ||
model = create_model("password") | ||
|
||
# Webmock doesn't support proxy assertions (https://github.com/bblimke/webmock/issues/753) | ||
# so we check that Net::HTTP receives the correct arguments. | ||
expect(Net::HTTP).to receive(:start). | ||
with("api.pwnedpasswords.com", 443, "example.com", 12345, "username", "password", anything). | ||
and_call_original | ||
|
||
expect(model).to_not be_valid | ||
expect(a_request(:get, "https://api.pwnedpasswords.com/range/5BAA6"). | ||
with(headers: { "User-Agent" => "Ruby Pwned::Password #{Pwned::VERSION}" })). | ||
to have_been_made.once | ||
end | ||
end | ||
|
||
describe "when not pwned", pwned_range: "37D5B" do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,23 @@ def verify_not_found_error(error) | |
with(headers: { "User-Agent" => "Super fun user agent" })). | ||
to have_been_made.once | ||
end | ||
|
||
it "allows the proxy to be set" do | ||
proxy = "https://username:[email protected]:12345" | ||
|
||
# Webmock doesn't support proxy assertions (https://github.com/bblimke/webmock/issues/753) | ||
# so we check that Net::HTTP receives the correct arguments. | ||
expect(Net::HTTP).to receive(:start). | ||
with("api.pwnedpasswords.com", 443, "example.com", 12345, "username", "password", anything). | ||
and_call_original | ||
|
||
password = Pwned::Password.new("password", proxy: proxy) | ||
password.pwned? | ||
|
||
expect(a_request(:get, "https://api.pwnedpasswords.com/range/5BAA6"). | ||
with(headers: { "User-Agent" => "Ruby Pwned::Password #{Pwned::VERSION}" })). | ||
to have_been_made.once | ||
end | ||
end | ||
|
||
describe "streaming", pwned_range: "A0F41" do | ||
|