Commit 28e13759ae318586d9c771b02402579b343c97cb
Increase test coverage. We now have 100% C0 coverage.
Signed-off-by: Coda Hale <coda.hale@gmail.com>Hongli Lai (Phusion) authored on 8/4/2009, 8:39:27 PM
Coda Hale committed on 8/12/2009, 9:50:39 PM
Parent: f01304abbeb445a3710fb3e15e69dee1b4637519
Files changed
spec/bcrypt/engine_spec.rb | changed |
spec/bcrypt/engine_spec.rb | ||
---|---|---|
@@ -28,8 +28,12 @@ | ||
28 | 28 | end |
29 | 29 | |
30 | 30 | context "Generating BCrypt hashes" do |
31 | 31 | |
32 | + class MyInvalidSecret | |
33 | + undef to_s | |
34 | + end | |
35 | + | |
32 | 36 | before :each do |
33 | 37 | @salt = BCrypt::Engine.generate_salt(4) |
34 | 38 | @password = "woo" |
35 | 39 | end |
@@ -42,12 +46,17 @@ | ||
42 | 46 | lambda { BCrypt::Engine.hash_secret(@password, 'nino') }.should raise_error(BCrypt::Errors::InvalidSalt) |
43 | 47 | end |
44 | 48 | |
45 | 49 | specify "should raise an InvalidSecret error if the secret is invalid" do |
50 | + lambda { BCrypt::Engine.hash_secret(MyInvalidSecret.new, @salt) }.should raise_error(BCrypt::Errors::InvalidSecret) | |
46 | 51 | lambda { BCrypt::Engine.hash_secret(nil, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret) |
47 | 52 | lambda { BCrypt::Engine.hash_secret(false, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret) |
48 | 53 | end |
49 | 54 | |
55 | + specify "should call #to_s on the secret and use the return value as the actual secret data" do | |
56 | + BCrypt::Engine.hash_secret(false, @salt).should == BCrypt::Engine.hash_secret("false", @salt) | |
57 | + end | |
58 | + | |
50 | 59 | specify "should be interoperable with other implementations" do |
51 | 60 | # test vectors from the OpenWall implementation <http://www.openwall.com/crypt/> |
52 | 61 | test_vectors = [ |
53 | 62 | ["U*U", "$2a$05$CCCCCCCCCCCCCCCCCCCCC.", "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"], |
Built with git-ssb-web