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

[AC-1200] Admin Console code ownership - move OrganizationFeatures (#3369)

This commit is contained in:
Thomas Rittson
2023-10-27 07:47:44 +10:00
committed by GitHub
parent 26dd8b0e47
commit ad230fb6a5
66 changed files with 151 additions and 152 deletions

View File

@ -0,0 +1,26 @@
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationApiKeys;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationApiKeys;
[SutProviderCustomize]
public class CreateOrganizationApiKeyCommandTest
{
[Theory]
[BitAutoData]
public async Task CreateAsync_CreatesOrganizationApiKey(SutProvider<CreateOrganizationApiKeyCommand> sutProvider,
Guid organizationId, OrganizationApiKeyType keyType)
{
await sutProvider.Sut.CreateAsync(organizationId, keyType);
await sutProvider.GetDependency<IOrganizationApiKeyRepository>().Received(1)
.CreateAsync(Arg.Is<OrganizationApiKey>(o => o.OrganizationId == organizationId
&& o.Type == keyType));
}
}

View File

@ -0,0 +1,80 @@
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationApiKeys;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationApiKeys;
[SutProviderCustomize]
public class GetOrganizationApiKeyQueryTests
{
[Theory]
[BitAutoData]
public async Task GetOrganizationApiKey_HasOne_Returns(SutProvider<GetOrganizationApiKeyQuery> sutProvider,
Guid id, Guid organizationId, OrganizationApiKeyType keyType)
{
sutProvider.GetDependency<IOrganizationApiKeyRepository>()
.GetManyByOrganizationIdTypeAsync(organizationId, keyType)
.Returns(new List<OrganizationApiKey>
{
new OrganizationApiKey
{
Id = id,
OrganizationId = organizationId,
ApiKey = "test",
Type = keyType,
RevisionDate = DateTime.Now.AddDays(-1),
},
});
var apiKey = await sutProvider.Sut.GetOrganizationApiKeyAsync(organizationId, keyType);
Assert.NotNull(apiKey);
Assert.Equal(id, apiKey.Id);
}
[Theory]
[BitAutoData]
public async Task GetOrganizationApiKey_HasTwo_Throws(SutProvider<GetOrganizationApiKeyQuery> sutProvider,
Guid organizationId, OrganizationApiKeyType keyType)
{
sutProvider.GetDependency<IOrganizationApiKeyRepository>()
.GetManyByOrganizationIdTypeAsync(organizationId, keyType)
.Returns(new List<OrganizationApiKey>
{
new OrganizationApiKey
{
Id = Guid.NewGuid(),
OrganizationId = organizationId,
ApiKey = "test",
Type = keyType,
RevisionDate = DateTime.Now.AddDays(-1),
},
new OrganizationApiKey
{
Id = Guid.NewGuid(),
OrganizationId = organizationId,
ApiKey = "test_other",
Type = keyType,
RevisionDate = DateTime.Now.AddDays(-1),
},
});
await Assert.ThrowsAsync<InvalidOperationException>(
async () => await sutProvider.Sut.GetOrganizationApiKeyAsync(organizationId, keyType));
}
[Theory]
[BitAutoData]
public async Task GetOrganizationApiKey_BadType_Throws(SutProvider<GetOrganizationApiKeyQuery> sutProvider,
Guid organizationId, OrganizationApiKeyType keyType)
{
keyType = (OrganizationApiKeyType)byte.MaxValue;
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(
async () => await sutProvider.Sut.GetOrganizationApiKeyAsync(organizationId, keyType));
}
}

View File

@ -0,0 +1,22 @@
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationApiKeys;
using Bit.Core.Entities;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using Bit.Test.Common.Helpers;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationApiKeys;
[SutProviderCustomize]
public class RotateOrganizationApiKeyCommandTests
{
[Theory, BitAutoData]
public async Task RotateApiKeyAsync_RotatesKey(SutProvider<RotateOrganizationApiKeyCommand> sutProvider,
OrganizationApiKey organizationApiKey)
{
var existingKey = organizationApiKey.ApiKey;
organizationApiKey = await sutProvider.Sut.RotateApiKeyAsync(organizationApiKey);
Assert.NotEqual(existingKey, organizationApiKey.ApiKey);
AssertHelper.AssertRecent(organizationApiKey.RevisionDate);
}
}