Skip to content

Commit

Permalink
Merge branch '4-stable' into rzhade3/update-migration-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Heather Harvey authored Jan 11, 2022
2 parents 6809310 + 0e29f8c commit 564e891
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/octokit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ def client_without_redirects(options = {})
conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
conn = Faraday.new(conn_opts) do |http|
if basic_authenticated?
http.basic_auth(@login, @password)
http.request :basic_auth, @login, @password
elsif token_authenticated?
http.authorization 'token', @access_token
http.request :authorization, 'token', @access_token
elsif bearer_authenticated?
http.authorization 'Bearer', @bearer_token
http.request :authorization, 'Bearer', @bearer_token
end
http.headers['accept'] = options[:accept] if options.key?(:accept)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/octokit/client/pub_sub_hubbub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def pub_sub_hubbub_request(options = {})
conn = Faraday.new(:url => @api_endpoint) do |http|
http.headers[:user_agent] = user_agent
if basic_authenticated?
http.basic_auth(@login, @password)
http.request :basic_auth, @login, @password
elsif token_authenticated?
http.authorization 'token', @access_token
http.request :authorization, 'token', @access_token
end
http.request :url_encoded
http.use Octokit::Response::RaiseError
Expand Down
10 changes: 5 additions & 5 deletions lib/octokit/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def agent
http.headers[:content_type] = "application/json"
http.headers[:user_agent] = user_agent
if basic_authenticated?
http.basic_auth(@login, @password)
http.request :basic_auth, @login, @password
elsif token_authenticated?
http.authorization 'token', @access_token
http.request :authorization, 'token', @access_token
elsif bearer_authenticated?
http.authorization 'Bearer', @bearer_token
http.request :authorization, 'Bearer', @bearer_token
elsif application_authenticated?
http.basic_auth(@client_id, @client_secret)
http.request :basic_auth, @client_id, @client_secret
end
end
end
Expand Down Expand Up @@ -176,7 +176,7 @@ def sawyer_options
:links_parser => Sawyer::LinkParsers::Simple.new
}
conn_opts = @connection_options
conn_opts[:builder] = @middleware if @middleware
conn_opts[:builder] = @middleware.dup if @middleware
conn_opts[:proxy] = @proxy if @proxy
if conn_opts[:ssl].nil?
conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
Expand Down
5 changes: 4 additions & 1 deletion lib/octokit/middleware/follow_redirects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def update_env(env, request_body, response)
original_url = env[:url]
env[:url] += safe_escape(response["location"])
unless same_host?(original_url, env[:url])
env[:request_headers].delete("Authorization")
# HACK: Faraday’s Authorization middlewares don’t touch the request if the `Authorization` header is set.
# This is a workaround to drop authentication info.
# See https://github.com/octokit/octokit.rb/pull/1359#issuecomment-925609697
env[:request_headers]["Authorization"] = "dummy"
end

if convert_to_get?(response)
Expand Down
5 changes: 4 additions & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
require 'webmock/rspec'
require 'base64'
require 'jwt'
require 'pry-byebug'
# latest version of pry-byebug is not compatible with Ruby 3.2.0
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2.0')
require 'pry-byebug'
end

WebMock.disable_net_connect!()

Expand Down
2 changes: 1 addition & 1 deletion spec/octokit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@

assert_requested original_request
assert_requested(:get, "https://example.com/bar") { |req|
req.headers["Authorization"].nil?
req.headers["Authorization"] == "dummy"
}
end

Expand Down

0 comments on commit 564e891

Please sign in to comment.