Skip to content

Commit c65a015

Browse files
committed
added test
1 parent 08ae7cf commit c65a015

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

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)