Skip to content

Commit b4ea2ca

Browse files
committed
bump Faraday, add Appraisals
Change-Id: Ice2d4c9978095fbbe163af41b5b2a6339579dd39 Reviewed-on: https://gerrit.instructure.com/c/footrest/+/414729 Reviewed-by: Caleb Siebach <caleb.siebach@instructure.com> Tested-by: Ethan Knapp <eknapp@instructure.com> QA-Review: Ethan Knapp <eknapp@instructure.com> Product-Review: Ethan Knapp <eknapp@instructure.com>
1 parent de56a76 commit b4ea2ca

10 files changed

Lines changed: 89 additions & 28 deletions

File tree

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
name: rspec (ruby ${{ matrix.ruby }})
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
ruby: ["2.7", "3.0", "3.2", "3.3"]
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Ruby ${{ matrix.ruby }}
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: ${{ matrix.ruby }}
23+
bundler-cache: true
24+
25+
# Generate the per-Faraday gemfiles from Appraisals (not committed),
26+
# install each, then run the suite across all of them.
27+
- name: Install appraisal gemfiles
28+
run: bundle exec appraisal install
29+
30+
- name: Run specs across Faraday versions
31+
run: bundle exec appraisal rspec

Appraisals

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test matrix for the supported Faraday major versions.
2+
# Regenerate the gemfiles after editing: bundle exec appraisal generate
3+
# Run the suite across versions: bundle exec appraisal rspec
4+
5+
appraise "faraday-1" do
6+
gem "faraday", "~> 1.10"
7+
end
8+
9+
appraise "faraday-2" do
10+
gem "faraday", "~> 2.0"
11+
end

footrest.gemspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ Gem::Specification.new do |gem|
2525
gem.add_development_dependency "webmock"
2626
gem.add_development_dependency "pry"
2727
gem.add_development_dependency "byebug"
28-
gem.add_development_dependency "faraday", ">1.0.0", "< 2"
28+
gem.add_development_dependency "appraisal", "~> 2.5"
29+
gem.add_development_dependency "faraday", ">= 1.0", "< 3"
2930

30-
gem.add_dependency "faraday", ">= 0.9.0", "< 2"
31+
gem.add_dependency "faraday", ">= 1.0", "< 3"
32+
gem.add_dependency "faraday-multipart", "~> 1.0"
3133
gem.add_dependency "activesupport", ">= 3.0.0"
3234

3335
# Parses Link headers formatted according to RFC 5988 draft spec

lib/footrest.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,3 @@
44

55
module Footrest
66
end
7-
8-
module Faraday
9-
class Response::Logger < Response::Middleware
10-
private
11-
12-
SENSITIVE_HEADERS = %w{Authorization}
13-
def dump_headers(headers)
14-
return "empty headers" unless headers
15-
headers.map { |k, v|
16-
message = "#{k}: "
17-
message << (SENSITIVE_HEADERS.include?(k) ? "[filtered]" : v.inspect)
18-
}.join("\n")
19-
end
20-
end
21-
end

lib/footrest/connection.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'faraday'
2+
require 'faraday/multipart'
23
require 'footrest/http_error'
34
require 'footrest/pagination'
45
require 'footrest/follow_redirects'
@@ -14,10 +15,14 @@ def set_connection(config)
1415
@connection = Faraday.new(url: config[:prefix]) do |faraday|
1516
faraday.request :multipart
1617
faraday.request :url_encoded
17-
if config[:logger] == true
18-
faraday.response :logger
19-
elsif config[:logger]
20-
faraday.use Faraday::Response::Logger, config[:logger]
18+
if config[:logger]
19+
logger = config[:logger] == true ? nil : config[:logger]
20+
faraday.response :logger, logger do |formatter|
21+
# Keep bearer tokens out of the logs. Faraday logs request headers
22+
# by default, and dump_headers lives on the formatter in both 1.x
23+
# and 2.x, so filter here rather than monkeypatching the logger.
24+
formatter.filter(/(Authorization:\s*).*/i, '\1[FILTERED]')
25+
end
2126
end
2227
faraday.use Footrest::FollowRedirects
2328
faraday.use Footrest::ParseJson, :content_type => /\bjson$/

lib/footrest/http_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def truncated_authorization_value
7070
end
7171
end
7272

73-
class RaiseFootrestErrors < Faraday::Response::Middleware
73+
class RaiseFootrestErrors < Faraday::Middleware
7474
ERROR_MAP = {
7575
400 => Footrest::HttpError::BadRequest,
7676
401 => Footrest::HttpError::Unauthorized,

lib/footrest/pagination.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
require 'faraday'
12
require 'link_header'
23

34
module Footrest
4-
class Pagination < Faraday::Response::Middleware
5+
# Faraday 2.x removed Faraday::Response::Middleware; the on_complete hook now
6+
# lives on the unified Faraday::Middleware base (also present in 1.x).
7+
class Pagination < Faraday::Middleware
58
Links = Struct.new(:first, :prev, :current, :next, :last) do
69
alias_method :previous, :prev
710
alias_method :prevous=, :prev=

lib/footrest/parse_json.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
require 'footrest/response_middleware'
22

3+
require 'json'
4+
35
module Footrest
46
# Public: Parse response bodies as JSON.
57
class ParseJson < ResponseMiddleware
6-
dependency do
7-
require 'json' unless defined?(::JSON)
8-
end
9-
108
define_parser do |body|
119
::JSON.parse body unless body.strip.empty?
1210
end

lib/footrest/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Footrest
2-
VERSION = '0.5.8' unless defined?(Footrest::VERSION)
2+
VERSION = '0.6.0' unless defined?(Footrest::VERSION)
33
end

spec/footrest/logger_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require_relative '../spec_helper'
2+
require 'logger'
3+
require 'stringio'
4+
5+
describe "Footrest request logging" do
6+
let(:io) { StringIO.new }
7+
let(:client) do
8+
Footrest::Client.new(
9+
prefix: "http://domain.test",
10+
token: "s3cr3t~deadbeef",
11+
logger: ::Logger.new(io)
12+
)
13+
end
14+
15+
before do
16+
stub_request(:get, "http://domain.test/page").
17+
to_return(status: 200, body: "{}", headers: { content_type: "application/json" })
18+
end
19+
20+
it "redacts the Authorization bearer token from the logs" do
21+
client.get("/page")
22+
23+
expect(io.string).to include("Authorization: [FILTERED]")
24+
expect(io.string).not_to include("s3cr3t~deadbeef")
25+
end
26+
end

0 commit comments

Comments
 (0)