Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions .rubocop_gradual.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[66, 5, 20, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 2485198147],
[78, 5, 74, "Style/InvertibleUnlessCondition: Prefer `if Gem.rubygems_version >= Gem::Version.new(\"2.7.0\")` over `unless Gem.rubygems_version < Gem::Version.new(\"2.7.0\")`.", 2453573257]
],
"lib/oauth2.rb:3930909031": [
[31, 5, 21, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 622027168],
[34, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
"lib/oauth2.rb:3563577000": [
[34, 5, 21, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 622027168],
[37, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
],
"lib/oauth2/authenticator.rb:3711266135": [
[42, 5, 113, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 734523108]
Expand All @@ -28,11 +28,11 @@
[130, 3, 52, "Gemspec/DependencyVersion: Dependency version specification is required.", 3163430777],
[131, 3, 48, "Gemspec/DependencyVersion: Dependency version specification is required.", 425065368]
],
"spec/oauth2/access_token_spec.rb:388877639": [
"spec/oauth2/access_token_spec.rb:2406469319": [
[3, 1, 34, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/access_token*_spec.rb`.", 1972107547],
[594, 13, 25, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 770233088],
[664, 9, 101, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3022740639],
[668, 9, 79, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2507338967]
[612, 13, 25, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 770233088],
[682, 9, 101, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3022740639],
[686, 9, 79, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2507338967]
],
"spec/oauth2/authenticator_spec.rb:853320290": [
[3, 1, 36, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/authenticator*_spec.rb`.", 819808017],
Expand All @@ -41,26 +41,26 @@
[69, 15, 38, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1480816240],
[79, 13, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2314399065]
],
"spec/oauth2/client_spec.rb:824695973": [
"spec/oauth2/client_spec.rb:623759711": [
[6, 1, 29, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/client*_spec.rb`.", 439549885],
[174, 7, 492, "RSpec/NoExpectationExample: No expectation found in this example.", 1272021224],
[193, 7, 592, "RSpec/NoExpectationExample: No expectation found in this example.", 3428877205],
[206, 15, 20, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2320605227],
[221, 15, 20, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1276531672],
[236, 15, 43, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1383956904],
[251, 15, 43, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3376202107],
[869, 5, 360, "RSpec/NoExpectationExample: No expectation found in this example.", 536201463],
[878, 5, 461, "RSpec/NoExpectationExample: No expectation found in this example.", 3392600621],
[889, 5, 340, "RSpec/NoExpectationExample: No expectation found in this example.", 244592251],
[934, 63, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785],
[979, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
[983, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
[991, 7, 89, "RSpec/NoExpectationExample: No expectation found in this example.", 4609419],
[1079, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
[1083, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
[1163, 17, 12, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 664794325],
[1188, 5, 459, "RSpec/NoExpectationExample: No expectation found in this example.", 2216851076],
[1198, 7, 450, "RSpec/NoExpectationExample: No expectation found in this example.", 2619808549]
[865, 5, 360, "RSpec/NoExpectationExample: No expectation found in this example.", 536201463],
[874, 5, 461, "RSpec/NoExpectationExample: No expectation found in this example.", 3392600621],
[885, 5, 340, "RSpec/NoExpectationExample: No expectation found in this example.", 244592251],
[930, 63, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785],
[975, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
[979, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
[987, 7, 89, "RSpec/NoExpectationExample: No expectation found in this example.", 4609419],
[1075, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
[1079, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
[1159, 17, 12, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 664794325],
[1184, 5, 459, "RSpec/NoExpectationExample: No expectation found in this example.", 2216851076],
[1194, 7, 450, "RSpec/NoExpectationExample: No expectation found in this example.", 2619808549]
],
"spec/oauth2/error_spec.rb:1209122273": [
[23, 1, 28, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/error*_spec.rb`.", 3385870076],
Expand Down Expand Up @@ -97,8 +97,7 @@
"spec/oauth2/version_spec.rb:1001406821": [
[3, 1, 30, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/version*_spec.rb`.", 1099517182]
],
"spec/oauth2_spec.rb:1511642301": [
[3, 1, 21, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2*_spec.rb`.", 3359091140],
[5, 68, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785]
"spec/oauth2_spec.rb:2292862590": [
[3, 1, 21, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2*_spec.rb`.", 3359091140]
]
}
5 changes: 4 additions & 1 deletion lib/oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

# The namespace of this library
module OAuth2
DEFAULT_CONFIG = SnakyHash::SymbolKeyed.new(silence_extra_tokens_warning: false)
OAUTH_DEBUG = ENV.fetch("OAUTH_DEBUG", "false").casecmp("true").zero?
DEFAULT_CONFIG = SnakyHash::SymbolKeyed.new(
silence_extra_tokens_warning: true,
)
@config = DEFAULT_CONFIG.dup
class << self
attr_accessor :config
Expand Down
2 changes: 1 addition & 1 deletion lib/oauth2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def build_access_token_legacy(response, access_token_opts, extract_access_token)
end

def oauth_debug_logging(builder)
builder.response(:logger, options[:logger], bodies: true) if ENV["OAUTH_DEBUG"] == "true"
builder.response(:logger, options[:logger], bodies: true) if OAuth2::OAUTH_DEBUG
end
end
end
18 changes: 18 additions & 0 deletions spec/oauth2/access_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
end
end

before do
@original_setw = OAuth2.config.silence_extra_tokens_warning
OAuth2.config.silence_extra_tokens_warning = false
end

after do
OAuth2.config.silence_extra_tokens_warning = @original_setw
end

it "warns on STDERR" do
msg = <<-MSG.lstrip
OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key ([:access_token, :id_token]); using :access_token.
Expand Down Expand Up @@ -89,6 +98,15 @@
end
end

before do
@original_setw = OAuth2.config.silence_extra_tokens_warning
OAuth2.config.silence_extra_tokens_warning = false
end

after do
OAuth2.config.silence_extra_tokens_warning = @original_setw
end

let(:hash) do
{
id_token: "confusing bug here",
Expand Down
36 changes: 16 additions & 20 deletions spec/oauth2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,12 @@

describe "#connection" do
context "when debugging" do
include_context "with stubbed env"
before do
stub_env("OAUTH_DEBUG" => debug_value)
stub_const("OAuth2::OAUTH_DEBUG", debug_value)
end

context "when OAUTH_DEBUG=true" do
let(:debug_value) { "true" }
let(:debug_value) { true }

it "smoothly handles successive requests" do
silence_all do
Expand Down Expand Up @@ -301,7 +300,7 @@
end

context "when OAUTH_DEBUG=false" do
let(:debug_value) { "false" }
let(:debug_value) { false }

it "smoothly handles successive requests" do
silence_all do
Expand Down Expand Up @@ -357,24 +356,21 @@
expect(response.headers).to eq("Content-Type" => "text/awesome")
end

context "with ENV" do
include_context "with stubbed env"
context "when OAUTH_DEBUG=true" do
before do
stub_env("OAUTH_DEBUG" => "true")
end
context "when silence_extra_tokens_warning=false" do
before do
stub_const("OAuth2::OAUTH_DEBUG", true)
end

it "outputs to $stdout when OAUTH_DEBUG=true" do
output = capture(:stdout) do
subject.request(:get, "/success")
end
logs = [
"request: GET https://api.example.com/success",
"response: Status 200",
'response: Content-Type: "text/awesome"',
]
expect(output).to include(*logs)
it "outputs to $stdout when OAUTH_DEBUG=true" do
output = capture(:stdout) do
subject.request(:get, "/success")
end
logs = [
"request: GET https://api.example.com/success",
"response: Status 200",
'response: Content-Type: "text/awesome"',
]
expect(output).to include(*logs)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/oauth2_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

RSpec.describe OAuth2 do
it "has a default config for silence_extra_tokens_warning" do
expect(described_class.config.silence_extra_tokens_warning).to eq(false)
it "silence_extra_tokens_warning default is opposite of OAUTH_DEBUG" do
expect(described_class.config.silence_extra_tokens_warning).to be(true)
end

describe ".configure" do
Expand Down
Loading