fix: clean up auth when deleting named contexts
Description
- Fixes named context deletion so cleanup uses the removed context's referenced
userandservervalues instead of the context name. - Removes the associated auth entry when deleting a context, matching the expected cleanup behavior for credentials tied to that server.
- Adds a regression test covering
context --deletefor a named context wherecontexts[].namediffers fromcontexts[].user.
Screenshot
Related issue(s)
Fixes #427
hey @Harsh4902 , would love your feedback here
@cotishq Please resolve the conflicts.
The current delete path uses the context name for user cleanup, which is wrong for named contexts where contexts[].name != contexts[].user. Cleaning up by the removed ContextRef is the right direction, and adding auth cleanup for the associated server also makes sense.
One thing to double-check before merge: are server, user, or auth entries ever intentionally shared by multiple contexts? If yes, deleting them unconditionally here could remove credentials/config still referenced by another context. If they are always 1:1 with a context, then this is fine.
If shared references are not a supported case, LGTM. @Harsh4902
yeah you are right, since microcks login supports the --name flag, users can define multiple named contexts pointing to the same server or user. so if one is deleted, deleting the server, user or auth config unconditionally would indeed break the remaining contexts that reference them.
i think we should check if any other contexts still reference the removed contexts user or server before deleting them.
what's your opinion should i update the PR to add references checking ?
yeah you are right, since microcks login supports the --name flag, users can define multiple named contexts pointing to the same server or user. so if one is deleted, deleting the server, user or auth config unconditionally would indeed break the remaining contexts that reference them.
i think we should check if any other contexts still reference the removed contexts user or server before deleting them.
what's your opinion should i update the PR to add references checking ?
Yes, please update the PR with reference checks.
Because multiple named contexts can share the same server / user / auth, we should only remove those entries if the deleted context was the last one referencing them.
Please add tests for both shared-reference and last-reference cases as well. Then I’ll re-review.