2022-10-25 21:23:49 +02:00
|
|
|
|
using System.Security.Claims;
|
2023-03-02 19:23:38 +01:00
|
|
|
|
using Bit.Api.Vault.Controllers;
|
|
|
|
|
using Bit.Api.Vault.Models.Request;
|
2022-10-25 21:23:49 +02:00
|
|
|
|
using Bit.Core.Services;
|
2023-03-02 19:23:38 +01:00
|
|
|
|
using Bit.Core.Vault.Models.Data;
|
|
|
|
|
using Bit.Core.Vault.Repositories;
|
2022-10-25 21:23:49 +02:00
|
|
|
|
using Bit.Test.Common.AutoFixture;
|
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Test.Controllers;
|
|
|
|
|
|
|
|
|
|
[ControllerCustomize(typeof(CiphersController))]
|
|
|
|
|
[SutProviderCustomize]
|
|
|
|
|
public class CiphersControllerTests
|
|
|
|
|
{
|
|
|
|
|
[Theory, BitAutoData]
|
|
|
|
|
public async Task PutPartialShouldReturnCipherWithGivenFolderAndFavoriteValues(Guid userId, Guid folderId, SutProvider<CiphersController> sutProvider)
|
|
|
|
|
{
|
|
|
|
|
var isFavorite = true;
|
|
|
|
|
var cipherId = Guid.NewGuid();
|
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IUserService>()
|
|
|
|
|
.GetProperUserId(Arg.Any<ClaimsPrincipal>())
|
|
|
|
|
.Returns(userId);
|
|
|
|
|
|
|
|
|
|
var cipherDetails = new CipherDetails
|
|
|
|
|
{
|
|
|
|
|
Favorite = isFavorite,
|
|
|
|
|
FolderId = folderId,
|
2023-03-02 19:23:38 +01:00
|
|
|
|
Type = Core.Vault.Enums.CipherType.SecureNote,
|
2022-10-25 21:23:49 +02:00
|
|
|
|
Data = "{}"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICipherRepository>()
|
|
|
|
|
.GetByIdAsync(cipherId, userId)
|
|
|
|
|
.Returns(Task.FromResult(cipherDetails));
|
|
|
|
|
|
|
|
|
|
var result = await sutProvider.Sut.PutPartial(cipherId.ToString(), new CipherPartialRequestModel { Favorite = isFavorite, FolderId = folderId.ToString() });
|
|
|
|
|
|
2023-07-14 17:18:26 +02:00
|
|
|
|
Assert.Equal(folderId, result.FolderId);
|
2022-10-25 21:23:49 +02:00
|
|
|
|
Assert.Equal(isFavorite, result.Favorite);
|
|
|
|
|
}
|
|
|
|
|
}
|