-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-25675] - fix NormalCipherPermissions.CanDelete #6666
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ public void CanRestore_WhenCipherDoesNotBelongToInputOrganization_ShouldThrowExc | |
| var cipherDetails = new CipherDetails { UserId = null, OrganizationId = Guid.NewGuid() }; | ||
|
|
||
| // Act | ||
| var exception = Assert.Throws<Exception>(() => NormalCipherPermissions.CanDelete(user, cipherDetails, organizationAbility)); | ||
| var exception = Assert.Throws<Exception>(() => NormalCipherPermissions.CanRestore(user, cipherDetails, organizationAbility)); | ||
|
|
||
| // Assert | ||
| Assert.Equal("Cipher does not belong to the input organization.", exception.Message); | ||
|
|
@@ -92,11 +92,11 @@ public void CanDelete_WhenCipherIsOwnedByOrganization( | |
| // Arrange | ||
| var user = new User { Id = Guid.Empty }; | ||
| var organizationId = Guid.NewGuid(); | ||
| var cipherDetails = new CipherDetails { Manage = manage, Edit = edit, UserId = null, OrganizationId = organizationId }; | ||
| var cipherDetails = new CipherDetails { Manage = manage, Edit = edit, UserId = user.Id, OrganizationId = organizationId }; | ||
|
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. 💭 This test now sets Question: Is this intentional to match the SQL view behavior? Or should the test maintain For comparison, the |
||
| var organizationAbility = new OrganizationAbility { Id = organizationId, LimitItemDeletion = limitItemDeletion }; | ||
|
|
||
| // Act | ||
| var result = NormalCipherPermissions.CanRestore(user, cipherDetails, organizationAbility); | ||
| var result = NormalCipherPermissions.CanDelete(user, cipherDetails, organizationAbility); | ||
|
|
||
| // Assert | ||
| Assert.Equal(result, expectedResult); | ||
|
|
||
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.
👍 Excellent fix! Adding the
cipherDetails.OrganizationId == nullcheck correctly distinguishes between personal and organization ciphers, even when the SQL view injects the user's ID intoUserIdfor org ciphers.This properly enforces the ownership boundary: personal ciphers can be deleted by their owner (
UserIdmatches and noOrganizationId), while org ciphers must go through the organization permission checks below.