Sitelet https://github.com/KennaSecurity/bcrypt-ruby/commit/005335162c61b6f25a34311da476f04fa0e5a331
Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit 0053351

Browse files
committed
Merge pull request bcrypt-ruby#95 from brunohenrique/master
Little improvements
2 parents 8e82ed6 + bd4abb4 commit 0053351

3 files changed

Lines changed: 46 additions & 46 deletions

File tree

‎spec/bcrypt/engine_spec.rb‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@
44
specify "should calculate the optimal cost factor to fit in a specific time" do
55
first = BCrypt::Engine.calibrate(100)
66
second = BCrypt::Engine.calibrate(400)
7-
second.should > first
7+
expect(second).to be > first
88
end
99
end
1010

1111
describe "Generating BCrypt salts" do
1212

1313
specify "should produce strings" do
14-
BCrypt::Engine.generate_salt.should be_an_instance_of(String)
14+
expect(BCrypt::Engine.generate_salt).to be_an_instance_of(String)
1515
end
1616

1717
specify "should produce random data" do
18-
BCrypt::Engine.generate_salt.should_not equal(BCrypt::Engine.generate_salt)
18+
expect(BCrypt::Engine.generate_salt).to_not equal(BCrypt::Engine.generate_salt)
1919
end
2020

2121
specify "should raise a InvalidCostError if the cost parameter isn't numeric" do
22-
lambda { BCrypt::Engine.generate_salt('woo') }.should raise_error(BCrypt::Errors::InvalidCost)
22+
expect { BCrypt::Engine.generate_salt('woo') }.to raise_error(BCrypt::Errors::InvalidCost)
2323
end
2424

2525
specify "should raise a InvalidCostError if the cost parameter isn't greater than 0" do
26-
lambda { BCrypt::Engine.generate_salt(-1) }.should raise_error(BCrypt::Errors::InvalidCost)
26+
expect { BCrypt::Engine.generate_salt(-1) }.to raise_error(BCrypt::Errors::InvalidCost)
2727
end
2828
end
2929

3030
describe "Autodetecting of salt cost" do
3131

3232
specify "should work" do
33-
BCrypt::Engine.autodetect_cost("$2a$08$hRx2IVeHNsTSYYtUWn61Ou").should eq 8
34-
BCrypt::Engine.autodetect_cost("$2a$05$XKd1bMnLgUnc87qvbAaCUu").should eq 5
35-
BCrypt::Engine.autodetect_cost("$2a$13$Lni.CZ6z5A7344POTFBBV.").should eq 13
33+
expect(BCrypt::Engine.autodetect_cost("$2a$08$hRx2IVeHNsTSYYtUWn61Ou")).to eq 8
34+
expect(BCrypt::Engine.autodetect_cost("$2a$05$XKd1bMnLgUnc87qvbAaCUu")).to eq 5
35+
expect(BCrypt::Engine.autodetect_cost("$2a$13$Lni.CZ6z5A7344POTFBBV.")).to eq 13
3636
end
3737

3838
end
@@ -49,21 +49,21 @@ class MyInvalidSecret
4949
end
5050

5151
specify "should produce a string" do
52-
BCrypt::Engine.hash_secret(@password, @salt).should be_an_instance_of(String)
52+
expect(BCrypt::Engine.hash_secret(@password, @salt)).to be_an_instance_of(String)
5353
end
5454

5555
specify "should raise an InvalidSalt error if the salt is invalid" do
56-
lambda { BCrypt::Engine.hash_secret(@password, 'nino') }.should raise_error(BCrypt::Errors::InvalidSalt)
56+
expect { BCrypt::Engine.hash_secret(@password, 'nino') }.to raise_error(BCrypt::Errors::InvalidSalt)
5757
end
5858

5959
specify "should raise an InvalidSecret error if the secret is invalid" do
60-
lambda { BCrypt::Engine.hash_secret(MyInvalidSecret.new, @salt) }.should raise_error(BCrypt::Errors::InvalidSecret)
61-
lambda { BCrypt::Engine.hash_secret(nil, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
62-
lambda { BCrypt::Engine.hash_secret(false, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
60+
expect { BCrypt::Engine.hash_secret(MyInvalidSecret.new, @salt) }.to raise_error(BCrypt::Errors::InvalidSecret)
61+
expect { BCrypt::Engine.hash_secret(nil, @salt) }.not_to raise_error
62+
expect { BCrypt::Engine.hash_secret(false, @salt) }.not_to raise_error
6363
end
6464

6565
specify "should call #to_s on the secret and use the return value as the actual secret data" do
66-
BCrypt::Engine.hash_secret(false, @salt).should == BCrypt::Engine.hash_secret("false", @salt)
66+
expect(BCrypt::Engine.hash_secret(false, @salt)).to eq BCrypt::Engine.hash_secret("false", @salt)
6767
end
6868

6969
specify "should be interoperable with other implementations" do
@@ -76,7 +76,7 @@ class MyInvalidSecret
7676
["0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "$2a$05$abcdefghijklmnopqrstuu", "$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui"]
7777
]
7878
for secret, salt, test_vector in test_vectors
79-
BCrypt::Engine.hash_secret(secret, salt).should eql(test_vector)
79+
expect(BCrypt::Engine.hash_secret(secret, salt)).to eql(test_vector)
8080
end
8181
end
8282
end

‎spec/bcrypt/error_spec.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
shared_examples "descends from StandardError" do
66
it "can be rescued as a StandardError" do
7-
described_class.should < StandardError
7+
expect(described_class).to be < StandardError
88
end
99
end
1010

1111
shared_examples "descends from BCrypt::Error" do
1212
it "can be rescued as a BCrypt::Error" do
13-
described_class.should < BCrypt::Error
13+
expect(described_class).to be < BCrypt::Error
1414
end
1515
end
1616

‎spec/bcrypt/password_spec.rb‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
end
99

1010
specify "should return a BCrypt::Password" do
11-
@password.should be_an_instance_of(BCrypt::Password)
11+
expect(@password).to be_an_instance_of(BCrypt::Password)
1212
end
1313

1414
specify "should return a valid bcrypt password" do
15-
lambda { BCrypt::Password.new(@password) }.should_not raise_error
15+
expect { BCrypt::Password.new(@password) }.not_to raise_error
1616
end
1717

1818
specify "should behave normally if the secret is not a string" do
19-
lambda { BCrypt::Password.create(nil) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
20-
lambda { BCrypt::Password.create({:woo => "yeah"}) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
21-
lambda { BCrypt::Password.create(false) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
19+
expect { BCrypt::Password.create(nil) }.not_to raise_error
20+
expect { BCrypt::Password.create({:woo => "yeah"}) }.not_to raise_error
21+
expect { BCrypt::Password.create(false) }.not_to raise_error
2222
end
2323

2424
specify "should tolerate empty string secrets" do
25-
lambda { BCrypt::Password.create( "\n".chop ) }.should_not raise_error
26-
lambda { BCrypt::Password.create( "" ) }.should_not raise_error
27-
lambda { BCrypt::Password.create( String.new ) }.should_not raise_error
25+
expect { BCrypt::Password.create( "\n".chop ) }.not_to raise_error
26+
expect { BCrypt::Password.create( "" ) }.not_to raise_error
27+
expect { BCrypt::Password.create( String.new ) }.not_to raise_error
2828
end
2929
end
3030

@@ -35,26 +35,26 @@
3535
end
3636

3737
specify "the cost is too damn high" do
38-
lambda {
38+
expect {
3939
BCrypt::Password.create("hello", :cost => 32)
40-
}.should raise_error(ArgumentError)
40+
}.to raise_error(ArgumentError)
4141
end
4242

4343
specify "the cost should be set to the default if nil" do
44-
BCrypt::Password.create("hello", :cost => nil).cost.should equal(BCrypt::Engine::DEFAULT_COST)
44+
expect(BCrypt::Password.create("hello", :cost => nil).cost).to equal(BCrypt::Engine::DEFAULT_COST)
4545
end
4646

4747
specify "the cost should be set to the default if empty hash" do
48-
BCrypt::Password.create("hello", {}).cost.should equal(BCrypt::Engine::DEFAULT_COST)
48+
expect(BCrypt::Password.create("hello", {}).cost).to equal(BCrypt::Engine::DEFAULT_COST)
4949
end
5050

5151
specify "the cost should be set to the passed value if provided" do
52-
BCrypt::Password.create("hello", :cost => 5).cost.should equal(5)
52+
expect(BCrypt::Password.create("hello", :cost => 5).cost).to equal(5)
5353
end
5454

5555
specify "the cost should be set to the global value if set" do
5656
BCrypt::Engine.cost = 5
57-
BCrypt::Password.create("hello").cost.should equal(5)
57+
expect(BCrypt::Password.create("hello").cost).to equal(5)
5858
# unset the global value to not affect other tests
5959
BCrypt::Engine.cost = nil
6060
end
@@ -65,7 +65,7 @@
6565
old_default_cost = BCrypt::Engine::DEFAULT_COST
6666

6767
BCrypt::Engine::DEFAULT_COST = 5
68-
BCrypt::Password.create("hello").cost.should equal(5)
68+
expect(BCrypt::Password.create("hello").cost).to equal(5)
6969

7070
# reset default to not affect other tests
7171
BCrypt::Engine::DEFAULT_COST = old_default_cost
@@ -74,17 +74,17 @@
7474

7575
specify "should read the version, cost, salt, and hash" do
7676
password = BCrypt::Password.new(@hash)
77-
password.version.should eql("2a")
78-
password.cost.should equal(5)
79-
password.salt.should eql("$2a$05$CCCCCCCCCCCCCCCCCCCCC.")
80-
password.salt.class.should eq String
81-
password.checksum.should eq("E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW")
82-
password.checksum.class.should eq String
83-
password.to_s.should eql(@hash)
77+
expect(password.version).to eql("2a")
78+
expect(password.cost).to equal(5)
79+
expect(password.salt).to eql("$2a$05$CCCCCCCCCCCCCCCCCCCCC.")
80+
expect(password.salt.class).to eq String
81+
expect(password.checksum).to eq("E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW")
82+
expect(password.checksum.class).to eq String
83+
expect(password.to_s).to eql(@hash)
8484
end
8585

8686
specify "should raise an InvalidHashError when given an invalid hash" do
87-
lambda { BCrypt::Password.new('weedle') }.should raise_error(BCrypt::Errors::InvalidHash)
87+
expect { BCrypt::Password.new('weedle') }.to raise_error(BCrypt::Errors::InvalidHash)
8888
end
8989
end
9090

@@ -96,28 +96,28 @@
9696
end
9797

9898
specify "should compare successfully to the original secret" do
99-
(@password == @secret).should be(true)
99+
expect((@password == @secret)).to be(true)
100100
end
101101

102102
specify "should compare unsuccessfully to anything besides original secret" do
103-
(@password == "@secret").should be(false)
103+
expect((@password == "@secret")).to be(false)
104104
end
105105
end
106106

107107
describe "Validating a generated salt" do
108108
specify "should not accept an invalid salt" do
109-
BCrypt::Engine.valid_salt?("invalid").should eq(false)
109+
expect(BCrypt::Engine.valid_salt?("invalid")).to eq(false)
110110
end
111111
specify "should accept a valid salt" do
112-
BCrypt::Engine.valid_salt?(BCrypt::Engine.generate_salt).should eq(true)
112+
expect(BCrypt::Engine.valid_salt?(BCrypt::Engine.generate_salt)).to eq(true)
113113
end
114114
end
115115

116116
describe "Validating a password hash" do
117117
specify "should not accept an invalid password" do
118-
BCrypt::Password.valid_hash?("i_am_so_not_valid").should be_false
118+
expect(BCrypt::Password.valid_hash?("i_am_so_not_valid")).to be_false
119119
end
120120
specify "should accept a valid password" do
121-
BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid").should be_true
121+
expect(BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid")).to be_true
122122
end
123123
end

0 commit comments

Comments
 (0)