Skip to content

Commit b747516

Browse files
authored
Raise ArgumentError when calling change_password! with blank password (#333)
* Raise ArgumentError when calling change_password! with blank password * Add CHANGELOG entry
1 parent 47f82a5 commit b747516

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22
## HEAD
33

4+
* Raise ArgumentError when calling change_password! with blank password [#333](https://github.com/Sorcery/sorcery/pull/333)
5+
46
## 0.16.4
57

68
* Adapt to open request protection strategy of rails 7.0 [#318](https://github.com/Sorcery/sorcery/pull/318)

lib/sorcery/model/submodules/reset_password.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def change_password(new_password, raise_on_failure: false)
131131
end
132132

133133
def change_password!(new_password)
134+
raise ArgumentError, 'Blank password passed to change_password!' if new_password.blank?
135+
134136
change_password(new_password, raise_on_failure: true)
135137
end
136138

spec/shared_examples/user_reset_password_shared_examples.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,18 @@
328328
expect(user.reset_password_token).to be_nil
329329
end
330330

331+
it 'when change_password! is called with empty argument, raise an exception' do
332+
expect {
333+
user.change_password!('')
334+
}.to raise_error(ArgumentError, 'Blank password passed to change_password!')
335+
end
336+
337+
it 'when change_password! is called with nil argument, raise an exception' do
338+
expect {
339+
user.change_password!(nil)
340+
}.to raise_error(ArgumentError, 'Blank password passed to change_password!')
341+
end
342+
331343
it 'when change_password is called, deletes reset_password_token and calls #save' do
332344
new_password = 'blabulsdf'
333345

0 commit comments

Comments
 (0)