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

🐛 [#4199] Delete authinfo from session after it's stored on submission #4271

Merged
merged 5 commits into from
May 24, 2024

Conversation

stevenbal
Copy link
Contributor

@stevenbal stevenbal commented May 6, 2024

Closes #4199 partly
Related PR: open-formulieren/open-forms-sdk#688

Changes

  • Delete authinfo from session after it's stored on submission
  • Add explicit anonymous option to submission endpoint

TODO:

  • add test for anonymous attribute
  • check where FORM_AUTH_SESSION_KEY is used
    • set_auth_attribute_on_session
    • set_cosign_data_on_submission (cosign also uses is_authenticated_with_an_allowed_plugin)
    • ResumeFormMixin: is_auth_data_correct / get_redirect_url -> user is always forced to login again (is this an issue?)
      • is_authenticated_with_plugin / meets_plugin_requirements -> run after relogging, so this is fine
      • EHerkenningAuthentication.check_requirements -> used in meets_plugin_requirements which is only used for resume flow
      • VerifyChangeAppointmentLinkView.custom_submission_modifications -> only used in resume flow
  • expose function to remove auth info from session in service.py
  • call this function at end of add_submission_to_session and other functions that rely on this attr (?)
  • update branch in CI of token-exchange lib to see if it passes: [DO NOT MERGE] 📌 Test with session persistance branch open-forms-ext-token-exchange#16

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages.sh
    • Ran ./bin/compilemessages_js.sh
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

@stevenbal stevenbal changed the title Issue/4199 session persistance ignores login choice 🐛 [#4199] Delete authinfo from session after it's stored on submission May 6, 2024
@stevenbal stevenbal marked this pull request as draft May 6, 2024 14:13
@stevenbal stevenbal force-pushed the issue/4199-session-persistance-ignores-login-choice branch from ed4be3c to 5532a35 Compare May 6, 2024 14:40
Copy link

codecov bot commented May 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.27%. Comparing base (9b49cd1) to head (49783de).
Report is 729 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4271   +/-   ##
=======================================
  Coverage   96.26%   96.27%           
=======================================
  Files         731      731           
  Lines       23718    23735   +17     
  Branches     2795     2797    +2     
=======================================
+ Hits        22833    22850   +17     
  Misses        616      616           
  Partials      269      269           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stevenbal stevenbal force-pushed the issue/4199-session-persistance-ignores-login-choice branch 2 times, most recently from 2f5e00b to b10b789 Compare May 13, 2024 13:11
@stevenbal stevenbal force-pushed the issue/4199-session-persistance-ignores-login-choice branch 4 times, most recently from 6032e0d to bf4318f Compare May 23, 2024 10:43
@stevenbal stevenbal marked this pull request as ready for review May 23, 2024 10:57
@stevenbal stevenbal force-pushed the issue/4199-session-persistance-ignores-login-choice branch from bf4318f to d731ee5 Compare May 23, 2024 11:03
@stevenbal
Copy link
Contributor Author

stevenbal commented May 23, 2024

@sergei-maertens I'm not 100% sure if this needs backport, what is our policy for when to backport bugfixes?

@stevenbal stevenbal requested a review from sergei-maertens May 23, 2024 11:04
@stevenbal
Copy link
Contributor Author

@sergei-maertens I checked the usage of the session auth info and I didn't notice any problems if we remove it from the session, the only thing that changes is that when resuming a form, the user will always be forced to login again even if it's within the same session (because the authinfo isn't persisted on the session anymore)

@sergei-maertens
Copy link
Member

@sergei-maertens I'm not 100% sure if this needs backport, what is our policy for when to backport bugfixes?

We typically label the ticket as such during refinement, based on how big the impact is and whether a workaround exists or not.

I think that the odds that a end user is filling out multiple forms at the same time where one is authenticated and the other one not are pretty low, so I don't think it warrants a backport. There also doesn't seem to be a stakeholder (except for us) in this, so it doesn't seem to be a big problem.

@sergei-maertens
Copy link
Member

@sergei-maertens I checked the usage of the session auth info and I didn't notice any problems if we remove it from the session, the only thing that changes is that when resuming a form, the user will always be forced to login again even if it's within the same session (because the authinfo isn't persisted on the session anymore)

I think that's a good side-effect of this patch, it fits better with the expectations that resuming always forces you to re-authenticate and creates less different authentication flows for the same "mechanism".

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a test with explicit anonymous start in openforms.submissions.tests.test_start_submission.

I don't put too much value on the unit tests of the signal, I'm mostly interested in the integration tests for the POST call that those behave as expected, so please add a test that sets up an authentication state and creates an anonymous submission and make assertions on that created submission.

src/openforms/authentication/tests/test_signals.py Outdated Show resolved Hide resolved
factory = APIRequestFactory()
request = factory.get("/foo")
request.session = self.client.session
request = Request(request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
request = Request(request)

APIRequestFactory already produces a Request instance, no?

I'd expect your type checker to complain about this too btw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too, that is why I used APIRequestFactory instead of RequestFactory but strangely enough my type checker complains about this if I don't explicitly cast it:

Screenshot from 2024-05-23 14-23-20

Copy link
Member

@sergei-maertens sergei-maertens May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you add an assert isinstance(request, Rrequest) after it? That should help the type checker

I am talking nonsense, the factory just generates a plain Django HttpRequest and the Request layer from DRF is something that only happens in views at runtime.

You could use openforms.typing.AnyRequest in your function signature instead, since the Request instance proxies down into the HttpRequest anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add AnyRequest 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means my type checker isn't messed up? 😄

src/openforms/submissions/api/viewsets.py Outdated Show resolved Hide resolved
@stevenbal stevenbal force-pushed the issue/4199-session-persistance-ignores-login-choice branch from d731ee5 to 4e3f218 Compare May 23, 2024 13:22
@stevenbal stevenbal requested a review from sergei-maertens May 23, 2024 13:24
stevenbal added 2 commits May 23, 2024 15:32
to allow the SDK to explicitly indicate that the submission is without authentication
@stevenbal stevenbal force-pushed the issue/4199-session-persistance-ignores-login-choice branch from 4e3f218 to 32448bc Compare May 23, 2024 13:32
@stevenbal
Copy link
Contributor Author

@sergei-maertens
Copy link
Member

Is this a known flaky test? @sergei-maertens https://github.com/open-formulieren/open-forms/actions/runs/9208977538/job/25332413671?pr=4271#step:7:3347

Yeah, sporadically it crashes. hypothesis tends to reveal those cases...

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it up to you to hit the merge button if this is ready to be merged in your opinion :)

or after the cosign data is set, previously an anonymous submission that is started after the user started an authenticated submission within the same session would incorrectly get the same authentication information attached to it as the authenticated submission
@stevenbal stevenbal force-pushed the issue/4199-session-persistance-ignores-login-choice branch from 32448bc to 49783de Compare May 24, 2024 07:56
@stevenbal
Copy link
Contributor Author

I'll leave it up to you to hit the merge button if this is ready to be merged in your opinion :)

I pushed the typing changed and will merge it once CI passes

@stevenbal stevenbal merged commit ba91722 into master May 24, 2024
28 checks passed
@stevenbal stevenbal deleted the issue/4199-session-persistance-ignores-login-choice branch May 24, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session persistance causes login choice te be ignored
2 participants