1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-05 14:23:30 +01:00
bitwarden-server/test/Core.Test/Entities/OrganizationConnectionTests.cs
Vincent Salucci 9a1a369472
[AC-1201] refactor: move all SCIM related files into the AdminConsole scope (#2841)
Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
2023-04-19 09:31:00 +10:00

79 lines
2.5 KiB
C#

using Bit.Core.AdminConsole.Models.OrganizationConnectionConfigs;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Test.Common.AutoFixture.Attributes;
using Xunit;
namespace Bit.Core.Test.Entities;
public class OrganizationConnectionTests
{
[Theory]
[BitAutoData]
public void OrganizationConnection_CanUse_Success(Guid connectionId, Guid organizationId)
{
var connection = new OrganizationConnection<ScimConfig>()
{
Id = connectionId,
OrganizationId = organizationId,
Enabled = true,
Type = OrganizationConnectionType.Scim,
Config = new ScimConfig() { Enabled = true }
};
Assert.True(connection.Validate<ScimConfig>(out var exception));
Assert.True(string.IsNullOrEmpty(exception));
}
[Theory]
[BitAutoData]
public void OrganizationConnection_CanUse_WhenDisabled_ReturnsFalse(Guid connectionId, Guid organizationId)
{
var connection = new OrganizationConnection<ScimConfig>()
{
Id = connectionId,
OrganizationId = organizationId,
Enabled = false,
Type = OrganizationConnectionType.Scim,
Config = new ScimConfig() { Enabled = true }
};
Assert.False(connection.Validate<ScimConfig>(out var exception));
Assert.Contains("Connection disabled", exception);
}
[Theory]
[BitAutoData]
public void OrganizationConnection_CanUse_WhenNoConfig_ReturnsFalse(Guid connectionId, Guid organizationId)
{
var connection = new OrganizationConnection<ScimConfig>()
{
Id = connectionId,
OrganizationId = organizationId,
Enabled = true,
Type = OrganizationConnectionType.Scim,
};
Assert.False(connection.Validate<ScimConfig>(out var exception));
Assert.Contains("No saved Connection config", exception);
}
[Theory]
[BitAutoData]
public void OrganizationConnection_CanUse_WhenConfigInvalid_ReturnsFalse(Guid connectionId, Guid organizationId)
{
var connection = new OrganizationConnection<ScimConfig>()
{
Id = connectionId,
OrganizationId = organizationId,
Enabled = true,
Type = OrganizationConnectionType.Scim,
Config = new ScimConfig() { Enabled = false }
};
Assert.False(connection.Validate<ScimConfig>(out var exception));
Assert.Contains("Scim Config is disabled", exception);
}
}