Stop 2FA override leaking from definition spec#23952
Conversation
The two "with definitions from plugins" examples called `override_value` directly on the shared `plugin_openproject_two_factor_authentication` definition instance. The "with settings reset" context snapshots `@all` shallowly, so the in-place mutation (2FA `enforced: true`) survived the restore and leaked globally. Any spec performing a real `post signin_path` login later in the same process (e.g. backlogs sprints request specs) was then forced into 2FA, never completing login, and failed with 401. Operates on a `dup` of the definition so `override_value` no longer mutates the instance retained by the snapshot.
There was a problem hiding this comment.
Pull request overview
This PR fixes an intermittent test-isolation leak in spec/constants/settings/definition_spec.rb by ensuring the spec no longer mutates the shared plugin_openproject_two_factor_authentication settings definition instance when exercising ENV overrides. This prevents later specs from inheriting an unintended “2FA enforced” configuration due to shallow snapshot/restore behavior.
Changes:
- Duplicate (
dup) the plugin settings definition before calling the privateoverride_valuehelper, so the shared definition inSettings::Definition.allis not mutated. - Update expectations to assert against the duplicated definition’s overridden value.
- Add clarifying comments documenting why the
dupis required (shallow restore of the settings snapshot).
|
Warning This pull request does not link an OpenProject work package. Please add a link to the work package in the description, or reference it in the |
|
Warning Flaky specs
🤖 Ask Copilot to investigateCopy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer. |
What are you trying to accomplish?
A test-isolation leak in
spec/constants/settings/definition_spec.rbintermittently fails unrelated request specs (e.g.modules/backlogs/spec/requests/backlogs/sprints_spec.rb) with401/302, depending on suite ordering. It surfaced on the CI for #23938 but is independent of that change.The two "with definitions from plugins" examples call
override_valuedirectly on the sharedplugin_openproject_two_factor_authenticationdefinition instance.override_valuemutates the object in place (enforced: true), and the"with settings reset"context only snapshots/restoresSettings::Definition.allshallowly — so the mutation survives into later examples. Any spec that performs a realpost signin_pathlogin afterwards is then forced into 2FA, never completes login, and fails.What approach did you choose and why?
dupof the definition before callingoverride_value, so the shared instance retained by the snapshot is never mutated.coerce/value=already reassign (deep_mergereturns a new hash), so the dup is fully independent.Merge checklist