Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMFR-1360 - Make sure emails are downcased #3637

Merged
merged 1 commit into from
Mar 29, 2023
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: 1 addition & 1 deletion app/services/cognito/confirm_password_reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ConfirmPasswordReset < BaseService
validates_format_of :password, with: /(?=.*[0-9])/, message: :invalid_no_number

def initialize(email, password, password_confirmation, confirmation_code)
@email = email
@email = email.try(:downcase)
@password = password
@password_confirmation = password_confirmation
@confirmation_code = confirmation_code
Expand Down
2 changes: 1 addition & 1 deletion app/services/cognito/resend_confirmation_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ResendConfirmationCode < BaseService
attr_accessor :error

def initialize(email)
@email = email
@email = email.try(:downcase)
@error = nil
end

Expand Down
42 changes: 42 additions & 0 deletions spec/services/cognito/confirm_password_reset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,48 @@

before { allow(Aws::CognitoIdentityProvider::Client).to receive(:new).and_return(aws_client) }

describe '#initialize' do
let(:confirm_password_reset) { described_class.new(email, password, password_confirmation, confirmation_code) }

let(:email) { '[email protected]' }

let(:confirm_password_reset_attributes) do
{
email: confirm_password_reset.email,
password: confirm_password_reset.password,
password_confirmation: confirm_password_reset.password_confirmation,
confirmation_code: confirm_password_reset.confirmation_code
}
end

it 'initialises the object with the attributes' do
expect(confirm_password_reset_attributes).to eq(
{
email: '[email protected]',
password: 'ValidPass123!',
password_confirmation: 'ValidPass123!',
confirmation_code: '1234'
}
)
end

context 'when the email has uppercase letters' do
let(:email) { '[email protected]' }

it 'makes the email lower case' do
expect(confirm_password_reset.email).to eq('[email protected]')
end
end

context 'when the email is nil' do
let(:email) { nil }

it 'returns nil for the email' do
expect(confirm_password_reset.email).to be_nil
end
end
end

describe '#validations' do
let(:response) { described_class.new(username, password, password_confirmation, confirmation_code) }

Expand Down
39 changes: 39 additions & 0 deletions spec/services/cognito/confirm_sign_up_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@

before { allow(Aws::CognitoIdentityProvider::Client).to receive(:new).and_return(aws_client) }

describe '#initialize' do
let(:confirm_sign_up) { described_class.new(email, confirmation_code) }

let(:confirm_sign_up_attributes) do
{
email: confirm_sign_up.email,
confirmation_code: confirm_sign_up.confirmation_code,
user: confirm_sign_up.user
}
end

it 'initialises the object with the attributes' do
expect(confirm_sign_up_attributes).to eq(
{
email: '[email protected]',
confirmation_code: '123456',
user: nil
}
)
end

context 'when the email has uppercase letters' do
let(:email) { '[email protected]' }

it 'makes the email lower case' do
expect(confirm_sign_up.email).to eq('[email protected]')
end
end

context 'when the email is nil' do
let(:email) { nil }
let(:user) { nil }

it 'returns nil for the email' do
expect(confirm_sign_up.email).to be_nil
end
end
end

describe '#validations' do
let(:response) { described_class.new(email, confirmation_code) }

Expand Down
40 changes: 40 additions & 0 deletions spec/services/cognito/create_user_from_cognito_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
require 'rails_helper'

RSpec.describe Cognito::CreateUserFromCognito do
describe '#initialize' do
let(:create_user_from_cognito) { described_class.new(username) }

let(:username) { '[email protected]' }

let(:create_user_from_cognito_attributes) do
{
username: create_user_from_cognito.username,
error: create_user_from_cognito.error,
user: create_user_from_cognito.user,
}
end

it 'initialises the object with the attributes' do
expect(create_user_from_cognito_attributes).to eq(
{
username: '[email protected]',
error: nil,
user: nil
}
)
end

context 'when the username has uppercase letters' do
let(:username) { '[email protected]' }

it 'makes the username lower case' do
expect(create_user_from_cognito.username).to eq('[email protected]')
end
end

context 'when the username is nil' do
let(:username) { nil }

it 'returns nil for the username' do
expect(create_user_from_cognito.username).to be_nil
end
end
end

describe '#call' do
include_context 'with cognito structs'

Expand Down
38 changes: 38 additions & 0 deletions spec/services/cognito/forgot_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,44 @@
let(:invalid_email) { 'someRandomString' }
let(:aws_client) { instance_double(Aws::CognitoIdentityProvider::Client) }

describe '#initialize' do
let(:forgot_password) { described_class.new(email) }

let(:email) { '[email protected]' }

let(:forgot_password_attributes) do
{
email: forgot_password.email,
error: forgot_password.error
}
end

it 'initialises the object with the attributes' do
expect(forgot_password_attributes).to eq(
{
email: '[email protected]',
error: nil
}
)
end

context 'when the email has uppercase letters' do
let(:email) { '[email protected]' }

it 'makes the email lower case' do
expect(forgot_password.email).to eq('[email protected]')
end
end

context 'when the email is nil' do
let(:email) { nil }

it 'returns nil for the email' do
expect(forgot_password.email).to be_nil
end
end
end

describe '#call' do
let(:response) { described_class.call(email) }

Expand Down
38 changes: 38 additions & 0 deletions spec/services/cognito/resend_confirmation_code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,44 @@

before { allow(Aws::CognitoIdentityProvider::Client).to receive(:new).and_return(aws_client) }

describe '#initialize' do
let(:resend_confirmation_code) { described_class.new(email) }

let(:email) { '[email protected]' }

let(:resend_confirmation_code_attributes) do
{
email: resend_confirmation_code.email,
error: resend_confirmation_code.error
}
end

it 'initialises the object with the attributes' do
expect(resend_confirmation_code_attributes).to eq(
{
email: '[email protected]',
error: nil
}
)
end

context 'when the email has uppercase letters' do
let(:email) { '[email protected]' }

it 'makes the email lower case' do
expect(resend_confirmation_code.email).to eq('[email protected]')
end
end

context 'when the email is nil' do
let(:email) { nil }

it 'returns nil for the email' do
expect(resend_confirmation_code.email).to be_nil
end
end
end

describe '#call' do
context 'when success' do
include_context 'with cognito structs'
Expand Down
72 changes: 72 additions & 0 deletions spec/services/cognito/respond_to_challenge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,78 @@

before { allow(Aws::CognitoIdentityProvider::Client).to receive(:new).and_return(aws_client) }

# rubocop:disable RSpec/ExampleLength
describe '#initialize' do
let(:respond_to_challenge_attributes) do
{
challenge_name: respond_to_challenge.challenge_name,
session: respond_to_challenge.session,
new_password: respond_to_challenge.new_password,
new_password_confirmation: respond_to_challenge.new_password_confirmation,
access_code: respond_to_challenge.access_code,
username: respond_to_challenge.username,
roles: respond_to_challenge.roles
}
end

context 'when no options are passed' do
let(:respond_to_challenge) { described_class.new(challenge_name, username, session) }

it 'initialises the object with the optional attributes as nil' do
expect(respond_to_challenge_attributes).to eq(
{
challenge_name: 'NEW_PASSWORD_REQUIRED',
session: 'Session',
new_password: nil,
new_password_confirmation: nil,
access_code: nil,
username: '123456',
roles: nil
}
)
end
end

context 'when the NEW_PASSWORD_REQUIRED params are passed' do
let(:respond_to_challenge) { described_class.new(challenge_name, username, session, new_password:, new_password_confirmation:) }

it 'initialises the object with the NEW_PASSWORD_REQUIRED attributes present' do
expect(respond_to_challenge_attributes).to eq(
{
challenge_name: 'NEW_PASSWORD_REQUIRED',
session: 'Session',
new_password: 'ValidPass123!',
new_password_confirmation: 'ValidPass123!',
access_code: nil,
username: '123456',
roles: nil
}
)
end
end

context 'when the SMS_MFA params are passed' do
let(:respond_to_challenge) { described_class.new(challenge_name, username, session, access_code:) }

let(:challenge_name) { 'SMS_MFA' }

it 'initialises the object with the SMS_MFA attributes present' do
expect(respond_to_challenge_attributes).to eq(
{
challenge_name: 'SMS_MFA',
session: 'Session',
new_password: nil,
new_password_confirmation: nil,
access_code: '123467',
username: '123456',
roles: nil
}
)
end
end
end
# rubocop:enable RSpec/ExampleLength

describe '#validations' do
let(:response) { described_class.new(challenge_name, username, session, new_password:, new_password_confirmation:) }

Expand Down
51 changes: 48 additions & 3 deletions spec/services/cognito/sign_in_user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,60 @@
require 'rails_helper'

RSpec.describe Cognito::SignInUser do
let(:email) { '[email protected]' }
let(:password) { 'ValidPass123!' }
let(:cookies_disabled) { false }

describe '#initialize' do
let(:sign_in_user) { described_class.new(email, password, cookies_disabled) }

let(:sign_in_user_attributes) do
{
email: sign_in_user.email,
password: sign_in_user.password,
error: sign_in_user.error,
needs_password_reset: sign_in_user.needs_password_reset,
cookies_disabled: sign_in_user.cookies_disabled,
needs_confirmation: sign_in_user.needs_confirmation
}
end

it 'initialises the object with the attributes' do
expect(sign_in_user_attributes).to eq(
{
email: '[email protected]',
password: 'ValidPass123!',
error: nil,
needs_password_reset: false,
cookies_disabled: false,
needs_confirmation: nil
}
)
end

context 'when the email has uppercase letters' do
let(:email) { '[email protected]' }

it 'makes the email lower case' do
expect(sign_in_user.email).to eq('[email protected]')
end
end

context 'when the email is nil' do
let(:email) { nil }

it 'returns nil for the email' do
expect(sign_in_user.email).to be_nil
end
end
end

describe '#call' do
include_context 'with cognito structs'

let(:email) { '[email protected]' }
let(:password) { 'ValidPass123!' }
let(:challenge_name) { 'Challenge name' }
let(:session) { 'Session' }
let(:user_id_for_srp) { 'User id' }
let(:cookies_disabled) { false }

let(:aws_client) { instance_double(Aws::CognitoIdentityProvider::Client) }

Expand Down
Loading