1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-04 20:50:21 -05:00

[PM-17562] Add Dapper Repositories For Ogranization Integrations and Configurations

This commit is contained in:
Brant DeBow 2025-03-31 08:17:48 -04:00
parent e8d608a1c0
commit 4018487acf
No known key found for this signature in database
GPG Key ID: 94411BB25947C72B
2 changed files with 117 additions and 4 deletions

View File

@ -19,15 +19,46 @@ public class OrganizationIntegrationConfigurationDetails
{
get
{
var configJson = JsonNode.Parse(Configuration ?? string.Empty) as JsonObject ?? new JsonObject();
var integrationJson = JsonNode.Parse(IntegrationConfiguration ?? string.Empty) as JsonObject ?? new JsonObject();
var integrationJson = IntegrationConfigurationJson;
foreach (var kvp in configJson)
foreach (var kvp in ConfigurationJson)
{
integrationJson[kvp.Key] = kvp.Value;
integrationJson[kvp.Key] = kvp.Value?.DeepClone();
}
return integrationJson;
}
}
private JsonObject ConfigurationJson
{
get
{
try
{
var configuration = Configuration ?? "{}";
return JsonNode.Parse(configuration) as JsonObject ?? new JsonObject();
}
catch
{
return new JsonObject();
}
}
}
private JsonObject IntegrationConfigurationJson
{
get
{
try
{
var integration = IntegrationConfiguration ?? "{}";
return JsonNode.Parse(integration) as JsonObject ?? new JsonObject();
}
catch
{
return new JsonObject();
}
}
}
}

View File

@ -0,0 +1,82 @@
using System.Text.Json;
using Bit.Core.Models.Data.Organizations;
using Xunit;
namespace Bit.Core.Test.Models.Data.Organizations;
public class OrganizationIntegrationConfigurationDetailsTests
{
[Fact]
public void MergedConfiguration_BothHaveValues()
{
var config = new { config = "A new config value" };
var integration = new { integration = "An integration value" };
var expectedObj = new { integration = "An integration value", config = "A new config value" };
var expected = JsonSerializer.Serialize(expectedObj);
var sut = new OrganizationIntegrationConfigurationDetails();
sut.Configuration = JsonSerializer.Serialize(config);
sut.IntegrationConfiguration = JsonSerializer.Serialize(integration);
var result = sut.MergedConfiguration;
Assert.Equal(expected, result.ToJsonString());
}
[Fact]
public void MergedConfiguration_BothNotJson()
{
var expectedObj = new { };
var expected = JsonSerializer.Serialize(expectedObj);
var sut = new OrganizationIntegrationConfigurationDetails();
sut.Configuration = "Not JSON";
sut.IntegrationConfiguration = "Not JSON";
var result = sut.MergedConfiguration;
Assert.Equal(expected, result.ToJsonString());
}
[Fact]
public void MergedConfiguration_BothNull()
{
var expectedObj = new { };
var expected = JsonSerializer.Serialize(expectedObj);
var sut = new OrganizationIntegrationConfigurationDetails();
sut.Configuration = null;
sut.IntegrationConfiguration = null;
var result = sut.MergedConfiguration;
Assert.Equal(expected, result.ToJsonString());
}
[Fact]
public void MergedConfiguration_ConfigNull()
{
var integration = new { integration = "An integration value" };
var expectedObj = new { integration = "An integration value" };
var expected = JsonSerializer.Serialize(expectedObj);
var sut = new OrganizationIntegrationConfigurationDetails();
sut.Configuration = null;
sut.IntegrationConfiguration = JsonSerializer.Serialize(integration);
var result = sut.MergedConfiguration;
Assert.Equal(expected, result.ToJsonString());
}
[Fact]
public void MergedConfiguration_IntegrationNull()
{
var config = new { config = "A new config value" };
var expectedObj = new { config = "A new config value" };
var expected = JsonSerializer.Serialize(expectedObj);
var sut = new OrganizationIntegrationConfigurationDetails();
sut.Configuration = JsonSerializer.Serialize(config);
sut.IntegrationConfiguration = null;
var result = sut.MergedConfiguration;
Assert.Equal(expected, result.ToJsonString());
}
}