Browse Source
* Add access to secret count to service account list * dotnet format * refactor into query * Remove duplicate * Add new method to nooppull/3154/head
11 changed files with 192 additions and 17 deletions
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
using Bit.Core.Enums; |
||||
using Bit.Core.SecretsManager.Models.Data; |
||||
using Bit.Core.SecretsManager.Queries.ServiceAccounts.Interfaces; |
||||
using Bit.Core.SecretsManager.Repositories; |
||||
|
||||
namespace Bit.Commercial.Core.SecretsManager.Queries.ServiceAccounts; |
||||
|
||||
public class ServiceAccountSecretsDetailsQuery : IServiceAccountSecretsDetailsQuery |
||||
{ |
||||
private readonly IServiceAccountRepository _serviceAccountRepository; |
||||
|
||||
public ServiceAccountSecretsDetailsQuery(IServiceAccountRepository serviceAccountRepository) |
||||
{ |
||||
_serviceAccountRepository = serviceAccountRepository; |
||||
} |
||||
|
||||
public async Task<IEnumerable<ServiceAccountSecretsDetails>> GetManyByOrganizationIdAsync( |
||||
Guid organizationId, Guid userId, AccessClientType accessClient, bool includeAccessToSecrets) |
||||
{ |
||||
if (includeAccessToSecrets) |
||||
{ |
||||
return await _serviceAccountRepository.GetManyByOrganizationIdWithSecretsDetailsAsync(organizationId, |
||||
userId, |
||||
accessClient); |
||||
} |
||||
|
||||
var serviceAccounts = |
||||
await _serviceAccountRepository.GetManyByOrganizationIdAsync(organizationId, userId, accessClient); |
||||
|
||||
return serviceAccounts.Select(sa => new ServiceAccountSecretsDetails |
||||
{ |
||||
ServiceAccount = sa, |
||||
AccessToSecrets = 0, |
||||
}); |
||||
} |
||||
} |
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
using Bit.Commercial.Core.SecretsManager.Queries.ServiceAccounts; |
||||
using Bit.Core.Enums; |
||||
using Bit.Core.SecretsManager.Entities; |
||||
using Bit.Core.SecretsManager.Models.Data; |
||||
using Bit.Core.SecretsManager.Repositories; |
||||
using Bit.Test.Common.AutoFixture; |
||||
using Bit.Test.Common.AutoFixture.Attributes; |
||||
using Bit.Test.Common.Helpers; |
||||
using NSubstitute; |
||||
using Xunit; |
||||
|
||||
namespace Bit.Commercial.Core.Test.SecretsManager.Queries.ServiceAccounts; |
||||
|
||||
[SutProviderCustomize] |
||||
public class ServiceAccountSecretsDetailsQueryTests |
||||
{ |
||||
[Theory] |
||||
[BitAutoData(false)] |
||||
[BitAutoData(true)] |
||||
public async Task GetManyByOrganizationId_CallsDifferentRepoMethods( |
||||
bool includeAccessToSecrets, |
||||
SutProvider<ServiceAccountSecretsDetailsQuery> sutProvider, |
||||
Guid organizationId, |
||||
Guid userId, |
||||
AccessClientType accessClient, |
||||
ServiceAccount mockSa, |
||||
ServiceAccountSecretsDetails mockSaDetails) |
||||
{ |
||||
sutProvider.GetDependency<IServiceAccountRepository>().GetManyByOrganizationIdAsync(default, default, default) |
||||
.ReturnsForAnyArgs(new List<ServiceAccount> { mockSa }); |
||||
|
||||
sutProvider.GetDependency<IServiceAccountRepository>().GetManyByOrganizationIdWithSecretsDetailsAsync(default, default, default) |
||||
.ReturnsForAnyArgs(new List<ServiceAccountSecretsDetails> { mockSaDetails }); |
||||
|
||||
|
||||
var result = await sutProvider.Sut.GetManyByOrganizationIdAsync(organizationId, userId, accessClient, includeAccessToSecrets); |
||||
|
||||
if (includeAccessToSecrets) |
||||
{ |
||||
await sutProvider.GetDependency<IServiceAccountRepository>().Received(1) |
||||
.GetManyByOrganizationIdWithSecretsDetailsAsync(Arg.Is(AssertHelper.AssertPropertyEqual(mockSaDetails.ServiceAccount.OrganizationId)), |
||||
Arg.Any<Guid>(), Arg.Any<AccessClientType>()); |
||||
} |
||||
else |
||||
{ |
||||
await sutProvider.GetDependency<IServiceAccountRepository>().Received(1) |
||||
.GetManyByOrganizationIdAsync(Arg.Is(AssertHelper.AssertPropertyEqual(mockSa.OrganizationId)), |
||||
Arg.Any<Guid>(), Arg.Any<AccessClientType>()); |
||||
Assert.Equal(0, result.First().AccessToSecrets); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
using Bit.Core.SecretsManager.Entities; |
||||
|
||||
namespace Bit.Core.SecretsManager.Models.Data; |
||||
|
||||
public class ServiceAccountSecretsDetails |
||||
{ |
||||
public ServiceAccount ServiceAccount { get; set; } |
||||
public int AccessToSecrets { get; set; } |
||||
} |
||||
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
using Bit.Core.Enums; |
||||
using Bit.Core.SecretsManager.Models.Data; |
||||
|
||||
namespace Bit.Core.SecretsManager.Queries.ServiceAccounts.Interfaces; |
||||
|
||||
public interface IServiceAccountSecretsDetailsQuery |
||||
{ |
||||
public Task<IEnumerable<ServiceAccountSecretsDetails>> GetManyByOrganizationIdAsync( |
||||
Guid organizationId, Guid userId, AccessClientType accessClient, bool includeAccessToSecrets); |
||||
} |
||||
Loading…
Reference in new issue