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 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After a configurable amount of consecutive failed login attempts the new attribute `locked_until` will be set. The default amount of attempts is 5 and the default time the user is locked is 5 minutes. After this commit locked users will still be able to log in. Locking out locked users is part of the next commit.
- Loading branch information
Philippe Hässig
committed
Aug 10, 2016
1 parent
9ebf812
commit 967fa33
Showing
10 changed files
with
129 additions
and
3 deletions.
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
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
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,63 @@ | ||
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 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 |