1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00
bitwarden-server/test/Api.Test/Tools/Models/Request/SendRequestModelTests.cs
Daniel James Smith 4e7b9d2edd
[PM-328] Move files for team-tools (#2857)
* Extract Import-Api endpoints into separate controller

Moved ciphers/import and ciphers/import-organization into new ImportController
Paths have been kept intact for now (no changes on clients needed)
Moved request-models used for import into tools-subfolder

* Update CODEOWNERS for team-tools-dev

* Move HibpController (reports) to tools

* Moving files related to Send

* Moving files related to ReferenceEvent

* Removed unneeded newline
2023-04-18 14:05:17 +02:00

59 lines
2.0 KiB
C#

using System.Text.Json;
using Bit.Api.Tools.Models;
using Bit.Api.Tools.Models.Request;
using Bit.Core.Tools.Enums;
using Bit.Core.Tools.Services;
using Bit.Test.Common.Helpers;
using NSubstitute;
using Xunit;
namespace Bit.Api.Test.Models.Request;
public class SendRequestModelTests
{
[Fact]
public void ToSend_Text_Success()
{
var deletionDate = DateTime.UtcNow.AddDays(5);
var sendRequest = new SendRequestModel
{
DeletionDate = deletionDate,
Disabled = false,
ExpirationDate = null,
HideEmail = false,
Key = "encrypted_key",
MaxAccessCount = null,
Name = "encrypted_name",
Notes = null,
Password = "Password",
Text = new SendTextModel()
{
Hidden = false,
Text = "encrypted_text"
},
Type = SendType.Text,
};
var sendService = Substitute.For<ISendService>();
sendService.HashPassword(Arg.Any<string>())
.Returns((info) => $"hashed_{(string)info[0]}");
var send = sendRequest.ToSend(Guid.NewGuid(), sendService);
Assert.Equal(deletionDate, send.DeletionDate);
Assert.False(send.Disabled);
Assert.Null(send.ExpirationDate);
Assert.False(send.HideEmail);
Assert.Equal("encrypted_key", send.Key);
Assert.Equal("hashed_Password", send.Password);
using var jsonDocument = JsonDocument.Parse(send.Data);
var root = jsonDocument.RootElement;
var text = AssertHelper.AssertJsonProperty(root, "Text", JsonValueKind.String).GetString();
Assert.Equal("encrypted_text", text);
AssertHelper.AssertJsonProperty(root, "Hidden", JsonValueKind.False);
Assert.False(root.TryGetProperty("Notes", out var _));
var name = AssertHelper.AssertJsonProperty(root, "Name", JsonValueKind.String).GetString();
Assert.Equal("encrypted_name", name);
}
}