Skip to content

Commit

Permalink
update gov one helper and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-coggin committed Nov 16, 2023
1 parent a15457b commit 36ee42d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 2 additions & 5 deletions app/helpers/gov_one_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ def login_uri
client_id: Rails.application.config.gov_one_client_id,
nonce: SecureRandom.uuid,
state: SecureRandom.uuid,
redirect_uri: GovOneAuthService::CALLBACKS[:login],
}

session[:gov_one_auth_state] = params[:state]

gov_one_uri(:login, params).to_s
"#{gov_one_uri(:login, params)}&redirect_uri=#{GovOneAuthService::CALLBACKS[:login]}"
end

# @return [String]
def logout_uri
params = {
id_token_hint: session[:id_token],
state: SecureRandom.uuid,
post_logout_redirect_uri: GovOneAuthService::CALLBACKS[:logout],
}

gov_one_uri(:logout, params).to_s
"#{gov_one_uri(:logout, params)}&post_logout_redirect_uri=#{GovOneAuthService::CALLBACKS[:logout]}"
end

# @return [String]
Expand Down
12 changes: 7 additions & 5 deletions spec/helpers/gov_one_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
subject(:login_uri) { helper.login_uri }

it 'encodes the authorize endpoint params' do
expect(login_uri).to start_with 'https://oidc.test.account.gov.uk/authorize?response_type=code&scope=email+openid&client_id='
expect(login_uri).to end_with 'redirect_uri=http%3A%2F%2Frecovery.app%2Fusers%2Fauth%2Fopenid_connect%2Fcallback'
expect(login_uri).to start_with 'https://oidc.test.account.gov.uk/authorize?response_type=code&scope=email+openid&client_id=some_client_id&'
expect(login_uri).to end_with 'redirect_uri=http://recovery.app/users/auth/openid_connect/callback'
end
end

Expand All @@ -15,25 +15,27 @@

it 'encodes the logout endpoint params' do
expect(logout_uri).to start_with 'https://oidc.test.account.gov.uk/logout?id_token_hint&state='
expect(logout_uri).to end_with '&post_logout_redirect_uri=http%3A%2F%2Frecovery.app%2Fusers%2Fsign_out'
expect(logout_uri).to end_with '&post_logout_redirect_uri=http://recovery.app/users/sign_out'
end
end

describe '#login_button' do
subject(:login_button) { helper.login_button }

it 'returns a link to the login uri' do
it 'returns a button link to the gov one login uri' do
expect(login_button).to include 'govuk-button'
expect(login_button).to include 'Sign in with Gov One Login'
expect(login_button).to include 'href="https://oidc.test.account.gov.uk/authorize?response_type=code&scope=email+openid&client_id=some_client_id&'
end
end

describe '#logout_button' do
subject(:logout_button) { helper.logout_button }

it 'returns a link to the login uri' do
it 'returns a button link to the gov one logout uri' do
expect(logout_button).to include 'govuk-button'
expect(logout_button).to include 'Sign out of Gov One Login'
expect(logout_button).to include 'href="https://oidc.test.account.gov.uk/logout?id_token_hint&state='
end
end
end
6 changes: 3 additions & 3 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
let(:email) { '[email protected]' }
let(:gov_one_id) { '123' }

context 'when user exists with email but no gov_one_id' do
context 'with an existing user having an email but no gov_one_id' do
let!(:user) { create(:user, email: email) }

it 'updates the user gov_one_id' do
Expand All @@ -220,7 +220,7 @@
end
end

context 'when user exists with gov_one_id' do
context 'with an existing user having a gov_one_id' do
let!(:user) { create(:user, gov_one_id: gov_one_id) }

it 'updates the user email' do
Expand All @@ -229,7 +229,7 @@
end
end

context 'when user does not exist' do
context 'without an existing user' do
let(:email) { '[email protected]' }
let(:gov_one_id) { '321' }

Expand Down

0 comments on commit 36ee42d

Please sign in to comment.