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

[PS 2020] Fixing value cannot be null, parameter source (#2554)

* Fixing value cannot be null, parameter source

* Running the dotnet format -v diag
This commit is contained in:
cyprain-okeke
2023-01-09 14:51:34 +01:00
committed by GitHub
parent b1dfbe7519
commit e7958609b6
2 changed files with 64 additions and 1 deletions

View File

@ -214,6 +214,7 @@ public class OrganizationConnectionsControllerTests
updated.Type = OrganizationConnectionType.CloudBillingSync;
var model = RequestModelFromEntity<BillingSyncConfig>(updated);
sutProvider.GetDependency<IGlobalSettings>().SelfHosted.Returns(true);
sutProvider.GetDependency<ICurrentContext>().OrganizationOwner(model.OrganizationId).Returns(true);
sutProvider.GetDependency<IOrganizationConnectionRepository>()
.GetByOrganizationIdTypeAsync(model.OrganizationId, model.Type)
@ -225,6 +226,23 @@ public class OrganizationConnectionsControllerTests
.GetByIdAsync(existing.Id)
.Returns(existing);
OrganizationLicense organizationLicense = new OrganizationLicense();
var now = DateTime.UtcNow;
organizationLicense.Issued = now.AddDays(-10);
organizationLicense.Expires = now.AddDays(10);
organizationLicense.Version = 1;
organizationLicense.UsersGetPremium = true;
organizationLicense.Id = config.CloudOrganizationId;
organizationLicense.Trial = true;
sutProvider.GetDependency<ILicensingService>()
.ReadOrganizationLicenseAsync(Arg.Any<Guid>())
.Returns(organizationLicense);
sutProvider.GetDependency<ILicensingService>()
.VerifyLicense(organizationLicense)
.Returns(true);
var expected = new OrganizationConnectionResponseModel(updated, typeof(BillingSyncConfig));
var result = await sutProvider.Sut.UpdateConnection(existing.Id, model);
@ -233,6 +251,51 @@ public class OrganizationConnectionsControllerTests
.UpdateAsync(Arg.Is(AssertHelper.AssertPropertyEqual(model.ToData(updated.Id))));
}
[Theory]
[BitAutoData]
public async Task UpdateConnection_BillingSyncType_InvalidLicense_ErrorThrows(OrganizationConnection existing, BillingSyncConfig config,
OrganizationConnection updated,
SutProvider<OrganizationConnectionsController> sutProvider)
{
existing.SetConfig(new BillingSyncConfig
{
CloudOrganizationId = config.CloudOrganizationId,
});
updated.Config = JsonSerializer.Serialize(config);
updated.Id = existing.Id;
updated.Type = OrganizationConnectionType.CloudBillingSync;
var model = RequestModelFromEntity<BillingSyncConfig>(updated);
sutProvider.GetDependency<IGlobalSettings>().SelfHosted.Returns(true);
sutProvider.GetDependency<ICurrentContext>().OrganizationOwner(model.OrganizationId).Returns(true);
sutProvider.GetDependency<IOrganizationConnectionRepository>()
.GetByOrganizationIdTypeAsync(model.OrganizationId, model.Type)
.Returns(new[] { existing });
sutProvider.GetDependency<IUpdateOrganizationConnectionCommand>()
.UpdateAsync<BillingSyncConfig>(default)
.ReturnsForAnyArgs(updated);
sutProvider.GetDependency<IOrganizationConnectionRepository>()
.GetByIdAsync(existing.Id)
.Returns(existing);
OrganizationLicense organizationLicense = new OrganizationLicense();
var now = DateTime.UtcNow;
organizationLicense.Issued = now.AddDays(-10);
organizationLicense.Expires = now.AddDays(10);
organizationLicense.Version = 1;
organizationLicense.UsersGetPremium = true;
organizationLicense.Id = config.CloudOrganizationId;
organizationLicense.Trial = true;
sutProvider.GetDependency<ILicensingService>()
.VerifyLicense(organizationLicense)
.Returns(false);
var exception = await Assert.ThrowsAsync<BadRequestException>(async () => await sutProvider.Sut.UpdateConnection(existing.Id, model));
Assert.Contains("Cannot verify license file.", exception.Message);
}
[Theory]
[BitAutoData]
public async Task UpdateConnection_DoesNotExist_ThrowsNotFound(SutProvider<OrganizationConnectionsController> sutProvider)