Prevent admins from deleting their own account#9139
Merged
ogenstad merged 2 commits intoMay 7, 2026
Conversation
Contributor
Author
Verdict: APPROVEDThe replication test is realistic, correctly scoped, and confirmed to fail against the buggy code. It follows project testing conventions (no mocking, exact-match GraphQL error assertion, imports at the top, no issue references in test names). A. Test realism
B. Test correctness
C. Test quality
D. Alignment with analysis
Suggestions (non-blocking)
Recommended next steps
|
gmazoyer
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why (from Patrick)
Prevents a user from deleting their own account, i.e. the last remaining admin should not be able to delete their own account.
Fixes #9138.
Changes
AI summary below
Analyst's findings (summary)
Replication test
Test file:
backend/tests/component/graphql/test_core_account.pyTest name:
test_admin_cannot_delete_own_accountWhat it tests: Asserts that calling
CoreAccountDeletewith the authenticated admin's own account ID returns a GraphQL error instead of succeeding silently.Verification: Test confirmed FAILING on current code.
Failure reason:
result.errorsisNonebecausemutate_deletehas no self-deletion guard and deletes the account without raising any error — the mutation returnsok: True.Failure output (last 20 lines)
Test expectations
The test asserts that when an authenticated admin sends a
CoreAccountDeletemutation targeting their own account ID, the GraphQL response contains an error. Specifically, it expectsresult.errorsto be non-empty and the error message to equal"Cannot delete your own account".The fix must:
original_account_idtoAccountSessioninauth.pyand populate it inprepare_graphql_paramsInfrahubAccountMutationinmutations/account.pythat overridesmutate_deleteto compare the target node ID againstoriginal_account_idand raiseValidationError("Cannot delete your own account")if they matchInfrahubKind.ACCOUNT: InfrahubAccountMutationinmanager.pyThe test does NOT cover the context-override bypass path (that requires a separate test case once the
original_account_idfield exists).