mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -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:
parent
b1dfbe7519
commit
e7958609b6
@ -96,7 +96,7 @@ public class OrganizationConnectionsController : Controller
|
||||
switch (model.Type)
|
||||
{
|
||||
case OrganizationConnectionType.CloudBillingSync:
|
||||
return await CreateOrUpdateOrganizationConnectionAsync<BillingSyncConfig>(organizationConnectionId, model);
|
||||
return await CreateOrUpdateOrganizationConnectionAsync<BillingSyncConfig>(organizationConnectionId, model, ValidateBillingSyncConfig);
|
||||
case OrganizationConnectionType.Scim:
|
||||
return await CreateOrUpdateOrganizationConnectionAsync<ScimConfig>(organizationConnectionId, model);
|
||||
default:
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user