-
Notifications
You must be signed in to change notification settings - Fork 9
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
Check validity of User when using DfE Sign in callback #10020
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ | |
|
||
RSpec.describe DsiProfile do | ||
describe '#update_profile_from_dfe_sign_in' do | ||
let(:provider_user) { create(:provider_user) } | ||
let(:support_user) { create(:provider_user) } | ||
let(:email_address) { Faker::Internet.email } | ||
let(:provider_user) { create(:provider_user, email_address: '[email protected]') } | ||
let(:email_address) { '[email protected]' } | ||
let(:dfe_user) do | ||
DfESignInUser.new( | ||
email_address:, | ||
|
@@ -14,11 +13,12 @@ | |
) | ||
end | ||
|
||
context 'local_user\'s email_address' do | ||
context "local_user's email_address" do | ||
it 'is updated if uid is previously known' do | ||
expect { | ||
described_class.update_profile_from_dfe_sign_in dfe_user:, local_user: provider_user | ||
}.to change(provider_user, :email_address).to(email_address) | ||
result = described_class.update_profile_from_dfe_sign_in dfe_user:, local_user: provider_user | ||
|
||
expect(result).to be_truthy | ||
expect(provider_user.reload.email_address).to eq(email_address) | ||
end | ||
|
||
it 'is not updated if uid is not yet established' do | ||
|
@@ -41,6 +41,17 @@ | |
described_class.update_profile_from_dfe_sign_in dfe_user: dfe_user_no_email, local_user: provider_user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was tempted to update all the specs in this context to be in the same format
|
||
}.not_to change(provider_user, :email_address) | ||
end | ||
|
||
context 'the email is already used by another user' do | ||
it 'is not updated' do | ||
_other_provider_user = create(:provider_user, email_address: email_address) | ||
|
||
result = described_class.update_profile_from_dfe_sign_in(dfe_user: dfe_user, local_user: provider_user) | ||
|
||
expect(result).to be_falsey | ||
expect(provider_user.reload.email_address).not_to eq(email_address) | ||
end | ||
end | ||
end | ||
|
||
context 'local_user\'s profile fields' do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ProviderUser do | ||
describe 'validations' do | ||
let!(:existing_provider_user) { create(:provider_user) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required for the |
||
|
||
it { is_expected.to validate_presence_of(:email_address) } | ||
it { is_expected.to validate_uniqueness_of(:email_address).case_insensitive } | ||
end | ||
|
||
describe '#downcase_email_address' do | ||
it 'saves email_address in lower case' do | ||
provider_user = create(:provider_user, email_address: '[email protected]') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,10 @@ | |
|
||
RSpec.describe SupportUser do | ||
describe 'validations' do | ||
it 'flags email addresses that differ only by case as duplicates' do | ||
create(:support_user, email_address: '[email protected]') | ||
duplicate_support_user = build(:support_user, email_address: '[email protected]') | ||
expect(duplicate_support_user).not_to be_valid | ||
Comment on lines
-5
to
-8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now covered by
|
||
end | ||
let!(:existing_support_user) { create(:support_user) } | ||
|
||
it { is_expected.to validate_presence_of(:email_address) } | ||
it { is_expected.to validate_uniqueness_of(:email_address).case_insensitive } | ||
end | ||
|
||
describe '#downcase_email_address' do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'DfESignInController#callbacks' do | ||
include DfESignInHelpers | ||
|
||
describe 'GET /auth/dfe/callback' do | ||
let(:omni_auth_hash) do | ||
fake_dfe_sign_in_auth_hash( | ||
email_address: '[email protected]', | ||
dfe_sign_in_uid: 'DFE_SIGN_IN_UID', | ||
first_name: '', | ||
last_name: '', | ||
) | ||
end | ||
|
||
before do | ||
OmniAuth.config.test_mode = true | ||
OmniAuth.config.mock_auth[:dfe] = omni_auth_hash | ||
end | ||
|
||
context 'there are no DfE sign omniauth values set' do | ||
let(:omni_auth_hash) { nil } | ||
|
||
it 'is forbidden by default' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before changes in this PR - this spec fails with
|
||
get auth_dfe_callback_path | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context 'when the Support User does not exist' do | ||
it 'does not sign in' do | ||
get support_interface_sign_in_path # makes sure the session[:post_dfe_sign_in_path] is set | ||
get auth_dfe_callback_path | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context 'when Support User exists with matching dfe_sign_in_uid' do | ||
let!(:support_user) { create(:support_user, dfe_sign_in_uid: 'DFE_SIGN_IN_UID') } | ||
|
||
it 'signs the Support User in' do | ||
get support_interface_sign_in_path # makes sure the session[:post_dfe_sign_in_path] is set | ||
get auth_dfe_callback_path | ||
|
||
expect(response).to redirect_to(support_interface_path) | ||
end | ||
|
||
it 'redirects to the Support interface when the post_dfe_sign_in_path is set to the Provider Interface' do | ||
# FIXME: Reliance on the session[:post_dfe_sign_in_path] is an anti-pattern | ||
skip('The use of session[:post_dfe_sign_in_path] is an anti-pattern') | ||
|
||
get provider_interface_sign_in_path # makes sure the session[:post_dfe_sign_in_path] is set | ||
get auth_dfe_callback_path | ||
|
||
expect(response).to redirect_to(support_interface_path) | ||
end | ||
end | ||
|
||
context 'when a different Support User exists with the same email address' do | ||
let!(:support_user) { create(:support_user, dfe_sign_in_uid: 'DFE_SIGN_IN_UID') } | ||
let!(:existing_support_user) { create(:support_user, email_address: '[email protected]') } | ||
|
||
it 'does not sign the Support User in' do | ||
get support_interface_sign_in_path # makes sure the session[:post_dfe_sign_in_path] is set | ||
get auth_dfe_callback_path | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before changes in this PR - this spec fails with
|
||
end | ||
end | ||
|
||
context 'when Provider User exists with matching dfe_sign_in_uid' do | ||
let!(:provider_user) { create(:provider_user, dfe_sign_in_uid: 'DFE_SIGN_IN_UID') } | ||
|
||
it 'signs the Provider User in' do | ||
get provider_interface_sign_in_path # makes sure the session[:post_dfe_sign_in_path] is set | ||
get auth_dfe_callback_path | ||
|
||
expect(response).to redirect_to(provider_interface_path) | ||
end | ||
|
||
it 'redirects to the Provider interface when the post_dfe_sign_in_path is set to the Support Interface' do | ||
# FIXME: Reliance on the session[:post_dfe_sign_in_path] is an anti-pattern | ||
skip('The use of session[:post_dfe_sign_in_path] is an anti-pattern') | ||
|
||
get support_interface_sign_in_path # makes sure the session[:post_dfe_sign_in_path] is set | ||
get auth_dfe_callback_path | ||
|
||
expect(response).to redirect_to(provider_interface_path) | ||
end | ||
end | ||
|
||
context 'when a different Provider User exists with the same email address' do | ||
let!(:provider_user) { create(:provider_user, dfe_sign_in_uid: 'DFE_SIGN_IN_UID') } | ||
let!(:existing_provider_user) { create(:provider_user, email_address: '[email protected]') } | ||
|
||
it 'does not sign the Provider User in' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before changes in this PR - this spec fails with
|
||
get provider_interface_sign_in_path # makes sure the session[:post_dfe_sign_in_path] is set | ||
get auth_dfe_callback_path | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end | ||
end |
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.
support_user
was never used in this spec