-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2087ad3
commit a1d7844
Showing
14 changed files
with
88 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module PasswordValidator | ||
extend ActiveSupport::Concern | ||
|
||
PASSWORD_REGEX = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).*$/ | ||
|
||
private | ||
|
||
def password_complexity | ||
return if good_password? | ||
|
||
error_message = I18n.t('devise.registrations.password_complexity_error') | ||
errors.add(:password, error_message) | ||
end | ||
|
||
def good_password? | ||
google_oauth2_enabled? || password.blank? || (password =~ PASSWORD_REGEX) | ||
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
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 |
---|---|---|
|
@@ -7,9 +7,9 @@ | |
# Mayor.create(name: 'Emanuel', city: cities.first) | ||
|
||
# Users | ||
user1 = User.create(name: 'Test1 Lastname', email: '[email protected]', password: 'password99', location: 'Toronto, ON, Canada', about: 'Hi my name is Test1! I want to use the site so that I can improve the way I handle my anxiety.') | ||
user2 = User.create(name: 'Test2 Lastname', email: '[email protected]', password: 'password99', location: 'Toronto, ON, Canada') | ||
user3 = User.create(name: 'Test3 Two-Lastnames', email: '[email protected]', password: 'password99', location: 'San Francisco, CA, United States') | ||
user1 = User.create(name: 'Test1 Lastname', email: '[email protected]', password: 'passworD@99', location: 'Toronto, ON, Canada', about: 'Hi my name is Test1! I want to use the site so that I can improve the way I handle my anxiety.') | ||
user2 = User.create(name: 'Test2 Lastname', email: '[email protected]', password: 'passworD@99', location: 'Toronto, ON, Canada') | ||
user3 = User.create(name: 'Test3 Two-Lastnames', email: '[email protected]', password: 'passworD@99', location: 'San Francisco, CA, United States') | ||
|
||
# Allies | ||
Allyship.create(user_id: user1.id, ally_id: user2.id, status: :accepted) | ||
|
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 |
---|---|---|
|
@@ -47,20 +47,20 @@ | |
factory :user, class: 'User' do | ||
sequence(:email) { |n| "some-email#{n}@ifme.org" } | ||
sequence(:name) { |n| "Some Person#{n}" } | ||
password { 'password' } | ||
password { 'passworD%1' } | ||
end | ||
|
||
factory :user1, class: User do | ||
name { 'Oprah Chang' } | ||
sequence(:email) { |n| "oprah.chang#{n}@example.com" } | ||
password { 'password' } | ||
password { 'passworD%1' } | ||
location { 'Toronto, ON, Canada' } | ||
end | ||
|
||
factory :user2, class: User do | ||
name { 'Plum Blossom' } | ||
email { '[email protected]' } | ||
password { 'password' } | ||
password { 'passworD%1' } | ||
location { 'Toronto, ON, Canada' } | ||
|
||
trait :with_allies do | ||
|
@@ -80,14 +80,14 @@ | |
factory :user3, class: User do | ||
name { 'Gentle Breezy' } | ||
email { '[email protected]' } | ||
password { 'password' } | ||
password { 'passworD%1' } | ||
location { 'Toronto, ON, Canada' } | ||
end | ||
|
||
factory :user_oauth, class: User do | ||
name { 'Orange Southland' } | ||
email { '[email protected]' } | ||
password { 'password' } | ||
password { 'passworD%1' } | ||
location { 'Toronto, ON, Canada' } | ||
token { 'has_a_token' } | ||
access_expires_at { Time.zone.now + 600 } | ||
|
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 |
---|---|---|
|
@@ -59,7 +59,7 @@ | |
end | ||
|
||
context 'an existing user' do | ||
let!(:user) { User.create(name: 'some name', email: '[email protected]', password: 'asdfasdf') } | ||
let!(:user) { User.create(name: 'some name', email: '[email protected]', password: 'asdfaS1!df') } | ||
|
||
it 'updates token information' do | ||
User.find_for_google_oauth2(access_token) | ||
|
@@ -93,7 +93,7 @@ | |
let!(:user) do | ||
User.create(name: 'some name', | ||
email: '[email protected]', | ||
password: 'asdfasdf', | ||
password: 'asdfasdF!1', | ||
token: 'some token') | ||
end | ||
|
||
|
@@ -135,6 +135,47 @@ | |
end | ||
end | ||
|
||
describe '#validations' do | ||
context 'password' do | ||
let(:user) { build(:user, password: nil) } | ||
|
||
context 'when password is blank' do | ||
it 'throws password error only from devise' do | ||
expect(user.valid?).to be false | ||
|
||
expect(user).to have(1).error_on(:password) | ||
expect(user.errors[:password]).not_to include(I18n.t('devise.registrations.password_complexity_error')) | ||
end | ||
end | ||
|
||
context 'when oauth is enabled' do | ||
it 'doesnt throw any errors even if the password strength is less' do | ||
user.password = 'warsdasdf' | ||
user.token = 'access token' | ||
expect(user.valid?).to be true | ||
end | ||
end | ||
|
||
context 'when password is valid' do | ||
it 'doesnt throw any errors' do | ||
user.password = 'waspAr$0' | ||
expect(user.valid?).to be true | ||
end | ||
end | ||
|
||
context 'when password is invalid' do | ||
it 'returns respective error message' do | ||
['waspar$0', 'waspaRs0', 'waspar$o', 'WASPAR$0', 'Was$0'].each do |password| | ||
user.password = password | ||
expect(user.valid?).to be false | ||
|
||
expect(user).to have(1).error_on(:password) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#available_groups' do | ||
it "returns the groups that allys belong to and the user doesn't" do | ||
user = create :user1 | ||
|