Skip to content

Commit

Permalink
SECURITY-8081: upgrade to faraday 2
Browse files Browse the repository at this point in the history
Co-authored-by: Istvan Demeter <[email protected]>
  • Loading branch information
knagy and qw3r committed Dec 2, 2022
1 parent 9b31887 commit d7621b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ gem install session-validator-client

## Usage


setup up the following environment variables:
Setup the following environment variables:

* `KEY_POOL`
* `SESSION_VALIDATOR_KEYID`
* `SESSION_VALIDATOR_URL`

###Validating a single Msid
### Validating a single Msid
`valid?(msid)` returns `true` if `msid` is valid

```ruby
Expand All @@ -27,7 +26,7 @@ client = SessionValidator::Client.new
client.valid?("staging_int_5ad5f96f307cf9.61063404")
```

###Batch validating multiple MSIDS
### Batch validating multiple MSIDS
`filter_invalid(msids)` returns an array of the invalid MSIDS.

```ruby
Expand All @@ -40,5 +39,6 @@ client.filter_invalid(["staging_int_5ad5f96f307cf9.61063404", "staging_int_5ad5f
## Running tests

```bash
rspec
$ bundle install
$ rspec
```
6 changes: 3 additions & 3 deletions lib/session_validator/client.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "uri"
require "escher-keypool"
require "faraday"
require "faraday_middleware"
require "faraday/retry"
require "faraday_middleware/escher"

class SessionValidator::Client
Expand All @@ -13,7 +13,7 @@ class SessionValidator::Client
date_header_name: "X-Ems-Date"
}.freeze
SERVICE_REQUEST_TIMEOUT = 2.freeze
NETWORK_ERRORS = Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed] - ['Timeout::Error']
NETWORK_ERRORS = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed] - ['Timeout::Error']

def valid?(msid)
response_status = client.get("/sessions/#{msid}", nil, headers).status
Expand All @@ -40,7 +40,7 @@ def client
faraday.options[:open_timeout] = SERVICE_REQUEST_TIMEOUT
faraday.options[:timeout] = SERVICE_REQUEST_TIMEOUT
faraday.request :retry, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2, methods: [:get, :post], exceptions: NETWORK_ERRORS
faraday.use FaradayMiddleware::Escher::RequestSigner, escher_config
faraday.use Faraday::Middleware::Escher::RequestSigner, escher_config
faraday.adapter Faraday.default_adapter
end
end
Expand Down
7 changes: 4 additions & 3 deletions session-validator-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ Gem::Specification.new do |s|
s.homepage = "https://github.com/emartech/session-validator-client-ruby"
s.licenses = ["MIT"]

s.required_ruby_version = ">= 1.9"
s.required_ruby_version = ">= 2.6"

s.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
s.require_paths = ['lib']

s.add_dependency "escher-keypool"
s.add_dependency "faraday", '~> 1.0'
s.add_dependency "faraday_middleware"
s.add_dependency "faraday", '~> 2.0', '>= 2.0.1'
s.add_dependency "faraday-retry"
s.add_dependency "faraday_middleware-escher"

s.add_development_dependency "rspec"
s.add_development_dependency "webmock"
s.add_development_dependency "rexml"
s.add_development_dependency "dotenv"
end

0 comments on commit d7621b9

Please sign in to comment.