mirror of
https://github.com/bitwarden/android.git
synced 2024-11-01 07:35:52 +03:00
8d5614cd7b
* Expand Hkdf crypto functions * Add tests for hkdf crypto functions Took the testing infrastructure from bitwarden/server * Move Hkdf to cryptoFunctionService * Port changes from bitwarden/jslib#192 * Port changes from bitwarden/jslib#205 * Make Send Expiration Optional implement changes from bitwarden/jslib#242 * Bug fixes found by testing * Test helpers * Test conversion between model types * Test SendService These are mostly happy-path tests to ensure a reasonably correct implementation * Add run tests step to GitHub Actions * Test send decryption * Test Request generation from Send * Constructor dependencies on separate lines * Remove unused testing infrastructure * Rename to match class name * Move fat arrows to previous lines * Handle exceptions in App layer * PR review cleanups * Throw when attempting to save an unkown Send Type I think it's best to only throw on unknown send types here. I don't think we want to throw whenever we encounter one since that would do bad things like lock up Sync if clients get out of date relative to servers. Instead, keep the client from ruining saved data by complaining last minute that it doesn't know what it's doing.
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using System;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Models.Domain;
|
|
using Bit.Core.Models.Request;
|
|
using Bit.Core.Test.AutoFixture;
|
|
using Bit.Core.Utilities;
|
|
using Bit.Test.Common;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.Models.Request
|
|
{
|
|
public class SendRequestTests
|
|
{
|
|
[Theory]
|
|
[InlineCustomAutoData(new[] { typeof(TextSendCustomization) })]
|
|
[InlineCustomAutoData(new[] { typeof(FileSendCustomization) })]
|
|
public void SendRequest_FromSend_Success(Send send)
|
|
{
|
|
var request = new SendRequest(send);
|
|
|
|
TestHelper.AssertPropertyEqual(send, request, "Id", "AccessId", "UserId", "Name", "Notes", "File", "Text", "Key", "AccessCount", "RevisionDate");
|
|
Assert.Equal(send.Name?.EncryptedString, request.Name);
|
|
Assert.Equal(send.Notes?.EncryptedString, request.Notes);
|
|
|
|
switch (send.Type)
|
|
{
|
|
case SendType.File:
|
|
// Only sets filename
|
|
Assert.Equal(send.File.FileName?.EncryptedString, request.File.FileName);
|
|
break;
|
|
case SendType.Text:
|
|
TestHelper.AssertPropertyEqual(send.Text, request?.Text, "Text");
|
|
Assert.Equal(send.Text.Text?.EncryptedString, request.Text.Text);
|
|
break;
|
|
default:
|
|
throw new Exception("Untested Send type");
|
|
}
|
|
|
|
ServiceContainer.Reset();
|
|
}
|
|
}
|
|
}
|