Skip to content

Commit d1bc745

Browse files
committed
Merge branch 'feat/OAUTH_DEBUG' into 'main'
✨ OAuth2::OAUTH_DEBUG See merge request oauth-xx/oauth2!645
2 parents 8434f5a + 53a817a commit d1bc745

File tree

6 files changed

+63
-47
lines changed

6 files changed

+63
-47
lines changed

.rubocop_gradual.lock

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[66, 5, 20, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 2485198147],
44
[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]
55
],
6-
"lib/oauth2.rb:3930909031": [
7-
[31, 5, 21, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 622027168],
8-
[34, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
6+
"lib/oauth2.rb:3563577000": [
7+
[34, 5, 21, "ThreadSafety/ClassAndModuleAttributes: Avoid mutating class and module attributes.", 622027168],
8+
[37, 11, 7, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 651502127]
99
],
1010
"lib/oauth2/authenticator.rb:3711266135": [
1111
[42, 5, 113, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 734523108]
@@ -28,11 +28,11 @@
2828
[130, 3, 52, "Gemspec/DependencyVersion: Dependency version specification is required.", 3163430777],
2929
[131, 3, 48, "Gemspec/DependencyVersion: Dependency version specification is required.", 425065368]
3030
],
31-
"spec/oauth2/access_token_spec.rb:388877639": [
31+
"spec/oauth2/access_token_spec.rb:2406469319": [
3232
[3, 1, 34, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/access_token*_spec.rb`.", 1972107547],
33-
[594, 13, 25, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 770233088],
34-
[664, 9, 101, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3022740639],
35-
[668, 9, 79, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2507338967]
33+
[612, 13, 25, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 770233088],
34+
[682, 9, 101, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3022740639],
35+
[686, 9, 79, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2507338967]
3636
],
3737
"spec/oauth2/authenticator_spec.rb:853320290": [
3838
[3, 1, 36, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/authenticator*_spec.rb`.", 819808017],
@@ -41,26 +41,26 @@
4141
[69, 15, 38, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1480816240],
4242
[79, 13, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2314399065]
4343
],
44-
"spec/oauth2/client_spec.rb:824695973": [
44+
"spec/oauth2/client_spec.rb:623759711": [
4545
[6, 1, 29, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/client*_spec.rb`.", 439549885],
4646
[174, 7, 492, "RSpec/NoExpectationExample: No expectation found in this example.", 1272021224],
4747
[193, 7, 592, "RSpec/NoExpectationExample: No expectation found in this example.", 3428877205],
4848
[206, 15, 20, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2320605227],
4949
[221, 15, 20, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1276531672],
5050
[236, 15, 43, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1383956904],
5151
[251, 15, 43, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3376202107],
52-
[869, 5, 360, "RSpec/NoExpectationExample: No expectation found in this example.", 536201463],
53-
[878, 5, 461, "RSpec/NoExpectationExample: No expectation found in this example.", 3392600621],
54-
[889, 5, 340, "RSpec/NoExpectationExample: No expectation found in this example.", 244592251],
55-
[934, 63, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785],
56-
[979, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
57-
[983, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
58-
[991, 7, 89, "RSpec/NoExpectationExample: No expectation found in this example.", 4609419],
59-
[1079, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
60-
[1083, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
61-
[1163, 17, 12, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 664794325],
62-
[1188, 5, 459, "RSpec/NoExpectationExample: No expectation found in this example.", 2216851076],
63-
[1198, 7, 450, "RSpec/NoExpectationExample: No expectation found in this example.", 2619808549]
52+
[865, 5, 360, "RSpec/NoExpectationExample: No expectation found in this example.", 536201463],
53+
[874, 5, 461, "RSpec/NoExpectationExample: No expectation found in this example.", 3392600621],
54+
[885, 5, 340, "RSpec/NoExpectationExample: No expectation found in this example.", 244592251],
55+
[930, 63, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785],
56+
[975, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
57+
[979, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
58+
[987, 7, 89, "RSpec/NoExpectationExample: No expectation found in this example.", 4609419],
59+
[1075, 11, 99, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3084776886],
60+
[1079, 11, 82, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1524553529],
61+
[1159, 17, 12, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 664794325],
62+
[1184, 5, 459, "RSpec/NoExpectationExample: No expectation found in this example.", 2216851076],
63+
[1194, 7, 450, "RSpec/NoExpectationExample: No expectation found in this example.", 2619808549]
6464
],
6565
"spec/oauth2/error_spec.rb:1209122273": [
6666
[23, 1, 28, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/error*_spec.rb`.", 3385870076],
@@ -97,8 +97,7 @@
9797
"spec/oauth2/version_spec.rb:1001406821": [
9898
[3, 1, 30, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/version*_spec.rb`.", 1099517182]
9999
],
100-
"spec/oauth2_spec.rb:1511642301": [
101-
[3, 1, 21, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2*_spec.rb`.", 3359091140],
102-
[5, 68, 2, "RSpec/BeEq: Prefer `be` over `eq`.", 5860785]
100+
"spec/oauth2_spec.rb:2292862590": [
101+
[3, 1, 21, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2*_spec.rb`.", 3359091140]
103102
]
104103
}

lib/oauth2.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
# The namespace of this library
2727
module OAuth2
28-
DEFAULT_CONFIG = SnakyHash::SymbolKeyed.new(silence_extra_tokens_warning: false)
28+
OAUTH_DEBUG = ENV.fetch("OAUTH_DEBUG", "false").casecmp("true").zero?
29+
DEFAULT_CONFIG = SnakyHash::SymbolKeyed.new(
30+
silence_extra_tokens_warning: true,
31+
)
2932
@config = DEFAULT_CONFIG.dup
3033
class << self
3134
attr_accessor :config

lib/oauth2/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def build_access_token_legacy(response, access_token_opts, extract_access_token)
449449
end
450450

451451
def oauth_debug_logging(builder)
452-
builder.response(:logger, options[:logger], bodies: true) if ENV["OAUTH_DEBUG"] == "true"
452+
builder.response(:logger, options[:logger], bodies: true) if OAuth2::OAUTH_DEBUG
453453
end
454454
end
455455
end

spec/oauth2/access_token_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
end
5151
end
5252

53+
before do
54+
@original_setw = OAuth2.config.silence_extra_tokens_warning
55+
OAuth2.config.silence_extra_tokens_warning = false
56+
end
57+
58+
after do
59+
OAuth2.config.silence_extra_tokens_warning = @original_setw
60+
end
61+
5362
it "warns on STDERR" do
5463
msg = <<-MSG.lstrip
5564
OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key ([:access_token, :id_token]); using :access_token.
@@ -89,6 +98,15 @@
8998
end
9099
end
91100

101+
before do
102+
@original_setw = OAuth2.config.silence_extra_tokens_warning
103+
OAuth2.config.silence_extra_tokens_warning = false
104+
end
105+
106+
after do
107+
OAuth2.config.silence_extra_tokens_warning = @original_setw
108+
end
109+
92110
let(:hash) do
93111
{
94112
id_token: "confusing bug here",

spec/oauth2/client_spec.rb

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,12 @@
267267

268268
describe "#connection" do
269269
context "when debugging" do
270-
include_context "with stubbed env"
271270
before do
272-
stub_env("OAUTH_DEBUG" => debug_value)
271+
stub_const("OAuth2::OAUTH_DEBUG", debug_value)
273272
end
274273

275274
context "when OAUTH_DEBUG=true" do
276-
let(:debug_value) { "true" }
275+
let(:debug_value) { true }
277276

278277
it "smoothly handles successive requests" do
279278
silence_all do
@@ -301,7 +300,7 @@
301300
end
302301

303302
context "when OAUTH_DEBUG=false" do
304-
let(:debug_value) { "false" }
303+
let(:debug_value) { false }
305304

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

360-
context "with ENV" do
361-
include_context "with stubbed env"
362-
context "when OAUTH_DEBUG=true" do
363-
before do
364-
stub_env("OAUTH_DEBUG" => "true")
365-
end
359+
context "when silence_extra_tokens_warning=false" do
360+
before do
361+
stub_const("OAuth2::OAUTH_DEBUG", true)
362+
end
366363

367-
it "outputs to $stdout when OAUTH_DEBUG=true" do
368-
output = capture(:stdout) do
369-
subject.request(:get, "/success")
370-
end
371-
logs = [
372-
"request: GET https://api.example.com/success",
373-
"response: Status 200",
374-
'response: Content-Type: "text/awesome"',
375-
]
376-
expect(output).to include(*logs)
364+
it "outputs to $stdout when OAUTH_DEBUG=true" do
365+
output = capture(:stdout) do
366+
subject.request(:get, "/success")
377367
end
368+
logs = [
369+
"request: GET https://api.example.com/success",
370+
"response: Status 200",
371+
'response: Content-Type: "text/awesome"',
372+
]
373+
expect(output).to include(*logs)
378374
end
379375
end
380376

spec/oauth2_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

33
RSpec.describe OAuth2 do
4-
it "has a default config for silence_extra_tokens_warning" do
5-
expect(described_class.config.silence_extra_tokens_warning).to eq(false)
4+
it "silence_extra_tokens_warning default is opposite of OAUTH_DEBUG" do
5+
expect(described_class.config.silence_extra_tokens_warning).to be(true)
66
end
77

88
describe ".configure" do

0 commit comments

Comments
 (0)