1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

Revert filescoped (#2227)

* Revert "Add git blame entry (#2226)"

This reverts commit 239286737d.

* Revert "Turn on file scoped namespaces (#2225)"

This reverts commit 34fb4cca2a.
This commit is contained in:
Justin Baur
2022-08-29 15:53:48 -04:00
committed by GitHub
parent 239286737d
commit bae03feffe
1208 changed files with 74317 additions and 73126 deletions

View File

@ -3,62 +3,63 @@ using Bit.Core.Settings;
using Microsoft.AspNetCore.Http;
using Xunit;
namespace Bit.Api.Test.Models.Request.Accounts;
public class PremiumRequestModelTests
namespace Bit.Api.Test.Models.Request.Accounts
{
public static IEnumerable<object[]> GetValidateData()
public class PremiumRequestModelTests
{
// 1. selfHosted
// 2. formFile
// 3. country
// 4. expected
public static IEnumerable<object[]> GetValidateData()
{
// 1. selfHosted
// 2. formFile
// 3. country
// 4. expected
yield return new object[] { true, null, null, false };
yield return new object[] { true, null, "US", false };
yield return new object[] { true, new NotImplementedFormFile(), null, false };
yield return new object[] { true, new NotImplementedFormFile(), "US", false };
yield return new object[] { true, null, null, false };
yield return new object[] { true, null, "US", false };
yield return new object[] { true, new NotImplementedFormFile(), null, false };
yield return new object[] { true, new NotImplementedFormFile(), "US", false };
yield return new object[] { false, null, null, false };
yield return new object[] { false, null, "US", true }; // Only true, cloud with null license AND a Country
yield return new object[] { false, new NotImplementedFormFile(), null, false };
yield return new object[] { false, new NotImplementedFormFile(), "US", false };
yield return new object[] { false, null, null, false };
yield return new object[] { false, null, "US", true }; // Only true, cloud with null license AND a Country
yield return new object[] { false, new NotImplementedFormFile(), null, false };
yield return new object[] { false, new NotImplementedFormFile(), "US", false };
}
[Theory]
[MemberData(nameof(GetValidateData))]
public void Validate_Success(bool selfHosted, IFormFile formFile, string country, bool expected)
{
var gs = new GlobalSettings
{
SelfHosted = selfHosted
};
var sut = new PremiumRequestModel
{
License = formFile,
Country = country,
};
Assert.Equal(expected, sut.Validate(gs));
}
}
[Theory]
[MemberData(nameof(GetValidateData))]
public void Validate_Success(bool selfHosted, IFormFile formFile, string country, bool expected)
public class NotImplementedFormFile : IFormFile
{
var gs = new GlobalSettings
{
SelfHosted = selfHosted
};
public string ContentType => throw new NotImplementedException();
var sut = new PremiumRequestModel
{
License = formFile,
Country = country,
};
public string ContentDisposition => throw new NotImplementedException();
Assert.Equal(expected, sut.Validate(gs));
public IHeaderDictionary Headers => throw new NotImplementedException();
public long Length => throw new NotImplementedException();
public string Name => throw new NotImplementedException();
public string FileName => throw new NotImplementedException();
public void CopyTo(Stream target) => throw new NotImplementedException();
public Task CopyToAsync(Stream target, CancellationToken cancellationToken = default) => throw new NotImplementedException();
public Stream OpenReadStream() => throw new NotImplementedException();
}
}
public class NotImplementedFormFile : IFormFile
{
public string ContentType => throw new NotImplementedException();
public string ContentDisposition => throw new NotImplementedException();
public IHeaderDictionary Headers => throw new NotImplementedException();
public long Length => throw new NotImplementedException();
public string Name => throw new NotImplementedException();
public string FileName => throw new NotImplementedException();
public void CopyTo(Stream target) => throw new NotImplementedException();
public Task CopyToAsync(Stream target, CancellationToken cancellationToken = default) => throw new NotImplementedException();
public Stream OpenReadStream() => throw new NotImplementedException();
}

View File

@ -7,53 +7,54 @@ using Bit.Test.Common.Helpers;
using NSubstitute;
using Xunit;
namespace Bit.Api.Test.Models.Request;
public class SendRequestModelTests
namespace Bit.Api.Test.Models.Request
{
[Fact]
public void ToSend_Text_Success()
public class SendRequestModelTests
{
var deletionDate = DateTime.UtcNow.AddDays(5);
var sendRequest = new SendRequestModel
[Fact]
public void ToSend_Text_Success()
{
DeletionDate = deletionDate,
Disabled = false,
ExpirationDate = null,
HideEmail = false,
Key = "encrypted_key",
MaxAccessCount = null,
Name = "encrypted_name",
Notes = null,
Password = "Password",
Text = new SendTextModel()
var deletionDate = DateTime.UtcNow.AddDays(5);
var sendRequest = new SendRequestModel
{
Hidden = false,
Text = "encrypted_text"
},
Type = SendType.Text,
};
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 sendService = Substitute.For<ISendService>();
sendService.HashPassword(Arg.Any<string>())
.Returns((info) => $"hashed_{(string)info[0]}");
var send = sendRequest.ToSend(Guid.NewGuid(), sendService);
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);
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);
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);
}
}
}