2022-06-30 01:46:41 +02:00
|
|
|
|
using System.Text.Json;
|
2021-03-30 23:21:46 +02:00
|
|
|
|
using AutoFixture.Xunit2;
|
|
|
|
|
using Bit.Api.Controllers;
|
2021-12-14 16:05:07 +01:00
|
|
|
|
using Bit.Api.Models.Request;
|
|
|
|
|
using Bit.Api.Models.Response;
|
2021-06-08 23:34:36 +02:00
|
|
|
|
using Bit.Core.Context;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Entities;
|
2021-03-30 23:21:46 +02:00
|
|
|
|
using Bit.Core.Enums;
|
|
|
|
|
using Bit.Core.Repositories;
|
|
|
|
|
using Bit.Core.Services;
|
|
|
|
|
using Bit.Core.Settings;
|
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Test.Controllers;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2021-03-30 23:21:46 +02:00
|
|
|
|
public class SendsControllerTests : IDisposable
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly SendsController _sut;
|
|
|
|
|
private readonly GlobalSettings _globalSettings;
|
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
|
private readonly ISendRepository _sendRepository;
|
|
|
|
|
private readonly ISendService _sendService;
|
|
|
|
|
private readonly ISendFileStorageService _sendFileStorageService;
|
|
|
|
|
private readonly ILogger<SendsController> _logger;
|
2021-06-08 23:34:36 +02:00
|
|
|
|
private readonly ICurrentContext _currentContext;
|
2021-03-30 23:21:46 +02:00
|
|
|
|
|
|
|
|
|
public SendsControllerTests()
|
|
|
|
|
{
|
|
|
|
|
_userService = Substitute.For<IUserService>();
|
|
|
|
|
_sendRepository = Substitute.For<ISendRepository>();
|
|
|
|
|
_sendService = Substitute.For<ISendService>();
|
|
|
|
|
_sendFileStorageService = Substitute.For<ISendFileStorageService>();
|
|
|
|
|
_globalSettings = new GlobalSettings();
|
|
|
|
|
_logger = Substitute.For<ILogger<SendsController>>();
|
2021-06-08 23:34:36 +02:00
|
|
|
|
_currentContext = Substitute.For<ICurrentContext>();
|
2021-03-30 23:21:46 +02:00
|
|
|
|
|
|
|
|
|
_sut = new SendsController(
|
|
|
|
|
_sendRepository,
|
|
|
|
|
_userService,
|
|
|
|
|
_sendService,
|
|
|
|
|
_sendFileStorageService,
|
|
|
|
|
_logger,
|
2021-06-08 23:34:36 +02:00
|
|
|
|
_globalSettings,
|
|
|
|
|
_currentContext
|
2021-03-30 23:21:46 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_sut?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory, AutoData]
|
|
|
|
|
public async Task SendsController_WhenSendHidesEmail_CreatorIdentifierShouldBeNull(
|
|
|
|
|
Guid id, Send send, User user)
|
|
|
|
|
{
|
|
|
|
|
var accessId = CoreHelpers.Base64UrlEncode(id.ToByteArray());
|
|
|
|
|
|
|
|
|
|
send.Id = default;
|
|
|
|
|
send.Type = SendType.Text;
|
2022-01-21 15:36:25 +01:00
|
|
|
|
send.Data = JsonSerializer.Serialize(new Dictionary<string, string>());
|
2021-03-30 23:21:46 +02:00
|
|
|
|
send.HideEmail = true;
|
|
|
|
|
|
|
|
|
|
_sendService.AccessAsync(id, null).Returns((send, false, false));
|
|
|
|
|
_userService.GetUserByIdAsync(Arg.Any<Guid>()).Returns(user);
|
|
|
|
|
|
|
|
|
|
var request = new SendAccessRequestModel();
|
|
|
|
|
var actionResult = await _sut.Access(accessId, request);
|
|
|
|
|
var response = (actionResult as ObjectResult)?.Value as SendAccessResponseModel;
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(response);
|
|
|
|
|
Assert.Null(response.CreatorIdentifier);
|
|
|
|
|
}
|
|
|
|
|
}
|