mirror of
https://github.com/bitwarden/mobile
synced 2025-12-15 07:43:37 +00:00
Send file model changes (#1293)
* Remove Url from SendFile. Add file length hit to SendRequest * Populate SendRequest file length
This commit is contained in:
@@ -3,7 +3,6 @@ namespace Bit.Core.Models.Api
|
|||||||
public class SendFileApi
|
public class SendFileApi
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Url { get; set; }
|
|
||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
public string Size { get; set; }
|
public string Size { get; set; }
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ namespace Bit.Core.Models.Data
|
|||||||
public SendFileData(SendFileApi data)
|
public SendFileData(SendFileApi data)
|
||||||
{
|
{
|
||||||
Id = data.Id;
|
Id = data.Id;
|
||||||
Url = data.Url;
|
|
||||||
FileName = data.FileName;
|
FileName = data.FileName;
|
||||||
Key = data.Key;
|
Key = data.Key;
|
||||||
Size = data.Size;
|
Size = data.Size;
|
||||||
@@ -18,7 +17,6 @@ namespace Bit.Core.Models.Data
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Url { get; set; }
|
|
||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
public string Size { get; set; }
|
public string Size { get; set; }
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ namespace Bit.Core.Models.Domain
|
|||||||
public class SendFile : Domain
|
public class SendFile : Domain
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Url { get; set; }
|
|
||||||
public string Size { get; set; }
|
public string Size { get; set; }
|
||||||
public string SizeName { get; set; }
|
public string SizeName { get; set; }
|
||||||
public CipherString FileName { get; set; }
|
public CipherString FileName { get; set; }
|
||||||
@@ -18,7 +17,7 @@ namespace Bit.Core.Models.Domain
|
|||||||
public SendFile(SendFileData file, bool alreadyEncrypted = false) : base()
|
public SendFile(SendFileData file, bool alreadyEncrypted = false) : base()
|
||||||
{
|
{
|
||||||
Size = file.Size;
|
Size = file.Size;
|
||||||
BuildDomainModel(this, file, new HashSet<string> { "Id", "Url", "SizeName", "FileName" }, alreadyEncrypted, new HashSet<string> { "Id", "Url", "SizeName" });
|
BuildDomainModel(this, file, new HashSet<string> { "Id", "SizeName", "FileName" }, alreadyEncrypted, new HashSet<string> { "Id", "SizeName" });
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<SendFileView> DecryptAsync(SymmetricCryptoKey key) =>
|
public Task<SendFileView> DecryptAsync(SymmetricCryptoKey key) =>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Bit.Core.Models.Request
|
|||||||
public class SendRequest
|
public class SendRequest
|
||||||
{
|
{
|
||||||
public SendType Type { get; set; }
|
public SendType Type { get; set; }
|
||||||
|
public long? FileLength { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
@@ -19,9 +20,10 @@ namespace Bit.Core.Models.Request
|
|||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public bool Disabled { get; set; }
|
public bool Disabled { get; set; }
|
||||||
|
|
||||||
public SendRequest(Send send)
|
public SendRequest(Send send, long? fileLength)
|
||||||
{
|
{
|
||||||
Type = send.Type;
|
Type = send.Type ;
|
||||||
|
FileLength = fileLength;
|
||||||
Name = send.Name?.EncryptedString;
|
Name = send.Name?.EncryptedString;
|
||||||
Notes = send.Notes?.EncryptedString;
|
Notes = send.Notes?.EncryptedString;
|
||||||
MaxAccessCount = send.MaxAccessCount;
|
MaxAccessCount = send.MaxAccessCount;
|
||||||
|
|||||||
@@ -10,13 +10,11 @@ namespace Bit.Core.Models.View
|
|||||||
public SendFileView(SendFile file)
|
public SendFileView(SendFile file)
|
||||||
{
|
{
|
||||||
Id = file.Id;
|
Id = file.Id;
|
||||||
Url = file.Url;
|
|
||||||
Size = file.Size;
|
Size = file.Size;
|
||||||
SizeName = file.SizeName;
|
SizeName = file.SizeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Url { get; set; }
|
|
||||||
public string Size { get; set; }
|
public string Size { get; set; }
|
||||||
public string SizeName { get; set; }
|
public string SizeName { get; set; }
|
||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
public async Task<string> SaveWithServerAsync(Send send, byte[] encryptedFileData)
|
public async Task<string> SaveWithServerAsync(Send send, byte[] encryptedFileData)
|
||||||
{
|
{
|
||||||
var request = new SendRequest(send);
|
var request = new SendRequest(send, encryptedFileData?.LongLength);
|
||||||
SendResponse response;
|
SendResponse response;
|
||||||
if (send.Id == null)
|
if (send.Id == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,15 +13,16 @@ namespace Bit.Core.Test.Models.Request
|
|||||||
public class SendRequestTests
|
public class SendRequestTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineCustomAutoData(new[] { typeof(TextSendCustomization) })]
|
[InlineCustomAutoData(new[] { typeof(TextSendCustomization) }, null)]
|
||||||
[InlineCustomAutoData(new[] { typeof(FileSendCustomization) })]
|
[InlineCustomAutoData(new[] { typeof(FileSendCustomization) }, 100)]
|
||||||
public void SendRequest_FromSend_Success(Send send)
|
public void SendRequest_FromSend_Success(long? fileLength, Send send)
|
||||||
{
|
{
|
||||||
var request = new SendRequest(send);
|
var request = new SendRequest(send, fileLength);
|
||||||
|
|
||||||
TestHelper.AssertPropertyEqual(send, request, "Id", "AccessId", "UserId", "Name", "Notes", "File", "Text", "Key", "AccessCount", "RevisionDate");
|
TestHelper.AssertPropertyEqual(send, request, "Id", "AccessId", "UserId", "Name", "Notes", "File", "Text", "Key", "AccessCount", "RevisionDate");
|
||||||
Assert.Equal(send.Name?.EncryptedString, request.Name);
|
Assert.Equal(send.Name?.EncryptedString, request.Name);
|
||||||
Assert.Equal(send.Notes?.EncryptedString, request.Notes);
|
Assert.Equal(send.Notes?.EncryptedString, request.Notes);
|
||||||
|
Assert.Equal(fileLength, request.FileLength);
|
||||||
|
|
||||||
switch (send.Type)
|
switch (send.Type)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ namespace Bit.Core.Test.Services
|
|||||||
Predicate<SendRequest> sendRequestPredicate = r =>
|
Predicate<SendRequest> sendRequestPredicate = r =>
|
||||||
{
|
{
|
||||||
// Note Send -> SendRequest tested in SendRequestTests
|
// Note Send -> SendRequest tested in SendRequestTests
|
||||||
TestHelper.AssertPropertyEqual(new SendRequest(send), r);
|
TestHelper.AssertPropertyEqual(new SendRequest(send, fileContentBytes?.LongLength), r);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ namespace Bit.Core.Test.Services
|
|||||||
{
|
{
|
||||||
Assert.Equal(2, fd.Count()); // expect a request and file content
|
Assert.Equal(2, fd.Count()); // expect a request and file content
|
||||||
|
|
||||||
var expectedRequest = JsonConvert.SerializeObject(new SendRequest(send));
|
var expectedRequest = JsonConvert.SerializeObject(new SendRequest(send, fileContentBytes?.LongLength));
|
||||||
var actualRequest = fd.First().ReadAsStringAsync().GetAwaiter().GetResult();
|
var actualRequest = fd.First().ReadAsStringAsync().GetAwaiter().GetResult();
|
||||||
Assert.Equal(expectedRequest, actualRequest);
|
Assert.Equal(expectedRequest, actualRequest);
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ namespace Bit.Core.Test.Services
|
|||||||
Predicate<SendRequest> sendRequestPredicate = r =>
|
Predicate<SendRequest> sendRequestPredicate = r =>
|
||||||
{
|
{
|
||||||
// Note Send -> SendRequest tested in SendRequestTests
|
// Note Send -> SendRequest tested in SendRequestTests
|
||||||
TestHelper.AssertPropertyEqual(new SendRequest(send), r);
|
TestHelper.AssertPropertyEqual(new SendRequest(send, null), r);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user