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

Merge branch 'brant/add-dapper-repository-organization-integrations' into brant/PM-17562-Slack-Event-Posting

This commit is contained in:
Brant DeBow 2025-03-31 08:18:20 -04:00
commit 3803139ddb
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 get
{ {
var configJson = JsonNode.Parse(Configuration ?? string.Empty) as JsonObject ?? new JsonObject(); var integrationJson = IntegrationConfigurationJson;
var integrationJson = JsonNode.Parse(IntegrationConfiguration ?? string.Empty) as JsonObject ?? new JsonObject();
foreach (var kvp in configJson) foreach (var kvp in ConfigurationJson)
{ {
integrationJson[kvp.Key] = kvp.Value; integrationJson[kvp.Key] = kvp.Value?.DeepClone();
} }
return integrationJson; 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());
}
}