-
Notifications
You must be signed in to change notification settings - Fork 166
Handle invalid OIDC requests before persisting #1494
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
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 |
|---|---|---|
|
|
@@ -12,4 +12,8 @@ def deactivate | |
| def sp_metadata | ||
| {} | ||
| end | ||
|
|
||
| def session_uuid | ||
| nil | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,64 +34,22 @@ | |
| let(:code_challenge_method) { nil } | ||
|
|
||
| describe '#submit' do | ||
| let(:user) { create(:user) } | ||
| let(:rails_session_id) { SecureRandom.hex } | ||
| subject(:result) { form.submit(user, rails_session_id) } | ||
| subject(:result) { form.submit } | ||
|
|
||
| context 'with valid params' do | ||
| it 'is successful' do | ||
| allow(FormResponse).to receive(:new) | ||
|
|
||
| form.submit(user, rails_session_id) | ||
|
|
||
| identity = user.identities.where(service_provider: client_id).first | ||
| form.submit | ||
|
|
||
| extra_attributes = { | ||
| client_id: client_id, | ||
| redirect_uri: "#{redirect_uri}?code=#{identity.session_uuid}&state=#{state}", | ||
| redirect_uri: nil, | ||
|
Contributor
Author
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. this should have no
Contributor
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. It should have a key. The
Contributor
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. The
Contributor
Author
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. Ah right! I forgot about that part, thanks! |
||
| } | ||
|
|
||
| expect(FormResponse).to have_received(:new). | ||
| with(success: true, errors: {}, extra: extra_attributes) | ||
| end | ||
|
|
||
| it 'links an identity for this client with the code as the session_uuid' do | ||
| redirect_uri = URI(result.to_h[:redirect_uri]) | ||
| code = URIService.params(redirect_uri)[:code] | ||
|
|
||
| identity = user.identities.where(service_provider: client_id).first | ||
| expect(identity.session_uuid).to eq(code) | ||
| expect(identity.nonce).to eq(nonce) | ||
| end | ||
|
|
||
| it 'sets the max ial/loa from the request on the identity' do | ||
| result | ||
|
|
||
| identity = user.identities.where(service_provider: client_id).first | ||
| expect(identity.ial).to eq(3) | ||
| end | ||
|
|
||
| context 'with PKCE' do | ||
| let(:code_challenge) { 'abcdef' } | ||
| let(:code_challenge_method) { 'S256' } | ||
|
|
||
| it 'records the code_challenge on the identity' do | ||
| allow(FormResponse).to receive(:new) | ||
|
|
||
| form.submit(user, rails_session_id) | ||
|
|
||
| identity = user.identities.where(service_provider: client_id).first | ||
|
|
||
| extra_attributes = { | ||
| client_id: client_id, | ||
| redirect_uri: "#{redirect_uri}?code=#{identity.session_uuid}&state=#{state}", | ||
| } | ||
|
|
||
| expect(identity.code_challenge).to eq(code_challenge) | ||
| expect(FormResponse).to have_received(:new). | ||
| with(success: true, errors: {}, extra: extra_attributes) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'with invalid params' do | ||
|
|
@@ -291,4 +249,45 @@ | |
| expect(form.client_id).to eq 'foobar' | ||
| end | ||
| end | ||
|
|
||
| describe '#link_identity_to_service_provider' do | ||
| let(:user) { create(:user) } | ||
| let(:rails_session_id) { SecureRandom.hex } | ||
|
|
||
| context 'with PKCE' do | ||
| let(:code_challenge) { 'abcdef' } | ||
| let(:code_challenge_method) { 'S256' } | ||
|
|
||
| it 'records the code_challenge on the identity' do | ||
| form.link_identity_to_service_provider(user, rails_session_id) | ||
|
|
||
| identity = user.identities.where(service_provider: client_id).first | ||
|
|
||
| expect(identity.code_challenge).to eq(code_challenge) | ||
| expect(identity.nonce).to eq(nonce) | ||
| expect(identity.ial).to eq(3) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe '#success_redirect_uri' do | ||
| let(:user) { create(:user) } | ||
| let(:rails_session_id) { SecureRandom.hex } | ||
|
|
||
| context 'when the identity has been linked' do | ||
| it 'returns a redirect URI with the code from the identity session_uuid' do | ||
| form.link_identity_to_service_provider(user, rails_session_id) | ||
| identity = user.identities.where(service_provider: client_id).first | ||
|
|
||
| expect(form.success_redirect_uri). | ||
| to eq "#{redirect_uri}?code=#{identity.session_uuid}&state=#{state}" | ||
| end | ||
| end | ||
|
|
||
| context 'when the identity has not been linked' do | ||
| it 'returns nil' do | ||
| expect(form.success_redirect_uri).to be_nil | ||
| 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.
What is the reason for redirecting in this scenario? Shouldn't all invalid requests be treated the same? Also, what is the user experience here (in general, not this particular test)? If bad requests are (usually) the fault of the SP, does it make sense to display an error page to the user for something they did not cause? Does the error page have a helpful message explaining what happened and what they can do?
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.
Some requests are "good enough" that we can redirect and provide an error to the client, so that they can handle the error (good enough in that the
client_idandredirect_urimatch each other)We display errors when the requests are not good enough to redirect