passwd 0.1.3 → 0.1.4
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/README.md +18 -9
- data/lib/passwd.rb +1 -0
- data/lib/passwd/active_record.rb +6 -2
- data/lib/passwd/base.rb +1 -1
- data/lib/passwd/errors.rb +15 -0
- data/lib/passwd/version.rb +1 -3
- data/spec/passwd/active_record_spec.rb +32 -11
- data/spec/passwd/base_spec.rb +4 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9ba7557a87c9ef3d0b947b32bae95c8693ce96c
|
4
|
+
data.tar.gz: 07de417852343a3cdb13f6ecf27f36b95190c307
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1072b0d5f670f2698c0f6b5982c457a587e3a3afcd7638586233a3a2425c5ec98a4ae8a50c9b91adeacd4a10c8eb8f59f95a8db2d7eb5b855c7bd8aef6f4b32
|
7
|
+
data.tar.gz: 4367e04477af7a420763b8681a9a455263a3094d2190a49c6c0c1b75bbd8b5ae9398574771410d5bc926e9b1bb0c5ea9c24ab947b53a55e5aa3aa6eadcb1acb6
|
data/README.md
CHANGED
@@ -180,21 +180,30 @@ if user.save
|
|
180
180
|
NoticeMailer.change_mail(user, password_text).deliver
|
181
181
|
end
|
182
182
|
```
|
183
|
+
|
183
184
|
`update_password` method will be set new password if the authentication successful.
|
184
|
-
Return the nil if authentication fails.
|
185
185
|
But `update_password` method doesn't call `save` method.
|
186
186
|
|
187
187
|
```ruby
|
188
188
|
@user = User.find(params[:id])
|
189
189
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
190
|
+
begin
|
191
|
+
confirm_check(new_pass, confirm)
|
192
|
+
@user.update_password(old_pass, new_pass, true)
|
193
|
+
@user.save!
|
194
|
+
redirect_to bar_path, notice: "Password updated successfully"
|
195
|
+
rescue PasswordNotMatch
|
196
|
+
flash.now[:alert] = "Password not match"
|
197
|
+
render action: :edit
|
198
|
+
rescue AuthError
|
199
|
+
flash.now[:alert] = "Password is incorrect"
|
200
|
+
render action: :edit
|
201
|
+
rescue PolicyNotMatch
|
202
|
+
flash.now[:alert] = "Policy not match"
|
203
|
+
render action: :edit
|
204
|
+
rescue
|
205
|
+
flash.now[:alert] = "Password update failed"
|
206
|
+
render action: :edit
|
198
207
|
end
|
199
208
|
```
|
200
209
|
|
data/lib/passwd.rb
CHANGED
data/lib/passwd/active_record.rb
CHANGED
@@ -39,11 +39,15 @@ module Passwd
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def define_update_password(salt_name, password_name)
|
42
|
-
define_method :update_password do |old_pass, new_pass|
|
42
|
+
define_method :update_password do |old_pass, new_pass, policy_check=false|
|
43
43
|
if Passwd.auth(old_pass, self.send(salt_name), self.send(password_name))
|
44
|
+
if policy_check
|
45
|
+
raise Passwd::PolicyNotMatch, "Policy not match" unless Passwd.policy_check(new_pass)
|
46
|
+
end
|
47
|
+
|
44
48
|
set_password(new_pass)
|
45
49
|
else
|
46
|
-
|
50
|
+
raise Passwd::AuthError
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
data/lib/passwd/base.rb
CHANGED
@@ -29,7 +29,7 @@ module Passwd
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def confirm_check(password, confirm, with_policy=false)
|
32
|
-
|
32
|
+
raise PasswordNotMatch, "Password not match" if password != confirm
|
33
33
|
return true unless with_policy
|
34
34
|
Passwd.policy_check(password)
|
35
35
|
end
|
data/lib/passwd/version.rb
CHANGED
@@ -12,14 +12,14 @@ describe Passwd::ActiveRecord do
|
|
12
12
|
let(:password_text) {"secret"}
|
13
13
|
let(:password_hash) {Digest::SHA1.hexdigest("#{salt}#{password_text}")}
|
14
14
|
|
15
|
-
describe "
|
15
|
+
describe ".#included" do
|
16
16
|
it "define singleton methods" do
|
17
17
|
expect(User.respond_to? :define_column).to be_true
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "extend methods" do
|
22
|
-
describe "
|
22
|
+
describe ".#define_column" do
|
23
23
|
let(:user) {User.new}
|
24
24
|
|
25
25
|
it "define singleton methods" do
|
@@ -41,7 +41,7 @@ describe Passwd::ActiveRecord do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe "defined methods from define_column" do
|
44
|
-
describe "
|
44
|
+
describe ".#authenticate" do
|
45
45
|
let!(:record) {
|
46
46
|
record = double("record mock")
|
47
47
|
record.stub(:salt).and_return(salt)
|
@@ -126,16 +126,37 @@ describe Passwd::ActiveRecord do
|
|
126
126
|
user
|
127
127
|
}
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
context "without policy check" do
|
130
|
+
it "should return update password" do
|
131
|
+
pass = "new_password"
|
132
|
+
user.should_receive(:set_password).with(pass).and_return(pass)
|
133
|
+
expect(user.update_password(password_text, pass)).to eq(pass)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should generate exception if authentication failed" do
|
137
|
+
Passwd.should_receive(:auth).and_return(false)
|
138
|
+
user.should_not_receive(:set_password)
|
139
|
+
expect {
|
140
|
+
user.update_password("invalid_password", "new_password")
|
141
|
+
}.to raise_error(Passwd::AuthError)
|
142
|
+
end
|
133
143
|
end
|
134
144
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
145
|
+
context "with policy check" do
|
146
|
+
it "should return update password" do
|
147
|
+
pass = "new_password"
|
148
|
+
Passwd.should_receive(:policy_check).and_return(true)
|
149
|
+
user.should_receive(:set_password).with(pass).and_return(pass)
|
150
|
+
expect(user.update_password(password_text, pass, true)).to eq(pass)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should generate exception if policy not match" do
|
154
|
+
pass = "new_password"
|
155
|
+
Passwd.should_receive(:policy_check).and_return(false)
|
156
|
+
expect {
|
157
|
+
user.update_password(password_text, pass, true)
|
158
|
+
}.to raise_error(Passwd::PolicyNotMatch)
|
159
|
+
end
|
139
160
|
end
|
140
161
|
end
|
141
162
|
end
|
data/spec/passwd/base_spec.rb
CHANGED
@@ -81,8 +81,10 @@ describe Passwd do
|
|
81
81
|
|
82
82
|
describe "#confirm_check" do
|
83
83
|
context "with out policy check" do
|
84
|
-
it "
|
85
|
-
expect
|
84
|
+
it "should generate exception if password don't match" do
|
85
|
+
expect{
|
86
|
+
Passwd.confirm_check("secret", "invalid")
|
87
|
+
}.to raise_error(Passwd::PasswordNotMatch)
|
86
88
|
end
|
87
89
|
|
88
90
|
it "return true if password matches" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passwd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/passwd/configuration/config.rb
|
74
74
|
- lib/passwd/configuration/policy.rb
|
75
75
|
- lib/passwd/configuration/tmp_config.rb
|
76
|
+
- lib/passwd/errors.rb
|
76
77
|
- lib/passwd/password.rb
|
77
78
|
- lib/passwd/version.rb
|
78
79
|
- passwd.gemspec
|