insecure_random 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/LICENSE.txt +17 -18
- data/README.md +66 -14
- data/insecure_random.gemspec +31 -13
- data/lib/insecure_random/version.rb +5 -0
- data/lib/insecure_random.rb +91 -5
- metadata +36 -28
- data/.gitignore +0 -17
- data/.travis.yml +0 -5
- data/Gemfile +0 -7
- data/Rakefile +0 -6
- data/spec/insecure_random_spec.rb +0 -84
- data/spec/spec_helper.rb +0 -6
- data/spec/support/random.rb +0 -3
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MjU4N2I2NGEzNjExZDNkMDg4MDExZDA3YTU0MDAxNzUzNGVkNDdjYzY3NzNm
|
10
|
-
ODQwYzk3ZmU5MmIzMDk4N2EwNjRlZWVkYTdiYmEwYzg4NmE1NmMyYzZmNDA2
|
11
|
-
MjhiODIzY2RhY2I5YmNlYTI0YzlkMmMwZmIxMjVhMWU1YTI2YmY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YzQzNjhlZmIwYTY3MjIwNjgyZTY2Zjg5YjRkNmI3ZWU3NDdlYjE3ODIzMTA4
|
14
|
-
MTE1OWUwNGE1MDgxZjAwMTQxOWRjOTRkYWU2YTA3NGIwOTllYmYwNGQ0YTAy
|
15
|
-
NTczZDc4OGY1M2U4YTU0NDcwOTU0ZTNmODhkMjZmZjRkZmM0YzE=
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a09a60eb5b61a7ea572735249dd0cf17ea60e9f00b352daef94482888e0cc22c
|
4
|
+
data.tar.gz: 2b714c8a2e666c94513d30031bf7f079391ed218acdc1da8e2d5719ca0212df1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33e0c230f00c79e49685785d0141df4c773fa40fd72d531f11c9d8b1c0ca29162fe1cf14574f0ca7e1a2999471487129876e96a3040a99daca561c834efd3fc7
|
7
|
+
data.tar.gz: dffa6a02b7b9952acc5c33a4dd1d3e215a7ea5800b87f35ca12cdecec87658aca2e17868254d151a57361cfe36d40d4bcff408b87e298a9a91806342db09f0d6
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2013 Steve Richert
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
|
1
|
+
<h1>
|
2
|
+
<picture>
|
3
|
+
<source media="(prefers-color-scheme: light)" srcset="https://github.com/user-attachments/assets/5c2a7f3b-71ec-4270-a613-9acebd783af5">
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/8cf2884e-a505-4187-87c6-282969e32f40">
|
5
|
+
<img alt="Insecure Random" src="https://github.com/user-attachments/assets/5c2a7f3b-71ec-4270-a613-9acebd783af5" style="height:2em">
|
6
|
+
</picture>
|
7
|
+
</h1>
|
2
8
|
|
3
|
-
|
4
|
-
[](https://travis-ci.org/laserlemon/insecure_random)
|
5
|
-
[](https://codeclimate.com/github/laserlemon/insecure_random)
|
6
|
-
[](https://coveralls.io/r/laserlemon/insecure_random)
|
7
|
-
[](https://gemnasium.com/laserlemon/insecure_random)
|
9
|
+
InsecureRandom hooks into SecureRandom to enable predictability via seeding.
|
8
10
|
|
9
|
-
|
11
|
+
[](https://github.com/laserlemon)
|
12
|
+
[](https://rubygems.org/gems/insecure_random)
|
13
|
+
[](https://github.com/laserlemon/insecure_random/actions/workflows/test.yml)
|
10
14
|
|
11
15
|
## Why?
|
12
16
|
|
@@ -33,10 +37,10 @@ rspec --seed=93487
|
|
33
37
|
|
34
38
|
RSpec does this by seeding and using `Kernel.rand` to order your specs. This has
|
35
39
|
the handy side effect of making other random test data reproducible as well. For
|
36
|
-
example, your Factory
|
40
|
+
example, your Factory Bot factories might use random data via Faker.
|
37
41
|
|
38
42
|
```ruby
|
39
|
-
|
43
|
+
FactoryBot.define do
|
40
44
|
factory :user do
|
41
45
|
name { Faker::Name.name }
|
42
46
|
age { rand(100) }
|
@@ -64,11 +68,28 @@ predictable way.
|
|
64
68
|
|
65
69
|
### The Solution
|
66
70
|
|
67
|
-
Fortunately, SecureRandom only defines a handful of methods so it's
|
68
|
-
override them to be backed by `Kernel.rand`.
|
71
|
+
Fortunately, SecureRandom only defines a handful of methods so it's relatively
|
72
|
+
easy to override them to be backed by `Kernel.rand`.
|
69
73
|
|
70
|
-
And it gets even better. All of SecureRandom's methods are derived from
|
71
|
-
`SecureRandom.
|
74
|
+
And it gets even better. All of SecureRandom's methods are derived from just
|
75
|
+
one method: `SecureRandom.gen_random`. So overriding that one method does the
|
76
|
+
trick!
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
Kernel.srand(123)
|
80
|
+
SecureRandom.alphanumeric # => "kMupcJV93fBPd34p"
|
81
|
+
SecureRandom.alphanumeric # => "WTiAHSCC3JeqYAdJ"
|
82
|
+
Kernel.srand(123)
|
83
|
+
SecureRandom.alphanumeric # => "jID3bLAGYx2FHi27"
|
84
|
+
|
85
|
+
InsecureRandom.enable!
|
86
|
+
|
87
|
+
Kernel.srand(123)
|
88
|
+
SecureRandom.alphanumeric # => "2YmG5zns39eGRfKQ"
|
89
|
+
SecureRandom.alphanumeric # => "c58d341u4OJzkTyD"
|
90
|
+
Kernel.srand(123)
|
91
|
+
SecureRandom.alphanumeric # => "2YmG5zns39eGRfKQ"
|
92
|
+
```
|
72
93
|
|
73
94
|
## Installation
|
74
95
|
|
@@ -80,4 +101,35 @@ group :development, :test do
|
|
80
101
|
end
|
81
102
|
```
|
82
103
|
|
83
|
-
|
104
|
+
## Usage
|
105
|
+
|
106
|
+
As of InsecureRandom 2.0, SecureRandom's behavior remains entirely unchanged
|
107
|
+
until you explicitly enable InsecureRandom by adding the following to your
|
108
|
+
test/spec helper:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
InsecureRandom.enable!
|
112
|
+
```
|
113
|
+
|
114
|
+
The `enable!` method globally enables repeatable results from SecureRandom via
|
115
|
+
`Kernel.srand` seeding and can be disabled again with `InsecureRandom.disable!`.
|
116
|
+
|
117
|
+
You may also use the `enable` method to _temporarily_ enable SecureRandom
|
118
|
+
repeatability, only during execution of the given block. For example, RSpec
|
119
|
+
can be configured to enable InsecureRandom for each individual example:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
RSpec.configure do |config|
|
123
|
+
config.around(:example) do |example|
|
124
|
+
InsecureRandom.enable do
|
125
|
+
example.run
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
:star: InsecureRandom does not change SecureRandom's behavior until either the
|
132
|
+
`InsecureRandom.enable!` or `InsecureRandom.enable` method is explicitly called.
|
133
|
+
That said…
|
134
|
+
|
135
|
+
:warning: **Make sure that InsecureRandom is not enabled in production!** :warning:
|
data/insecure_random.gemspec
CHANGED
@@ -1,19 +1,37 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
spec.name = "insecure_random"
|
5
|
-
spec.version = "1.0.0"
|
3
|
+
require_relative "lib/insecure_random/version"
|
6
4
|
|
7
|
-
|
8
|
-
spec.
|
9
|
-
spec.summary
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "insecure_random"
|
7
|
+
spec.summary = "Like SecureRandom, but less… secure"
|
10
8
|
spec.description = "InsecureRandom overwrites SecureRandom to enable predictability via seeding."
|
11
|
-
spec.
|
12
|
-
|
9
|
+
spec.version = InsecureRandom::VERSION
|
10
|
+
|
11
|
+
spec.author = "Steve Richert"
|
12
|
+
spec.email = "steve.richert@hey.com"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.homepage = "https://github.com/laserlemon/insecure_random"
|
15
|
+
|
16
|
+
spec.metadata = {
|
17
|
+
"allowed_push_host" => "https://rubygems.org",
|
18
|
+
"bug_tracker_uri" => "https://github.com/laserlemon/insecure_random/issues",
|
19
|
+
"funding_uri" => "https://github.com/sponsors/laserlemon",
|
20
|
+
"homepage_uri" => "https://github.com/laserlemon/insecure_random",
|
21
|
+
"rubygems_mfa_required" => "true",
|
22
|
+
"source_code_uri" => "https://github.com/laserlemon/insecure_random",
|
23
|
+
}
|
24
|
+
|
25
|
+
spec.required_ruby_version = ">= 3.0.0"
|
26
|
+
spec.add_development_dependency "bundler", ">= 2"
|
27
|
+
spec.add_development_dependency "rake", ">= 13"
|
13
28
|
|
14
|
-
spec.files
|
15
|
-
|
16
|
-
|
29
|
+
spec.files = [
|
30
|
+
"insecure_random.gemspec",
|
31
|
+
"lib/insecure_random.rb",
|
32
|
+
"lib/insecure_random/version.rb",
|
33
|
+
"LICENSE.txt",
|
34
|
+
]
|
17
35
|
|
18
|
-
spec.
|
36
|
+
spec.extra_rdoc_files = ["README.md"]
|
19
37
|
end
|
data/lib/insecure_random.rb
CHANGED
@@ -1,8 +1,94 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The InsecureRandom module is the interface for enabling and disabling the
|
4
|
+
# ability to seed SecureRandom's output. Outside of enabling or disabling this
|
5
|
+
# ability, there should be no need to call methods on the InsecureRandom module
|
6
|
+
# directly. Simply use SecureRandom as you normally would, with the confidence
|
7
|
+
# that its output is now repeatable by seeding via Kernel.srand.
|
8
|
+
module InsecureRandom
|
9
|
+
# This module is mixed into SecureRandom. Because the Hook module is empty,
|
10
|
+
# mixing it in changes no behavior, but this module gives us a foothold in
|
11
|
+
# SecureRandom so that adding instance methods to Hook module adds the same
|
12
|
+
# method to SecureRandom as a singleton method.
|
13
|
+
module Hook
|
14
|
+
end
|
15
|
+
|
16
|
+
# The Overrides module holds all of the method overrides necessary to change
|
17
|
+
# SecureRandom's behavior to repeatable by seeding.
|
18
|
+
module Overrides
|
19
|
+
def gen_random(n)
|
20
|
+
Random.bytes(n)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns whether SecureRandom's behavior is currently repeatable by seeding.
|
25
|
+
def self.enabled?
|
26
|
+
Hook.instance_methods.any?
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns whether SecureRandom's behavior is not currently repeatable.
|
30
|
+
def self.disabled?
|
31
|
+
!enabled?
|
32
|
+
end
|
33
|
+
|
34
|
+
# Change SecureRandom's behavior to be repeatable by seeding. Enablement
|
35
|
+
# occurs globally and remains enabled until explicitly disabled. See:
|
36
|
+
# InsecureRandom.disable! below.
|
37
|
+
#
|
38
|
+
# Returns true if enabled successfully or false if already enabled.
|
39
|
+
def self.enable!
|
40
|
+
return false if enabled?
|
41
|
+
|
42
|
+
Overrides.instance_methods.each do |method|
|
43
|
+
Hook.define_method(method, Overrides.instance_method(method))
|
44
|
+
end
|
2
45
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
# Reverts SecureRandom's behavior to no longer be repeatable by seeding.
|
50
|
+
# Disablement occurs globally and remains disabled until explicity
|
51
|
+
# enabled. See: InsecureRandom.enable! above.
|
52
|
+
#
|
53
|
+
# Returns true if disabled successfully or false if already disabled.
|
54
|
+
def self.disable!
|
55
|
+
return false unless enabled?
|
56
|
+
|
57
|
+
Hook.instance_methods.each do |method|
|
58
|
+
Hook.remove_method(method)
|
59
|
+
end
|
60
|
+
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
# Enables SecureRandom's repeatable behavior for the duration of the given
|
65
|
+
# block, then reliably restores SecureRandom's original enablement.
|
66
|
+
#
|
67
|
+
# Returns the return value of the given block.
|
68
|
+
def self.enable
|
69
|
+
toggled = enable!
|
70
|
+
yield
|
71
|
+
ensure
|
72
|
+
disable! if toggled
|
73
|
+
end
|
74
|
+
|
75
|
+
# Disables SecureRandom's repeatable behavior for the duration of the given
|
76
|
+
# block, then reliably restores SecureRandom's original enablement.
|
77
|
+
#
|
78
|
+
# Returns the return value of the given block.
|
79
|
+
def self.disable
|
80
|
+
toggled = disable!
|
81
|
+
yield
|
82
|
+
ensure
|
83
|
+
enable! if toggled
|
7
84
|
end
|
8
85
|
end
|
86
|
+
|
87
|
+
# Install InsecureRandom.
|
88
|
+
#
|
89
|
+
# THIS DOES NOT *ENABLE* InsecureRandom. You must explicitly enable via
|
90
|
+
# the InsecureRandom.enable! or InsecureRandom.enable methods. Until
|
91
|
+
# InsecureRandom is explicitly enabled, SecureRandom's behavior remains
|
92
|
+
# entirely untouched.
|
93
|
+
require "securerandom"
|
94
|
+
SecureRandom.singleton_class.prepend(InsecureRandom::Hook)
|
metadata
CHANGED
@@ -1,71 +1,79 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insecure_random
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Richert
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-07-01 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bundler
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- -
|
16
|
+
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
18
|
+
version: '2'
|
20
19
|
type: :development
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- -
|
23
|
+
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
25
|
+
version: '2'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '13'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '13'
|
27
40
|
description: InsecureRandom overwrites SecureRandom to enable predictability via seeding.
|
28
|
-
email: steve.richert@
|
41
|
+
email: steve.richert@hey.com
|
29
42
|
executables: []
|
30
43
|
extensions: []
|
31
|
-
extra_rdoc_files:
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README.md
|
32
46
|
files:
|
33
|
-
- .gitignore
|
34
|
-
- .travis.yml
|
35
|
-
- Gemfile
|
36
47
|
- LICENSE.txt
|
37
48
|
- README.md
|
38
|
-
- Rakefile
|
39
49
|
- insecure_random.gemspec
|
40
50
|
- lib/insecure_random.rb
|
41
|
-
-
|
42
|
-
- spec/spec_helper.rb
|
43
|
-
- spec/support/random.rb
|
51
|
+
- lib/insecure_random/version.rb
|
44
52
|
homepage: https://github.com/laserlemon/insecure_random
|
45
53
|
licenses:
|
46
54
|
- MIT
|
47
|
-
metadata:
|
48
|
-
|
55
|
+
metadata:
|
56
|
+
allowed_push_host: https://rubygems.org
|
57
|
+
bug_tracker_uri: https://github.com/laserlemon/insecure_random/issues
|
58
|
+
funding_uri: https://github.com/sponsors/laserlemon
|
59
|
+
homepage_uri: https://github.com/laserlemon/insecure_random
|
60
|
+
rubygems_mfa_required: 'true'
|
61
|
+
source_code_uri: https://github.com/laserlemon/insecure_random
|
49
62
|
rdoc_options: []
|
50
63
|
require_paths:
|
51
64
|
- lib
|
52
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
66
|
requirements:
|
54
|
-
- -
|
67
|
+
- - ">="
|
55
68
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
69
|
+
version: 3.0.0
|
57
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
71
|
requirements:
|
59
|
-
- -
|
72
|
+
- - ">="
|
60
73
|
- !ruby/object:Gem::Version
|
61
74
|
version: '0'
|
62
75
|
requirements: []
|
63
|
-
|
64
|
-
rubygems_version: 2.0.3
|
65
|
-
signing_key:
|
76
|
+
rubygems_version: 3.6.2
|
66
77
|
specification_version: 4
|
67
78
|
summary: Like SecureRandom, but less… secure
|
68
|
-
test_files:
|
69
|
-
- spec/insecure_random_spec.rb
|
70
|
-
- spec/spec_helper.rb
|
71
|
-
- spec/support/random.rb
|
79
|
+
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe SecureRandom do
|
4
|
-
let(:seed) { Kernel.srand }
|
5
|
-
|
6
|
-
describe ".random_bytes" do
|
7
|
-
it "is a 16 byte string" do
|
8
|
-
value = SecureRandom.random_bytes
|
9
|
-
|
10
|
-
expect(value).to be_a(String)
|
11
|
-
expect(value.size).to eq(16)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "accepts an integer length argument" do
|
15
|
-
value = SecureRandom.random_bytes(32)
|
16
|
-
|
17
|
-
expect(value.size).to eq(32)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "accepts a decimal length argument" do
|
21
|
-
value = SecureRandom.random_bytes(32.9)
|
22
|
-
|
23
|
-
expect(value.size).to eq(32)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "accepts a nil length argument" do
|
27
|
-
value = SecureRandom.random_bytes(nil)
|
28
|
-
|
29
|
-
expect(value.size).to eq(16)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "is random-ish" do
|
33
|
-
sample = []
|
34
|
-
1000.times do
|
35
|
-
SecureRandom.random_bytes.bytes.each do |byte|
|
36
|
-
sample << byte
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# MATH!
|
41
|
-
mean = sample.inject(:+).to_f / sample.size
|
42
|
-
variance = sample.inject(0) { |memo, value|
|
43
|
-
memo + (value - mean) ** 2
|
44
|
-
}.to_f / (sample.size - 1)
|
45
|
-
actual_standard_deviation = Math.sqrt(variance)
|
46
|
-
expected_standard_deviation = Math.sqrt(((256 ** 2) - 1).to_f / 12)
|
47
|
-
|
48
|
-
expect(actual_standard_deviation).to be_within(1).
|
49
|
-
of(expected_standard_deviation)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "is reproducible" do
|
53
|
-
Kernel.srand(seed)
|
54
|
-
value1 = SecureRandom.random_bytes
|
55
|
-
|
56
|
-
Kernel.srand(seed)
|
57
|
-
value2 = SecureRandom.random_bytes
|
58
|
-
|
59
|
-
expect(value2).to eq(value1)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
%w(
|
64
|
-
hex
|
65
|
-
base64
|
66
|
-
urlsafe_base64
|
67
|
-
random_number
|
68
|
-
uuid
|
69
|
-
).each do |method|
|
70
|
-
if SecureRandom.respond_to?(method)
|
71
|
-
describe ".#{method}" do
|
72
|
-
it "is reproducible" do
|
73
|
-
Kernel.srand(seed)
|
74
|
-
value1 = SecureRandom.send(method)
|
75
|
-
|
76
|
-
Kernel.srand(seed)
|
77
|
-
value2 = SecureRandom.send(method)
|
78
|
-
|
79
|
-
expect(value2).to eq(value1)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/spec/support/random.rb
DELETED