Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog
## HEAD

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

## 0.16.4

* Adapt to open request protection strategy of rails 7.0 [#318](https://github.com/Sorcery/sorcery/pull/318)
Expand Down
2 changes: 2 additions & 0 deletions lib/sorcery/model/submodules/reset_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def change_password(new_password, raise_on_failure: false)
end

def change_password!(new_password)
raise ArgumentError, 'Blank password passed to change_password!' if new_password.blank?

change_password(new_password, raise_on_failure: true)
end

Expand Down
12 changes: 12 additions & 0 deletions spec/shared_examples/user_reset_password_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,18 @@
expect(user.reset_password_token).to be_nil
end

it 'when change_password! is called with empty argument, raise an exception' do
expect {
user.change_password!('')
}.to raise_error(ArgumentError, 'Blank password passed to change_password!')
end

it 'when change_password! is called with nil argument, raise an exception' do
expect {
user.change_password!(nil)
}.to raise_error(ArgumentError, 'Blank password passed to change_password!')
end

it 'when change_password is called, deletes reset_password_token and calls #save' do
new_password = 'blabulsdf'

Expand Down