FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improvements on specs by brunohenrique · Pull Request #108 · bcrypt-ruby/bcrypt-ruby · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .lock  (1) .rb  (2) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
30 changes: 15 additions & 15 deletions Gemfile.lock
This file contains hidden or 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
Expand Up @@ -7,25 +7,25 @@ GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
json (1.8.1)
json (1.8.1-java)
rake (10.1.0)
rake-compiler (0.9.2)
json (1.8.2)
json (1.8.2-java)
rake (10.4.2)
rake-compiler (0.9.5)
rake
rdoc (3.12.2)
json (~> 1.4)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.2)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.2)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.2)
rspec-support (~> 3.0.0)
rspec-support (3.0.2)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)

PLATFORMS
java
Expand Down
30 changes: 14 additions & 16 deletions spec/bcrypt/engine_spec.rb
This file contains hidden or 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,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))

describe "The BCrypt engine" do
RSpec.describe "The BCrypt engine" do
specify "should calculate the optimal cost factor to fit in a specific time" do
first = BCrypt::Engine.calibrate(100)
second = BCrypt::Engine.calibrate(400)
Expand All @@ -15,7 +15,7 @@
end

specify "should produce random data" do
expect(BCrypt::Engine.generate_salt).to_not equal(BCrypt::Engine.generate_salt)
expect(BCrypt::Engine.generate_salt).not_to eq(BCrypt::Engine.generate_salt)
end

specify "should raise a InvalidCostError if the cost parameter isn't numeric" do
Expand All @@ -30,9 +30,9 @@
describe "Autodetecting of salt cost" do

specify "should work" do
expect(BCrypt::Engine.autodetect_cost("$2a$08$hRx2IVeHNsTSYYtUWn61Ou")).to eq 8
expect(BCrypt::Engine.autodetect_cost("$2a$05$XKd1bMnLgUnc87qvbAaCUu")).to eq 5
expect(BCrypt::Engine.autodetect_cost("$2a$13$Lni.CZ6z5A7344POTFBBV.")).to eq 13
expect(BCrypt::Engine.autodetect_cost("$2a$08$hRx2IVeHNsTSYYtUWn61Ou")).to eq(8)
expect(BCrypt::Engine.autodetect_cost("$2a$05$XKd1bMnLgUnc87qvbAaCUu")).to eq(5)
expect(BCrypt::Engine.autodetect_cost("$2a$13$Lni.CZ6z5A7344POTFBBV.")).to eq(13)
end

end
Expand All @@ -43,27 +43,25 @@ class MyInvalidSecret
undef to_s
end

before :each do
@salt = BCrypt::Engine.generate_salt(4)
@password = "woo"
end
let(:salt) { BCrypt::Engine.generate_salt(4) }
let(:password) { "woo" }

specify "should produce a string" do
expect(BCrypt::Engine.hash_secret(@password, @salt)).to be_an_instance_of(String)
expect(BCrypt::Engine.hash_secret(password, salt)).to be_an_instance_of(String)
end

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

specify "should raise an InvalidSecret error if the secret is invalid" do
expect { BCrypt::Engine.hash_secret(MyInvalidSecret.new, @salt) }.to raise_error(BCrypt::Errors::InvalidSecret)
expect { BCrypt::Engine.hash_secret(nil, @salt) }.not_to raise_error
expect { BCrypt::Engine.hash_secret(false, @salt) }.not_to raise_error
expect { BCrypt::Engine.hash_secret(MyInvalidSecret.new, salt) }.to raise_error(BCrypt::Errors::InvalidSecret)
expect { BCrypt::Engine.hash_secret(nil, salt) }.not_to raise_error
expect { BCrypt::Engine.hash_secret(false, salt) }.not_to raise_error
end

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

specify "should be interoperable with other implementations" do
Expand All @@ -76,7 +74,7 @@ class MyInvalidSecret
["0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "$2a$05$abcdefghijklmnopqrstuu", "$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui"]
]
for secret, salt, test_vector in test_vectors
expect(BCrypt::Engine.hash_secret(secret, salt)).to eql(test_vector)
expect(BCrypt::Engine.hash_secret(secret, salt)).to eq(test_vector)
end
end
end
56 changes: 25 additions & 31 deletions spec/bcrypt/password_spec.rb
This file contains hidden or 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,18 +1,16 @@
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))

describe "Creating a hashed password" do
RSpec.describe "Creating a hashed password" do

before :each do
@secret = "wheedle"
@password = BCrypt::Password.create(@secret, :cost => 4)
end
let(:secret) { "wheedle" }
let(:password) { BCrypt::Password.create(secret, :cost => 4) }

specify "should return a BCrypt::Password" do
expect(@password).to be_an_instance_of(BCrypt::Password)
expect(password).to be_an_instance_of(BCrypt::Password)
end

specify "should return a valid bcrypt password" do
expect { BCrypt::Password.new(@password) }.not_to raise_error
expect { BCrypt::Password.new(password) }.not_to raise_error
end

specify "should behave normally if the secret is not a string" do
Expand All @@ -29,10 +27,8 @@
end

describe "Reading a hashed password" do
before :each do
@secret = "U*U"
@hash = "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"
end

let(:hash) { "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW" }

specify "the cost is too damn high" do
expect {
Expand All @@ -41,20 +37,20 @@
end

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

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

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

specify "the cost should be set to the global value if set" do
BCrypt::Engine.cost = 5
expect(BCrypt::Password.create("hello").cost).to equal(5)
expect(BCrypt::Password.create("hello").cost).to eq(5)
# unset the global value to not affect other tests
BCrypt::Engine.cost = nil
end
Expand All @@ -65,23 +61,23 @@
old_default_cost = BCrypt::Engine::DEFAULT_COST

BCrypt::Engine::DEFAULT_COST = 5
expect(BCrypt::Password.create("hello").cost).to equal(5)
expect(BCrypt::Password.create("hello").cost).to eq(5)

# reset default to not affect other tests
BCrypt::Engine::DEFAULT_COST = old_default_cost
$VERBOSE = old_verbose
end

specify "should read the version, cost, salt, and hash" do
password = BCrypt::Password.new(@hash)
expect(password.version).to eql("2a")
expect(password.version.class).to eq String
expect(password.cost).to equal(5)
expect(password.salt).to eql("$2a$05$CCCCCCCCCCCCCCCCCCCCC.")
expect(password.salt.class).to eq String
password = BCrypt::Password.new(hash)
expect(password.version).to eq("2a")
expect(password.version.class).to eq(String)
expect(password.cost).to eq(5)
expect(password.salt).to eq("$2a$05$CCCCCCCCCCCCCCCCCCCCC.")
expect(password.salt.class).to eq(String)
expect(password.checksum).to eq("E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW")
expect(password.checksum.class).to eq String
expect(password.to_s).to eql(@hash)
expect(password.checksum.class).to eq(String)
expect(password.to_s).to eq(hash)
end

specify "should raise an InvalidHashError when given an invalid hash" do
Expand All @@ -90,18 +86,16 @@
end

describe "Comparing a hashed password with a secret" do
before :each do
@secret = "U*U"
@hash = "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"
@password = BCrypt::Password.create(@secret)
end
let(:secret) {"U*U"}
let(:hash) { "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW" }
let(:password) { BCrypt::Password.create(secret) }

specify "should compare successfully to the original secret" do
expect((@password == @secret)).to be(true)
expect((password == secret)).to be(true)
end

specify "should compare unsuccessfully to anything besides original secret" do
expect((@password == "@secret")).to be(false)
expect((password == "secret")).to be(false)
end
end

Expand Down

Back | FazBrowse Home | New Git URL