This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 189
Lock user after a configurable amount of failed login attempts #169
Open
neckhair
wants to merge
14
commits into
rbCAS:master
Choose a base branch
from
ninech:lock-user
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
967fa33
Lock users after x failed attempts
d382925
Reject login when a user is locked
1107716
Allow to disable th max failed attempts feature
77f73f1
Make the lock timeout configurable
a32fa91
Defers credential check
cimnine 8ec6562
Removes superfluous instruction.
cimnine fc49a9a
Revert "Defers credential check"
cimnine 5167b81
Defers credential check, take two.
cimnine b81827b
Improves check whether any given user is locked.
cimnine e57aa73
No separate message when account is locked by default.
cimnine 4177592
Fixes the check whether a user is actually locked.
cimnine b4c741d
Adds information about lock status to users rake task
cimnine b8b305e
Adds a rake task to unlock locked users and list lock status
cimnine 672d176
Enhanced with nil check
cimnine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddLockedUntilToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :casino_users, :locked_until, :datetime | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
spec/dummy/db/migrate/20160810122605_add_locked_until_to_users.casino.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This migration comes from casino (originally 20160810113208) | ||
class AddLockedUntilToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :casino_users, :locked_until, :datetime | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe CASino::User do | ||
let(:user) { FactoryGirl.create :user } | ||
|
||
describe '#locked?' do | ||
it 'is true when locked_until is in the future' do | ||
user = FactoryGirl.create :user, locked_until: 1.hour.from_now | ||
expect(user).to be_locked | ||
end | ||
|
||
it 'is false when locked_until is in the past' do | ||
user = FactoryGirl.create :user, locked_until: 1.hour.ago | ||
expect(user).to_not be_locked | ||
end | ||
|
||
it 'is false when locked_until is empty' do | ||
user = FactoryGirl.create :user, locked_until: nil | ||
expect(user).to_not be_locked | ||
end | ||
end | ||
|
||
describe '#max_failed_logins_reached?' do | ||
let(:max_failed_attempts) { 2 } | ||
|
||
subject { user.max_failed_logins_reached?(max_failed_attempts) } | ||
|
||
context 'when the user has no login attempts' do | ||
it { is_expected.to eq false } | ||
end | ||
|
||
context 'when the user has only successful logins' do | ||
it { is_expected.to eq false } | ||
end | ||
|
||
context 'when the feature is disabled' do | ||
let(:max_failed_attempts) { -1 } | ||
it { is_expected.to eq false } | ||
end | ||
|
||
context 'when the maxium value is invalid' do | ||
let(:max_failed_attempts) { nil } | ||
it { is_expected.to eq false } | ||
end | ||
|
||
context 'when the maximum of attempts is reached' do | ||
before { FactoryGirl.create_list :login_attempt, 2, successful: false, user: user } | ||
|
||
context 'in a row' do | ||
it { is_expected.to eq true } | ||
end | ||
|
||
context 'but the last attempt was successful' do | ||
before { FactoryGirl.create :login_attempt, successful: true, user: user } | ||
it { is_expected.to eq false } | ||
end | ||
|
||
context 'but a successful between' do | ||
before do | ||
FactoryGirl.create :login_attempt, successful: true, user: user | ||
FactoryGirl.create :login_attempt, successful: false, user: user | ||
end | ||
|
||
it { is_expected.to eq false } | ||
end | ||
end | ||
|
||
context 'when the user has less then the maximum failed attempts' do | ||
before { FactoryGirl.create :login_attempt, successful: false, user: user } | ||
it { is_expected.to eq false } | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constant seems to be unused.