Skip to content

Commit 1517196

Browse files
committed
added test
1 parent 938b858 commit 1517196

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ Style/StringLiterals:
4444
Style/TrailingCommaInArguments:
4545
EnforcedStyleForMultiline: comma
4646

47-
Style/TrailingCommaInLiteral:
47+
Style/TrailingCommaInArrayLiteral:
4848
EnforcedStyleForMultiline: comma

lib/omniauth-oauth2.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
require "omniauth-oauth2/version" # rubocop:disable FileName
1+
require "omniauth-oauth2/version"
22
require "omniauth/strategies/oauth2"

lib/omniauth/strategies/oauth2.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ def options_for(option)
106106
end
107107

108108
# constant-time comparison algorithm to prevent timing attacks
109-
def secure_compare(a, b)
110-
return false unless a.bytesize == b.bytesize
109+
def secure_compare(string_a, string_b)
110+
return false unless string_a.bytesize == string_b.bytesize
111111

112-
l = a.unpack "C#{a.bytesize}"
112+
l = string_a.unpack "C#{string_a.bytesize}"
113113

114114
res = 0
115-
b.each_byte { |byte| res |= byte ^ l.shift }
116-
res == 0
115+
string_b.each_byte { |byte| res |= byte ^ l.shift }
116+
res.zero?
117117
end
118118

119119
# An error that is indicated in the OAuth 2.0 callback.

spec/omniauth/strategies/oauth2_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ def app
8787
instance.callback_phase
8888
end
8989
end
90+
91+
describe "#secure_params" do
92+
subject { fresh_strategy }
93+
94+
it "returns true when the two inputs are the same and false otherwise" do
95+
instance = subject.new("abc", "def")
96+
expect(instance.send(:secure_compare, "a", "a")).to be true
97+
expect(instance.send(:secure_compare, "b", "a")).to be false
98+
end
99+
end
90100
end
91101

92102
describe OmniAuth::Strategies::OAuth2::CallbackError do

0 commit comments

Comments
 (0)