Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

ensure Rack::Protection::Base#random_string always outputs 32 characters #69

Merged
merged 1 commit into from Sep 9, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rack/protection/base.rb
Expand Up @@ -99,7 +99,7 @@ def origin(env)
end

def random_string(secure = defined? SecureRandom)
secure ? SecureRandom.hex(32) : "%032x" % rand(2**128-1)
secure ? SecureRandom.hex(16) : "%032x" % rand(2**128-1)
rescue NotImplementedError
random_string false
end
Expand Down
9 changes: 9 additions & 0 deletions spec/base_spec.rb
@@ -0,0 +1,9 @@
require File.expand_path('../spec_helper.rb', __FILE__)

describe Rack::Protection::Base do
describe "#random_string" do
it "outputs a string of 32 characters" do
described_class.new(lambda {}).random_string.length.should == 32
end
end
end