forked from oauth-xx/oauth-ruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a "secure_equals" method to Helper to avoid timing attacks as m…
…entioned here: http://codahale.com/a-lesson-in-timing-attacks/
- Loading branch information
Showing
7 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
# encoding: utf-8 | ||
require File.dirname(__FILE__) + '/test_helper.rb' | ||
|
||
class TestOauth < Test::Unit::TestCase | ||
|
||
include OAuth::Helper | ||
|
||
def test_parameter_escaping_kcode_invariant | ||
old = $KCODE | ||
begin | ||
%w(n N e E s S u U).each do |kcode| | ||
$KCODE = kcode | ||
assert_equal '%E3%81%82', OAuth::Helper.escape('あ'), | ||
assert_equal '%E3%81%82', OAuth::Helper.escape("あ"), | ||
"Failed to correctly escape Japanese under $KCODE = #{kcode}" | ||
assert_equal '%C3%A9', OAuth::Helper.escape('é'), | ||
assert_equal '%C3%A9', OAuth::Helper.escape("é"), | ||
"Failed to correctly escape e+acute under $KCODE = #{kcode}" | ||
end | ||
ensure | ||
$KCODE = old | ||
end | ||
end | ||
|
||
def test_secure_equals | ||
[nil,1,12345,"12345",'1','Hello'*45].each do |value| | ||
assert secure_equals(value,value) | ||
end | ||
end | ||
|
||
def test_not_secure_equals | ||
a=[nil,1,12345,"12345",'1','Hello'*45] | ||
a.zip(a.reverse).each do |a,b| | ||
assert !secure_equals(a,b) | ||
end | ||
end | ||
|
||
end |