mirror of
https://github.com/bitwarden/server
synced 2025-12-19 17:53:44 +00:00
[PM-25675] - fix NormalCipherPermissions.CanDelete (#6666)
* fix NormalCipherPermissions.CanDelete * fix test * fix tests
This commit is contained in:
@@ -14,7 +14,7 @@ public class NormalCipherPermissions
|
|||||||
throw new Exception("Cipher needs to belong to a user or an organization.");
|
throw new Exception("Cipher needs to belong to a user or an organization.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.Id == cipherDetails.UserId)
|
if (cipherDetails.OrganizationId == null && user.Id == cipherDetails.UserId)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class CiphersControllerTests
|
|||||||
sutProvider.GetDependency<ICipherRepository>().GetByIdAsync(id, userId).ReturnsForAnyArgs(cipherDetails);
|
sutProvider.GetDependency<ICipherRepository>().GetByIdAsync(id, userId).ReturnsForAnyArgs(cipherDetails);
|
||||||
|
|
||||||
sutProvider.GetDependency<ICollectionCipherRepository>().GetManyByUserIdCipherIdAsync(userId, id).Returns((ICollection<CollectionCipher>)new List<CollectionCipher>());
|
sutProvider.GetDependency<ICollectionCipherRepository>().GetManyByUserIdCipherIdAsync(userId, id).Returns((ICollection<CollectionCipher>)new List<CollectionCipher>());
|
||||||
sutProvider.GetDependency<IApplicationCacheService>().GetOrganizationAbilitiesAsync().Returns(new Dictionary<Guid, OrganizationAbility> { { cipherDetails.OrganizationId.Value, new OrganizationAbility() } });
|
sutProvider.GetDependency<IApplicationCacheService>().GetOrganizationAbilitiesAsync().Returns(new Dictionary<Guid, OrganizationAbility> { { cipherDetails.OrganizationId.Value, new OrganizationAbility { Id = cipherDetails.OrganizationId.Value } } });
|
||||||
var cipherService = sutProvider.GetDependency<ICipherService>();
|
var cipherService = sutProvider.GetDependency<ICipherService>();
|
||||||
|
|
||||||
await sutProvider.Sut.PutCollections_vNext(id, model);
|
await sutProvider.Sut.PutCollections_vNext(id, model);
|
||||||
@@ -95,7 +95,7 @@ public class CiphersControllerTests
|
|||||||
sutProvider.GetDependency<ICipherRepository>().GetByIdAsync(id, userId).ReturnsForAnyArgs(cipherDetails);
|
sutProvider.GetDependency<ICipherRepository>().GetByIdAsync(id, userId).ReturnsForAnyArgs(cipherDetails);
|
||||||
|
|
||||||
sutProvider.GetDependency<ICollectionCipherRepository>().GetManyByUserIdCipherIdAsync(userId, id).Returns((ICollection<CollectionCipher>)new List<CollectionCipher>());
|
sutProvider.GetDependency<ICollectionCipherRepository>().GetManyByUserIdCipherIdAsync(userId, id).Returns((ICollection<CollectionCipher>)new List<CollectionCipher>());
|
||||||
sutProvider.GetDependency<IApplicationCacheService>().GetOrganizationAbilitiesAsync().Returns(new Dictionary<Guid, OrganizationAbility> { { cipherDetails.OrganizationId.Value, new OrganizationAbility() } });
|
sutProvider.GetDependency<IApplicationCacheService>().GetOrganizationAbilitiesAsync().Returns(new Dictionary<Guid, OrganizationAbility> { { cipherDetails.OrganizationId.Value, new OrganizationAbility { Id = cipherDetails.OrganizationId.Value } } });
|
||||||
|
|
||||||
var result = await sutProvider.Sut.PutCollections_vNext(id, model);
|
var result = await sutProvider.Sut.PutCollections_vNext(id, model);
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class NormalCipherPermissionTests
|
|||||||
var cipherDetails = new CipherDetails { UserId = null, OrganizationId = Guid.NewGuid() };
|
var cipherDetails = new CipherDetails { UserId = null, OrganizationId = Guid.NewGuid() };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var exception = Assert.Throws<Exception>(() => NormalCipherPermissions.CanDelete(user, cipherDetails, organizationAbility));
|
var exception = Assert.Throws<Exception>(() => NormalCipherPermissions.CanRestore(user, cipherDetails, organizationAbility));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("Cipher does not belong to the input organization.", exception.Message);
|
Assert.Equal("Cipher does not belong to the input organization.", exception.Message);
|
||||||
@@ -92,11 +92,11 @@ public class NormalCipherPermissionTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
var user = new User { Id = Guid.Empty };
|
var user = new User { Id = Guid.Empty };
|
||||||
var organizationId = Guid.NewGuid();
|
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 };
|
||||||
var organizationAbility = new OrganizationAbility { Id = organizationId, LimitItemDeletion = limitItemDeletion };
|
var organizationAbility = new OrganizationAbility { Id = organizationId, LimitItemDeletion = limitItemDeletion };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = NormalCipherPermissions.CanRestore(user, cipherDetails, organizationAbility);
|
var result = NormalCipherPermissions.CanDelete(user, cipherDetails, organizationAbility);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(result, expectedResult);
|
Assert.Equal(result, expectedResult);
|
||||||
|
|||||||
Reference in New Issue
Block a user