bcrypt 3.1.3-java

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.
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
2
+
3
+ describe "Errors" do
4
+
5
+ shared_examples "descends from StandardError" do
6
+ it "can be rescued as a StandardError" do
7
+ described_class.should < StandardError
8
+ end
9
+ end
10
+
11
+ shared_examples "descends from BCrypt::Error" do
12
+ it "can be rescued as a BCrypt::Error" do
13
+ described_class.should < BCrypt::Error
14
+ end
15
+ end
16
+
17
+ describe BCrypt::Error do
18
+ include_examples "descends from StandardError"
19
+ end
20
+
21
+ describe BCrypt::Errors::InvalidCost do
22
+ include_examples "descends from BCrypt::Error"
23
+ end
24
+
25
+ describe BCrypt::Errors::InvalidHash do
26
+ include_examples "descends from BCrypt::Error"
27
+ end
28
+
29
+ describe BCrypt::Errors::InvalidSalt do
30
+ include_examples "descends from BCrypt::Error"
31
+ end
32
+
33
+ describe BCrypt::Errors::InvalidSecret do
34
+ include_examples "descends from BCrypt::Error"
35
+ end
36
+
37
+ end
@@ -0,0 +1,123 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
2
+
3
+ describe "Creating a hashed password" do
4
+
5
+ before :each do
6
+ @secret = "wheedle"
7
+ @password = BCrypt::Password.create(@secret, :cost => 4)
8
+ end
9
+
10
+ specify "should return a BCrypt::Password" do
11
+ @password.should be_an_instance_of(BCrypt::Password)
12
+ end
13
+
14
+ specify "should return a valid bcrypt password" do
15
+ lambda { BCrypt::Password.new(@password) }.should_not raise_error
16
+ end
17
+
18
+ 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)
22
+ end
23
+
24
+ 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
28
+ end
29
+ end
30
+
31
+ describe "Reading a hashed password" do
32
+ before :each do
33
+ @secret = "U*U"
34
+ @hash = "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"
35
+ end
36
+
37
+ specify "the cost is too damn high" do
38
+ lambda {
39
+ BCrypt::Password.create("hello", :cost => 32)
40
+ }.should raise_error(ArgumentError)
41
+ end
42
+
43
+ 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)
45
+ end
46
+
47
+ 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)
49
+ end
50
+
51
+ specify "the cost should be set to the passed value if provided" do
52
+ BCrypt::Password.create("hello", :cost => 5).cost.should equal(5)
53
+ end
54
+
55
+ specify "the cost should be set to the global value if set" do
56
+ BCrypt::Engine.cost = 5
57
+ BCrypt::Password.create("hello").cost.should equal(5)
58
+ # unset the global value to not affect other tests
59
+ BCrypt::Engine.cost = nil
60
+ end
61
+
62
+ specify "the cost should be set to an overridden constant for backwards compatibility" do
63
+ # suppress "already initialized constant" warning
64
+ old_verbose, $VERBOSE = $VERBOSE, nil
65
+ old_default_cost = BCrypt::Engine::DEFAULT_COST
66
+
67
+ BCrypt::Engine::DEFAULT_COST = 5
68
+ BCrypt::Password.create("hello").cost.should equal(5)
69
+
70
+ # reset default to not affect other tests
71
+ BCrypt::Engine::DEFAULT_COST = old_default_cost
72
+ $VERBOSE = old_verbose
73
+ end
74
+
75
+ specify "should read the version, cost, salt, and hash" do
76
+ 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)
84
+ end
85
+
86
+ specify "should raise an InvalidHashError when given an invalid hash" do
87
+ lambda { BCrypt::Password.new('weedle') }.should raise_error(BCrypt::Errors::InvalidHash)
88
+ end
89
+ end
90
+
91
+ describe "Comparing a hashed password with a secret" do
92
+ before :each do
93
+ @secret = "U*U"
94
+ @hash = "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"
95
+ @password = BCrypt::Password.create(@secret)
96
+ end
97
+
98
+ specify "should compare successfully to the original secret" do
99
+ (@password == @secret).should be(true)
100
+ end
101
+
102
+ specify "should compare unsuccessfully to anything besides original secret" do
103
+ (@password == "@secret").should be(false)
104
+ end
105
+ end
106
+
107
+ describe "Validating a generated salt" do
108
+ specify "should not accept an invalid salt" do
109
+ BCrypt::Engine.valid_salt?("invalid").should eq(false)
110
+ end
111
+ specify "should accept a valid salt" do
112
+ BCrypt::Engine.valid_salt?(BCrypt::Engine.generate_salt).should eq(true)
113
+ end
114
+ end
115
+
116
+ describe "Validating a password hash" do
117
+ specify "should not accept an invalid password" do
118
+ BCrypt::Password.valid_hash?("i_am_so_not_valid").should be_false
119
+ end
120
+ specify "should accept a valid password" do
121
+ BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid").should be_true
122
+ end
123
+ end
@@ -0,0 +1,2 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'bcrypt'
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcrypt
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 3.1.3
6
+ platform: java
7
+ authors:
8
+ - Coda Hale
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2014-02-21 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake-compiler
17
+ version_requirements: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.2
23
+ requirement: *id001
24
+ prerelease: false
25
+ type: :development
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ version_requirements: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ requirement: *id002
35
+ prerelease: false
36
+ type: :development
37
+ - !ruby/object:Gem::Dependency
38
+ name: rdoc
39
+ version_requirements: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: "3.12"
45
+ requirement: *id003
46
+ prerelease: false
47
+ type: :development
48
+ description: " bcrypt() is a sophisticated and secure hash algorithm designed by The OpenBSD project\n for hashing passwords. The bcrypt Ruby gem provides a simple wrapper for safely handling\n passwords.\n"
49
+ email: coda.hale@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - README.md
56
+ - COPYING
57
+ - CHANGELOG
58
+ - lib/bcrypt.rb
59
+ - lib/bcrypt/engine.rb
60
+ - lib/bcrypt/error.rb
61
+ - lib/bcrypt/password.rb
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - .travis.yml
66
+ - CHANGELOG
67
+ - COPYING
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - README.md
71
+ - Rakefile
72
+ - bcrypt.gemspec
73
+ - ext/jruby/bcrypt_jruby/BCrypt.java
74
+ - ext/mri/bcrypt_ext.c
75
+ - ext/mri/crypt.c
76
+ - ext/mri/crypt.h
77
+ - ext/mri/crypt_blowfish.c
78
+ - ext/mri/crypt_gensalt.c
79
+ - ext/mri/extconf.rb
80
+ - ext/mri/ow-crypt.h
81
+ - ext/mri/wrapper.c
82
+ - lib/bcrypt.rb
83
+ - lib/bcrypt/engine.rb
84
+ - lib/bcrypt/error.rb
85
+ - lib/bcrypt/password.rb
86
+ - spec/TestBCrypt.java
87
+ - spec/bcrypt/engine_spec.rb
88
+ - spec/bcrypt/error_spec.rb
89
+ - spec/bcrypt/password_spec.rb
90
+ - spec/spec_helper.rb
91
+ - lib/bcrypt_ext.jar
92
+ homepage: https://github.com/codahale/bcrypt-ruby
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --title
98
+ - bcrypt-ruby
99
+ - --line-numbers
100
+ - --inline-source
101
+ - --main
102
+ - README.md
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 2
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 2
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project:
126
+ rubygems_version: 1.8.25
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: OpenBSD's bcrypt() password hashing algorithm.
130
+ test_files: []
131
+