sequel_secure_password 0.2.7 → 0.2.8
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 +4 -4
- data/lib/sequel_secure_password.rb +12 -8
- data/lib/sequel_secure_password/version.rb +1 -1
- data/spec/sequel_secure_password_spec.rb +14 -1
- data/spec/spec_helper.rb +12 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0606b0500d90c609f19b7483ef378c19d6d924af
|
4
|
+
data.tar.gz: f96d44063edfaa879487eae5c73b96f119fed836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a627b52ff04198f2a0bb4f3602b203c262a77dfe7079e0e713b04d1f4d7674303dc6cd9f7fd815623393a676c372d3ec2d250f851a723fedeb2563f2bc320f8d
|
7
|
+
data.tar.gz: 090095f000cf4a50e15ea3a4e2320a45dc5984328e63e40c3cac5616e038940cbeb2fe42ab2590a6dfd907cd7184072ebe428806a64ee6ab99d8265e0e67d9a5
|
@@ -11,15 +11,19 @@ module Sequel
|
|
11
11
|
# Configure the plugin by setting the available options. Options:
|
12
12
|
# * :cost - the cost factor when creating password hash. Default:
|
13
13
|
# BCrypt::Engine::DEFAULT_COST(10)
|
14
|
+
# * :include_validations - when set to false, password present and
|
15
|
+
# confirmation validations won't be included. Default: true
|
14
16
|
def self.configure(model, options = {})
|
15
17
|
model.instance_eval do
|
16
|
-
@cost
|
18
|
+
@cost = options.fetch(:cost, BCrypt::Engine::DEFAULT_COST)
|
19
|
+
@include_validations = options.fetch(:include_validations, true)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
23
|
module ClassMethods
|
21
|
-
attr_reader :cost
|
22
|
-
Plugins.inherited_instance_variables(self, :@cost
|
24
|
+
attr_reader :cost, :include_validations
|
25
|
+
Plugins.inherited_instance_variables(self, :@cost => nil,
|
26
|
+
:@include_validations => true)
|
23
27
|
end
|
24
28
|
|
25
29
|
module InstanceMethods
|
@@ -42,12 +46,12 @@ module Sequel
|
|
42
46
|
def validate
|
43
47
|
super
|
44
48
|
|
45
|
-
|
46
|
-
|
49
|
+
if model.include_validations
|
50
|
+
errors.add :password, 'is not present' if SecurePassword.blank_string? password_digest
|
51
|
+
errors.add :password, 'has no confirmation' if SecurePassword.blank_string? password_confirmation
|
52
|
+
errors.add :password, 'doesn\'t match confirmation' if password != password_confirmation
|
53
|
+
end
|
47
54
|
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
55
|
end
|
52
56
|
end
|
53
57
|
end
|
@@ -48,6 +48,20 @@ describe "model using Sequel::Plugins::SecurePassword" do
|
|
48
48
|
expect( User.inherited_instance_variables ).to include(:@cost)
|
49
49
|
end
|
50
50
|
|
51
|
+
it "has an inherited instance variable :@include_validations" do
|
52
|
+
expect( User.inherited_instance_variables ).to include(:@include_validations)
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when validations are disabled" do
|
56
|
+
subject(:user_without_validations) { UserWithoutValidations.new }
|
57
|
+
before do
|
58
|
+
user_without_validations.password = "foo"
|
59
|
+
user_without_validations.password_confirmation = "bar"
|
60
|
+
end
|
61
|
+
|
62
|
+
it { should be_valid }
|
63
|
+
end
|
64
|
+
|
51
65
|
describe "#authenticate" do
|
52
66
|
let(:secret) { "foo" }
|
53
67
|
before { user.password = secret }
|
@@ -71,6 +85,5 @@ describe "model using Sequel::Plugins::SecurePassword" do
|
|
71
85
|
BCrypt::Password.new(highcost_user.password_digest).cost.should be 12
|
72
86
|
}
|
73
87
|
end
|
74
|
-
|
75
88
|
end
|
76
89
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,18 +21,27 @@ RSpec.configure do |c|
|
|
21
21
|
plugin :secure_password
|
22
22
|
end
|
23
23
|
|
24
|
-
User.create_table!
|
25
|
-
|
26
24
|
class HighCostUser < Sequel::Model
|
27
25
|
set_schema do
|
28
26
|
primary_key :id
|
29
27
|
varchar :password_digest
|
30
28
|
end
|
31
29
|
|
32
|
-
plugin :secure_password, :
|
30
|
+
plugin :secure_password, cost: 12
|
31
|
+
end
|
32
|
+
|
33
|
+
class UserWithoutValidations < Sequel::Model
|
34
|
+
set_schema do
|
35
|
+
primary_key :id
|
36
|
+
varchar :password_digest
|
37
|
+
end
|
38
|
+
|
39
|
+
plugin :secure_password, include_validations: false
|
33
40
|
end
|
34
41
|
|
42
|
+
User.create_table!
|
35
43
|
HighCostUser.create_table!
|
44
|
+
UserWithoutValidations.create_table!
|
36
45
|
end
|
37
46
|
|
38
47
|
c.around :each do |example|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_secure_password
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Lenik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|