A platform for community discussion. Free, open, simple.
FIX: Twitter health check broken on Faraday update (#35407)
Ted Johanssonce1c48b1a96f
diff --git a/lib/auth/twitter_authenticator.rb b/lib/auth/twitter_authenticator.rbindex 334c4948dac..8a20a11b265 100644--- a/lib/auth/twitter_authenticator.rb+++ b/lib/auth/twitter_authenticator.rb@@ -19,8 +19,13 @@ class Auth::TwitterAuthenticator < Auth::ManagedAuthenticatordef healthy?connection =- Faraday.new(url: "https://api.twitter.com") do |config|- config.basic_auth(SiteSetting.twitter_consumer_key, SiteSetting.twitter_consumer_secret)+ Faraday.new(url: "https://api.twitter.com") do |connection|+ connection.request(+ :authorization,+ :basic,+ SiteSetting.twitter_consumer_key,+ SiteSetting.twitter_consumer_secret,+ )endconnection.post("/oauth2/token").status == 200rescue Faraday::Errordiff --git a/spec/lib/auth/twitter_authenticator_spec.rb b/spec/lib/auth/twitter_authenticator_spec.rbindex 3473f8df8e3..4f21a12a9f5 100644--- a/spec/lib/auth/twitter_authenticator_spec.rb+++ b/spec/lib/auth/twitter_authenticator_spec.rb@@ -69,13 +69,10 @@ RSpec.describe Auth::TwitterAuthenticator dodescribe "#healthy?" dolet(:authenticator) { described_class.new }- let(:connection) { mock("Faraday::Connection") }- let(:response) { mock("Faraday::Response") }-before do- Faraday.stubs(:new).returns(connection)- connection.stubs(:post).returns(response)- response.stubs(:status).returns(status)+ stub_request(:post, "https://api.twitter.com/oauth2/token").with(+ basic_auth: [SiteSetting.twitter_consumer_key, SiteSetting.twitter_consumer_secret],+ ).to_return(status:)endcontext "when endpoint is reachable" do@@ -93,7 +90,7 @@ RSpec.describe Auth::TwitterAuthenticator docontext "when an unexpected error happens" dolet(:status) { anything }- before { connection.stubs(:post).raises(Faraday::ServerError) }+ before { Faraday::Connection.any_instance.stubs(:post).raises(Faraday::ServerError) }it { expect(authenticator).not_to be_healthy }end