-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix merge conflicts and update locales
- Loading branch information
Showing
14 changed files
with
157 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
svg.govuk-button__start-icon xmlns='http://www.w3.org/2000/svg' width='17.5' height='19' viewBox='0 0 33 40' aria-hidden='true' focusable='false' | ||
path fill='currentColor' d='M0 0h13l20 20-20 20H0l20-20z' |
This file was deleted.
Oops, something went wrong.
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
100 changes: 54 additions & 46 deletions
100
spec/controllers/users/omniauth_callbacks_controller_spec.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 |
---|---|---|
@@ -1,58 +1,66 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Users::OmniauthCallbacksController, type: :controller do | ||
let(:auth_service) { instance_double(GovOneAuthService) } | ||
let(:access_token) { 'mock_access_token' } | ||
let(:id_token) { 'mock_id_token' } | ||
let(:email) { '[email protected]' } | ||
let(:params) do | ||
{ 'code' => 'mock_code', 'state' => 'mock_state' } | ||
end | ||
|
||
before do | ||
request.env['devise.mapping'] = Devise.mappings[:user] | ||
session[:gov_one_auth_state] = 'mock_state' | ||
|
||
allow(GovOneAuthService).to receive(:new).and_return(auth_service) | ||
allow(auth_service).to receive(:tokens).and_return({ 'access_token' => access_token, 'id_token' => id_token }) | ||
allow(auth_service).to receive(:user_info).and_return({ 'email' => email }) | ||
allow(auth_service).to receive(:jwt_assertion).and_return('mock_jwt_assertion') | ||
allow(auth_service).to receive(:decode_id_token).and_return([{ 'sub' => 'mock_sub' }]) | ||
end | ||
|
||
context 'with a new user' do | ||
before do | ||
get :openid_connect, params: params | ||
end | ||
|
||
it 'creates an account' do | ||
expect(User.find_by(email: email)).to be_truthy | ||
expect(User.find_by(gov_one_id: 'mock_sub')).to be_truthy | ||
end | ||
|
||
it 'redirects to complete registration' do | ||
expect(session[:id_token]).to eq id_token | ||
expect(response).to redirect_to edit_registration_name_path | ||
end | ||
end | ||
|
||
describe '#openid_connect' do | ||
let(:auth_service) { instance_double(GovOneAuthService) } | ||
let(:access_token) { 'mock_access_token' } | ||
let(:id_token) { 'mock_id_token' } | ||
let(:email) { '[email protected]' } | ||
context 'with an existing non-gov-one user' do | ||
before do | ||
create :user, :registered, email: email | ||
get :openid_connect, params: params | ||
end | ||
|
||
it 'updates the account' do | ||
expect(User.find_by(gov_one_id: 'mock_sub')).to be_truthy | ||
end | ||
|
||
it 'redirects to /my-modules' do | ||
expect(session[:id_token]).to eq id_token | ||
expect(response).to redirect_to my_modules_path | ||
end | ||
end | ||
|
||
context 'with an existing gov-one user' do | ||
before do | ||
allow(GovOneAuthService).to receive(:new).and_return(auth_service) | ||
allow(auth_service).to receive(:tokens).and_return({ 'access_token' => access_token, 'id_token' => id_token }) | ||
allow(auth_service).to receive(:user_info).and_return({ 'email' => email }) | ||
allow(auth_service).to receive(:jwt_assertion).and_return('mock_jwt_assertion') | ||
allow(auth_service).to receive(:decode_id_token).and_return([{ 'sub' => 'mock_sub' }]) | ||
session[:gov_one_auth_state] = 'mock_state' | ||
end | ||
|
||
context 'when a User does not exist' do | ||
it 'creates the user with the email and id_token' do | ||
get :openid_connect, params: { 'code' => 'mock_code', 'state' => 'mock_state' } | ||
expect(User.find_by(email: email)).to be_truthy | ||
expect(User.find_by(gov_one_id: 'mock_sub')).to be_truthy | ||
expect(response).to redirect_to(edit_registration_name_path) | ||
expect(session[:id_token]).to eq(id_token) | ||
end | ||
end | ||
|
||
context 'when a User email exists' do | ||
before do | ||
create :user, :registered, email: email | ||
end | ||
|
||
it 'updates the user id_token and signs them in' do | ||
get :openid_connect, params: { 'code' => 'mock_code', 'state' => 'mock_state' } | ||
expect(User.find_by(gov_one_id: 'mock_sub')).to be_truthy | ||
expect(response).to redirect_to(my_modules_path) | ||
expect(session[:id_token]).to eq(id_token) | ||
end | ||
end | ||
|
||
context 'when a User id_token exists' do | ||
before do | ||
create :user, :registered, gov_one_id: 'mock_sub' | ||
end | ||
|
||
it 'signs the user in' do | ||
get :openid_connect, params: { 'code' => 'mock_code', 'state' => 'mock_state' } | ||
expect(response).to redirect_to(my_modules_path) | ||
expect(session[:id_token]).to eq(id_token) | ||
end | ||
create :user, :registered, gov_one_id: 'mock_sub' | ||
get :openid_connect, params: params | ||
end | ||
|
||
it 'redirects to /my-modules' do | ||
expect(session[:id_token]).to eq id_token | ||
expect(response).to redirect_to my_modules_path | ||
end | ||
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 |
---|---|---|
|
@@ -208,33 +208,40 @@ | |
end | ||
|
||
describe '.find_or_create_from_gov_one' do | ||
subject(:find_or_create) { described_class.find_or_create_from_gov_one(email: email, gov_one_id: gov_one_id) } | ||
|
||
let(:email) { '[email protected]' } | ||
let(:gov_one_id) { '123' } | ||
let(:user) { create(:user) } | ||
|
||
context 'with an existing user having an email but no gov_one_id' do | ||
let!(:user) { create(:user, email: email) } | ||
before do | ||
user.update_column(:email, email) | ||
find_or_create | ||
end | ||
|
||
it 'updates the user gov_one_id' do | ||
described_class.find_or_create_from_gov_one(email: email, gov_one_id: gov_one_id) | ||
expect(user.reload.gov_one_id).to eq(gov_one_id) | ||
end | ||
end | ||
|
||
context 'with an existing user having a gov_one_id' do | ||
let!(:user) { create(:user, gov_one_id: gov_one_id) } | ||
before do | ||
user.update_column(:gov_one_id, gov_one_id) | ||
find_or_create | ||
end | ||
|
||
it 'updates the user email' do | ||
described_class.find_or_create_from_gov_one(email: email, gov_one_id: gov_one_id) | ||
expect(user.reload.email).to eq(email) | ||
end | ||
end | ||
|
||
context 'without an existing user' do | ||
let(:email) { '[email protected]' } | ||
let(:gov_one_id) { '321' } | ||
before do | ||
find_or_create | ||
end | ||
|
||
it 'creates a new user' do | ||
described_class.find_or_create_from_gov_one(email: email, gov_one_id: gov_one_id) | ||
expect(described_class.count).to eq(1) | ||
expect(described_class.first.email).to eq(email) | ||
expect(described_class.first.gov_one_id).to eq(gov_one_id) | ||
|
Oops, something went wrong.