2023-02-06 18:26:06 +01:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http.Headers;
|
2023-01-20 00:31:19 +01:00
|
|
|
|
using Bit.Api.IntegrationTest.Factories;
|
2023-02-06 18:26:06 +01:00
|
|
|
|
using Bit.Api.IntegrationTest.SecretsManager.Enums;
|
|
|
|
|
using Bit.Api.Models.Response;
|
2023-01-24 19:57:28 +01:00
|
|
|
|
using Bit.Api.SecretsManager.Models.Request;
|
|
|
|
|
using Bit.Api.SecretsManager.Models.Response;
|
2023-02-06 18:26:06 +01:00
|
|
|
|
using Bit.Core.Enums;
|
2023-01-24 19:57:28 +01:00
|
|
|
|
using Bit.Core.SecretsManager.Entities;
|
|
|
|
|
using Bit.Core.SecretsManager.Repositories;
|
2023-01-20 00:31:19 +01:00
|
|
|
|
using Bit.Test.Common.Helpers;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2023-01-24 19:57:28 +01:00
|
|
|
|
namespace Bit.Api.IntegrationTest.SecretsManager.Controllers;
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
2023-03-22 16:04:50 +01:00
|
|
|
|
public class AccessPoliciesControllerTests : IClassFixture<ApiApplicationFactory>, IAsyncLifetime
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
private const string _mockEncryptedString =
|
|
|
|
|
"2.3Uk+WNBIoU5xzmVFNcoWzz==|1MsPIYuRfdOHfu/0uY6H2Q==|/98sp4wb6pHP1VTZ9JcNCYgQjEUMFPlqJgCwRk1YXKg=";
|
|
|
|
|
|
2023-01-20 00:31:19 +01:00
|
|
|
|
private readonly IAccessPolicyRepository _accessPolicyRepository;
|
|
|
|
|
|
|
|
|
|
private readonly HttpClient _client;
|
|
|
|
|
private readonly ApiApplicationFactory _factory;
|
|
|
|
|
private readonly IProjectRepository _projectRepository;
|
|
|
|
|
private readonly IServiceAccountRepository _serviceAccountRepository;
|
2023-02-06 18:26:06 +01:00
|
|
|
|
private string _email = null!;
|
|
|
|
|
private SecretsManagerOrganizationHelper _organizationHelper = null!;
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
2023-03-22 16:04:50 +01:00
|
|
|
|
public AccessPoliciesControllerTests(ApiApplicationFactory factory)
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
|
|
|
|
_factory = factory;
|
|
|
|
|
_client = _factory.CreateClient();
|
|
|
|
|
_accessPolicyRepository = _factory.GetService<IAccessPolicyRepository>();
|
|
|
|
|
_serviceAccountRepository = _factory.GetService<IServiceAccountRepository>();
|
|
|
|
|
_projectRepository = _factory.GetService<IProjectRepository>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task InitializeAsync()
|
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
_email = $"integration-test{Guid.NewGuid()}@bitwarden.com";
|
|
|
|
|
await _factory.LoginWithNewAccount(_email);
|
|
|
|
|
_organizationHelper = new SecretsManagerOrganizationHelper(_factory, _email);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task DisposeAsync()
|
|
|
|
|
{
|
|
|
|
|
_client.Dispose();
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoginAsync(string email)
|
|
|
|
|
{
|
|
|
|
|
var tokens = await _factory.LoginAsync(email);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task CreateProjectAccessPolicies_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var (projectId, serviceAccountId) = await CreateProjectAndServiceAccountAsync(org.Id);
|
2023-02-06 18:26:06 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var request = new AccessPoliciesCreateRequest
|
2023-02-06 18:26:06 +01:00
|
|
|
|
{
|
2023-07-13 18:46:01 +02:00
|
|
|
|
ServiceAccountAccessPolicyRequests = new List<AccessPolicyRequest>
|
|
|
|
|
{
|
|
|
|
|
new() { GranteeId = serviceAccountId, Read = true, Write = true },
|
|
|
|
|
},
|
|
|
|
|
};
|
2023-02-06 18:26:06 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var response = await _client.PostAsJsonAsync($"/projects/{projectId}/access-policies", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CreateProjectAccessPolicies_NoPermission()
|
|
|
|
|
{
|
|
|
|
|
// Create a new account as a user
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
var (projectId, serviceAccountId) = await CreateProjectAndServiceAccountAsync(org.Id);
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var request = new AccessPoliciesCreateRequest
|
|
|
|
|
{
|
|
|
|
|
ServiceAccountAccessPolicyRequests = new List<AccessPolicyRequest>
|
|
|
|
|
{
|
2023-07-13 18:46:01 +02:00
|
|
|
|
new() { GranteeId = serviceAccountId, Read = true, Write = true },
|
2023-02-06 18:26:06 +01:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var response = await _client.PostAsJsonAsync($"/projects/{projectId}/access-policies", request);
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
2023-07-13 18:46:01 +02:00
|
|
|
|
public async Task CreateProjectAccessPolicies_MismatchedOrgIds_NotFound(PermissionType permissionType)
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var (projectId, serviceAccountId) = await CreateProjectAndServiceAccountAsync(org.Id, true);
|
|
|
|
|
await SetupProjectAndServiceAccountPermissionAsync(permissionType, projectId, serviceAccountId);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var request = new AccessPoliciesCreateRequest
|
2023-02-06 18:26:06 +01:00
|
|
|
|
{
|
2023-07-13 18:46:01 +02:00
|
|
|
|
ServiceAccountAccessPolicyRequests = new List<AccessPolicyRequest>
|
2023-02-06 18:26:06 +01:00
|
|
|
|
{
|
2023-07-13 18:46:01 +02:00
|
|
|
|
new() { GranteeId = serviceAccountId, Read = true, Write = true },
|
|
|
|
|
},
|
|
|
|
|
};
|
2023-02-06 18:26:06 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
|
|
|
|
|
var response = await _client.PostAsJsonAsync($"/projects/{projectId}/access-policies", request);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task CreateProjectAccessPolicies_Success(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var (projectId, serviceAccountId) = await CreateProjectAndServiceAccountAsync(org.Id);
|
|
|
|
|
await SetupProjectAndServiceAccountPermissionAsync(permissionType, projectId, serviceAccountId);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
|
|
|
|
var request = new AccessPoliciesCreateRequest
|
|
|
|
|
{
|
|
|
|
|
ServiceAccountAccessPolicyRequests = new List<AccessPolicyRequest>
|
|
|
|
|
{
|
2023-07-13 18:46:01 +02:00
|
|
|
|
new() { GranteeId = serviceAccountId, Read = true, Write = true },
|
2023-02-06 18:26:06 +01:00
|
|
|
|
},
|
2023-01-20 00:31:19 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var response = await _client.PostAsJsonAsync($"/projects/{projectId}/access-policies", request);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ProjectAccessPoliciesResponseModel>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
2023-07-13 18:46:01 +02:00
|
|
|
|
Assert.Equal(serviceAccountId, result!.ServiceAccountAccessPolicies.First().ServiceAccountId);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
Assert.True(result.ServiceAccountAccessPolicies.First().Read);
|
|
|
|
|
Assert.True(result.ServiceAccountAccessPolicies.First().Write);
|
|
|
|
|
AssertHelper.AssertRecent(result.ServiceAccountAccessPolicies.First().RevisionDate);
|
|
|
|
|
AssertHelper.AssertRecent(result.ServiceAccountAccessPolicies.First().CreationDate);
|
|
|
|
|
|
|
|
|
|
var createdAccessPolicy =
|
|
|
|
|
await _accessPolicyRepository.GetByIdAsync(result.ServiceAccountAccessPolicies.First().Id);
|
|
|
|
|
Assert.NotNull(createdAccessPolicy);
|
|
|
|
|
Assert.Equal(result.ServiceAccountAccessPolicies.First().Read, createdAccessPolicy!.Read);
|
|
|
|
|
Assert.Equal(result.ServiceAccountAccessPolicies.First().Write, createdAccessPolicy.Write);
|
|
|
|
|
Assert.Equal(result.ServiceAccountAccessPolicies.First().Id, createdAccessPolicy.Id);
|
|
|
|
|
AssertHelper.AssertRecent(createdAccessPolicy.CreationDate);
|
|
|
|
|
AssertHelper.AssertRecent(createdAccessPolicy.RevisionDate);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task UpdateAccessPolicy_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
const bool expectedRead = true;
|
|
|
|
|
const bool expectedWrite = false;
|
|
|
|
|
var request = new AccessPolicyUpdateRequest { Read = expectedRead, Write = expectedWrite };
|
|
|
|
|
|
|
|
|
|
var response = await _client.PutAsJsonAsync($"/access-policies/{initData.AccessPolicyId}", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task UpdateAccessPolicy_NoPermission()
|
|
|
|
|
{
|
|
|
|
|
// Create a new account as a user
|
2023-02-16 16:47:34 +01:00
|
|
|
|
await _organizationHelper.Initialize(true, true);
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(orgUser.OrganizationId);
|
|
|
|
|
|
|
|
|
|
const bool expectedRead = true;
|
|
|
|
|
const bool expectedWrite = false;
|
|
|
|
|
var request = new AccessPolicyUpdateRequest { Read = expectedRead, Write = expectedWrite };
|
|
|
|
|
|
|
|
|
|
var response = await _client.PutAsJsonAsync($"/access-policies/{initData.AccessPolicyId}", request);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
2023-07-13 18:46:01 +02:00
|
|
|
|
public async Task UpdateAccessPolicy_Success(PermissionType permissionType)
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
var accessPolicies = new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserProjectAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedProjectId = initData.ProjectId, OrganizationUserId = orgUser.Id, Read = true, Write = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(accessPolicies);
|
|
|
|
|
}
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
|
|
|
|
const bool expectedRead = true;
|
|
|
|
|
const bool expectedWrite = false;
|
|
|
|
|
var request = new AccessPolicyUpdateRequest { Read = expectedRead, Write = expectedWrite };
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var response = await _client.PutAsJsonAsync($"/access-policies/{initData.AccessPolicyId}", request);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ServiceAccountProjectAccessPolicyResponseModel>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.Equal(expectedRead, result!.Read);
|
|
|
|
|
Assert.Equal(expectedWrite, result.Write);
|
|
|
|
|
AssertHelper.AssertRecent(result.RevisionDate);
|
|
|
|
|
|
|
|
|
|
var updatedAccessPolicy = await _accessPolicyRepository.GetByIdAsync(result.Id);
|
|
|
|
|
Assert.NotNull(updatedAccessPolicy);
|
|
|
|
|
Assert.Equal(expectedRead, updatedAccessPolicy!.Read);
|
|
|
|
|
Assert.Equal(expectedWrite, updatedAccessPolicy.Write);
|
|
|
|
|
AssertHelper.AssertRecent(updatedAccessPolicy.RevisionDate);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task DeleteAccessPolicy_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
var response = await _client.DeleteAsync($"/access-policies/{initData.AccessPolicyId}");
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
|
|
|
|
[Fact]
|
2023-02-06 18:26:06 +01:00
|
|
|
|
public async Task DeleteAccessPolicy_NoPermission()
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
// Create a new account as a user
|
2023-02-16 16:47:34 +01:00
|
|
|
|
await _organizationHelper.Initialize(true, true);
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var initData = await SetupAccessPolicyRequest(orgUser.OrganizationId);
|
|
|
|
|
|
|
|
|
|
var response = await _client.DeleteAsync($"/access-policies/{initData.AccessPolicyId}");
|
|
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
2023-07-13 18:46:01 +02:00
|
|
|
|
public async Task DeleteAccessPolicy_Success(PermissionType permissionType)
|
2023-02-06 18:26:06 +01:00
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
var accessPolicies = new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserProjectAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedProjectId = initData.ProjectId, OrganizationUserId = orgUser.Id, Read = true, Write = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(accessPolicies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var response = await _client.DeleteAsync($"/access-policies/{initData.AccessPolicyId}");
|
2023-01-20 00:31:19 +01:00
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var test = await _accessPolicyRepository.GetByIdAsync(initData.AccessPolicyId);
|
2023-01-20 00:31:19 +01:00
|
|
|
|
Assert.Null(test);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 19:25:14 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetProjectAccessPolicies_ReturnsEmpty()
|
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var project = await _projectRepository.CreateAsync(new Project
|
2023-02-02 19:25:14 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
OrganizationId = org.Id,
|
2023-02-02 19:25:14 +01:00
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var response = await _client.GetAsync($"/projects/{project.Id}/access-policies");
|
2023-02-02 19:25:14 +01:00
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ProjectAccessPoliciesResponseModel>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.Empty(result!.UserAccessPolicies);
|
2023-02-16 16:47:34 +01:00
|
|
|
|
Assert.Empty(result.GroupAccessPolicies);
|
|
|
|
|
Assert.Empty(result.ServiceAccountAccessPolicies);
|
2023-02-02 19:25:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task GetProjectAccessPolicies_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
2023-02-16 16:47:34 +01:00
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/projects/{initData.ProjectId}/access-policies");
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 00:31:19 +01:00
|
|
|
|
[Fact]
|
2023-02-06 18:26:06 +01:00
|
|
|
|
public async Task GetProjectAccessPolicies_NoPermission()
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
// Create a new account as a user
|
2023-02-16 16:47:34 +01:00
|
|
|
|
await _organizationHelper.Initialize(true, true);
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(orgUser.OrganizationId);
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/projects/{initData.ProjectId}/access-policies");
|
|
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task GetProjectAccessPolicies(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
var accessPolicies = new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserProjectAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedProjectId = initData.ProjectId, OrganizationUserId = orgUser.Id, Read = true, Write = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(accessPolicies);
|
|
|
|
|
}
|
2023-01-20 00:31:19 +01:00
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var response = await _client.GetAsync($"/projects/{initData.ProjectId}/access-policies");
|
2023-01-20 00:31:19 +01:00
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ProjectAccessPoliciesResponseModel>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result?.ServiceAccountAccessPolicies);
|
|
|
|
|
Assert.Single(result!.ServiceAccountAccessPolicies);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task GetPeoplePotentialGrantees_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.GetAsync(
|
|
|
|
|
$"/organizations/{org.Id}/access-policies/people/potential-grantees");
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task GetPeoplePotentialGrantees_Success(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
2023-02-16 16:47:34 +01:00
|
|
|
|
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
2023-02-06 18:26:06 +01:00
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.GetAsync(
|
|
|
|
|
$"/organizations/{org.Id}/access-policies/people/potential-grantees");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ListResponseModel<PotentialGranteeResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result?.Data);
|
|
|
|
|
Assert.NotEmpty(result!.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task GetServiceAccountPotentialGrantees_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.GetAsync(
|
|
|
|
|
$"/organizations/{org.Id}/access-policies/service-accounts/potential-grantees");
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetServiceAccountPotentialGrantees_OnlyReturnsServiceAccountsWithWriteAccess()
|
|
|
|
|
{
|
|
|
|
|
// Create a new account as a user
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
2023-02-16 16:47:34 +01:00
|
|
|
|
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
2023-02-06 18:26:06 +01:00
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
2023-02-16 16:47:34 +01:00
|
|
|
|
await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
2023-02-06 18:26:06 +01:00
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.GetAsync(
|
|
|
|
|
$"/organizations/{org.Id}/access-policies/service-accounts/potential-grantees");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ListResponseModel<PotentialGranteeResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result?.Data);
|
|
|
|
|
Assert.Empty(result!.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task GetServiceAccountsPotentialGrantees_Success(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(
|
|
|
|
|
new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserServiceAccountAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedServiceAccountId = serviceAccount.Id,
|
|
|
|
|
OrganizationUserId = orgUser.Id,
|
|
|
|
|
Read = true,
|
|
|
|
|
Write = true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.GetAsync(
|
|
|
|
|
$"/organizations/{org.Id}/access-policies/service-accounts/potential-grantees");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ListResponseModel<PotentialGranteeResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result?.Data);
|
|
|
|
|
Assert.NotEmpty(result!.Data);
|
2023-07-14 17:18:26 +02:00
|
|
|
|
Assert.Equal(serviceAccount.Id, result.Data.First(x => x.Id == serviceAccount.Id).Id);
|
2023-02-16 16:47:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task GetProjectPotentialGrantees_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.GetAsync(
|
|
|
|
|
$"/organizations/{org.Id}/access-policies/projects/potential-grantees");
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetProjectPotentialGrantees_OnlyReturnsProjectsWithWriteAccess()
|
|
|
|
|
{
|
|
|
|
|
// Create a new account as a user
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
await _projectRepository.CreateAsync(new Project { OrganizationId = org.Id, Name = _mockEncryptedString });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.GetAsync(
|
|
|
|
|
$"/organizations/{org.Id}/access-policies/projects/potential-grantees");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ListResponseModel<PotentialGranteeResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result?.Data);
|
|
|
|
|
Assert.Empty(result!.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task GetProjectPotentialGrantees_Success(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var project = await _projectRepository.CreateAsync(new Project
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(
|
|
|
|
|
new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserProjectAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedProjectId = project.Id, OrganizationUserId = orgUser.Id, Read = true, Write = true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.GetAsync(
|
|
|
|
|
$"/organizations/{org.Id}/access-policies/projects/potential-grantees");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ListResponseModel<PotentialGranteeResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result?.Data);
|
|
|
|
|
Assert.NotEmpty(result!.Data);
|
2023-07-14 17:18:26 +02:00
|
|
|
|
Assert.Equal(project.Id, result.Data.First(x => x.Id == project.Id).Id);
|
2023-02-06 18:26:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-07 21:30:22 +01:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task CreateServiceAccountAccessPolicies_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, orgUser) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var request = new AccessPoliciesCreateRequest
|
|
|
|
|
{
|
|
|
|
|
UserAccessPolicyRequests = new List<AccessPolicyRequest>
|
|
|
|
|
{
|
|
|
|
|
new() { GranteeId = orgUser.Id, Read = true, Write = true },
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.PostAsJsonAsync($"/service-accounts/{serviceAccount.Id}/access-policies", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
2023-07-13 18:46:01 +02:00
|
|
|
|
public async Task CreateServiceAccountAccessPolicies_MismatchOrgId_NotFound(PermissionType permissionType)
|
2023-02-07 21:30:22 +01:00
|
|
|
|
{
|
|
|
|
|
var (org, orgUser) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var ownerOrgUserId = orgUser.Id;
|
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
2023-07-13 18:46:01 +02:00
|
|
|
|
OrganizationId = Guid.NewGuid(),
|
2023-02-07 21:30:22 +01:00
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var request =
|
|
|
|
|
await SetupUserServiceAccountAccessPolicyRequestAsync(permissionType, org.Id, orgUser.Id,
|
|
|
|
|
serviceAccount.Id);
|
2023-02-07 21:30:22 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var response =
|
|
|
|
|
await _client.PostAsJsonAsync($"/service-accounts/{serviceAccount.Id}/access-policies", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
2023-02-07 21:30:22 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task CreateServiceAccountAccessPolicies_Success(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, orgUser) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var ownerOrgUserId = orgUser.Id;
|
2023-02-07 21:30:22 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
2023-02-07 21:30:22 +01:00
|
|
|
|
{
|
2023-07-13 18:46:01 +02:00
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
var request =
|
|
|
|
|
await SetupUserServiceAccountAccessPolicyRequestAsync(permissionType, org.Id, orgUser.Id,
|
|
|
|
|
serviceAccount.Id);
|
2023-02-07 21:30:22 +01:00
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.PostAsJsonAsync($"/service-accounts/{serviceAccount.Id}/access-policies", request);
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ServiceAccountAccessPoliciesResponseModel>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.Equal(ownerOrgUserId,
|
|
|
|
|
result!.UserAccessPolicies.First(ap => ap.OrganizationUserId == ownerOrgUserId).OrganizationUserId);
|
|
|
|
|
Assert.True(result.UserAccessPolicies.First().Read);
|
|
|
|
|
Assert.True(result.UserAccessPolicies.First().Write);
|
|
|
|
|
|
|
|
|
|
var createdAccessPolicy =
|
|
|
|
|
await _accessPolicyRepository.GetByIdAsync(result.UserAccessPolicies.First().Id);
|
|
|
|
|
Assert.NotNull(createdAccessPolicy);
|
|
|
|
|
Assert.Equal(result.UserAccessPolicies.First().Read, createdAccessPolicy!.Read);
|
|
|
|
|
Assert.Equal(result.UserAccessPolicies.First().Write, createdAccessPolicy.Write);
|
|
|
|
|
Assert.Equal(result.UserAccessPolicies.First().Id, createdAccessPolicy.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CreateServiceAccountAccessPolicies_NoPermission()
|
|
|
|
|
{
|
|
|
|
|
// Create a new account as a user
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var request = new AccessPoliciesCreateRequest
|
|
|
|
|
{
|
|
|
|
|
UserAccessPolicyRequests = new List<AccessPolicyRequest>
|
|
|
|
|
{
|
|
|
|
|
new() { GranteeId = orgUser.Id, Read = true, Write = true },
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.PostAsJsonAsync($"/service-accounts/{serviceAccount.Id}/access-policies", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task GetServiceAccountAccessPolicies_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/service-accounts/{initData.ServiceAccountId}/access-policies");
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetServiceAccountAccessPolicies_ReturnsEmpty()
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/service-accounts/{serviceAccount.Id}/access-policies");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ServiceAccountAccessPoliciesResponseModel>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.Empty(result!.UserAccessPolicies);
|
2023-02-16 16:47:34 +01:00
|
|
|
|
Assert.Empty(result.GroupAccessPolicies);
|
2023-02-07 21:30:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetServiceAccountAccessPolicies_NoPermission()
|
|
|
|
|
{
|
|
|
|
|
// Create a new account as a user
|
2023-02-16 16:47:34 +01:00
|
|
|
|
await _organizationHelper.Initialize(true, true);
|
2023-02-07 21:30:22 +01:00
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(orgUser.OrganizationId);
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/service-accounts/{initData.ServiceAccountId}/access-policies");
|
|
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task GetServiceAccountAccessPolicies(PermissionType permissionType)
|
|
|
|
|
{
|
2023-05-17 12:14:36 +02:00
|
|
|
|
var (org, ownerOrgUser) = await _organizationHelper.Initialize(true, true);
|
2023-02-07 21:30:22 +01:00
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
var accessPolicies = new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserServiceAccountAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedServiceAccountId = initData.ServiceAccountId,
|
|
|
|
|
OrganizationUserId = orgUser.Id,
|
|
|
|
|
Read = true,
|
|
|
|
|
Write = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(accessPolicies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var policies = new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserServiceAccountAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedServiceAccountId = initData.ServiceAccountId,
|
2023-05-17 12:14:36 +02:00
|
|
|
|
OrganizationUserId = ownerOrgUser.Id,
|
2023-02-07 21:30:22 +01:00
|
|
|
|
Read = true,
|
|
|
|
|
Write = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(policies);
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/service-accounts/{initData.ServiceAccountId}/access-policies");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<ServiceAccountAccessPoliciesResponseModel>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result?.UserAccessPolicies);
|
|
|
|
|
Assert.NotEmpty(result!.UserAccessPolicies);
|
2023-05-17 12:14:36 +02:00
|
|
|
|
Assert.Equal(ownerOrgUser.Id,
|
|
|
|
|
result.UserAccessPolicies.First(x => x.OrganizationUserId == ownerOrgUser.Id).OrganizationUserId);
|
2023-02-07 21:30:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 16:47:34 +01:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task CreateServiceAccountGrantedPolicies_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var request = new List<GrantedAccessPolicyRequest> { new() { GrantedId = new Guid() } };
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.PostAsJsonAsync($"/service-accounts/{serviceAccount.Id}/granted-policies", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CreateServiceAccountGrantedPolicies_NoPermission()
|
2023-02-16 16:47:34 +01:00
|
|
|
|
{
|
2023-07-13 18:46:01 +02:00
|
|
|
|
// Create a new account as a user
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
2023-02-16 16:47:34 +01:00
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var project = await _projectRepository.CreateAsync(new Project
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var request =
|
|
|
|
|
new List<GrantedAccessPolicyRequest> { new() { GrantedId = project.Id, Read = true, Write = true } };
|
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var response =
|
|
|
|
|
await _client.PostAsJsonAsync($"/service-accounts/{serviceAccount.Id}/granted-policies", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
2023-02-16 16:47:34 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task CreateServiceAccountGrantedPolicies_MismatchedOrgId_NotFound(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, orgUser) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var ownerOrgUserId = orgUser.Id;
|
|
|
|
|
|
|
|
|
|
var (projectId, serviceAccountId) = await CreateProjectAndServiceAccountAsync(org.Id, true);
|
|
|
|
|
await SetupProjectAndServiceAccountPermissionAsync(permissionType, projectId, serviceAccountId);
|
|
|
|
|
|
|
|
|
|
var request =
|
|
|
|
|
new List<GrantedAccessPolicyRequest> { new() { GrantedId = projectId, Read = true, Write = true } };
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await _client.PostAsJsonAsync($"/service-accounts/{serviceAccountId}/granted-policies", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task CreateServiceAccountGrantedPolicies_Success(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, orgUser) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var ownerOrgUserId = orgUser.Id;
|
2023-02-16 16:47:34 +01:00
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
var (projectId, serviceAccountId) = await CreateProjectAndServiceAccountAsync(org.Id);
|
|
|
|
|
await SetupProjectAndServiceAccountPermissionAsync(permissionType, projectId, serviceAccountId);
|
|
|
|
|
|
|
|
|
|
var request =
|
|
|
|
|
new List<GrantedAccessPolicyRequest> { new() { GrantedId = projectId, Read = true, Write = true } };
|
2023-02-16 16:47:34 +01:00
|
|
|
|
|
|
|
|
|
var response =
|
2023-07-13 18:46:01 +02:00
|
|
|
|
await _client.PostAsJsonAsync($"/service-accounts/{serviceAccountId}/granted-policies", request);
|
2023-02-16 16:47:34 +01:00
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content
|
|
|
|
|
.ReadFromJsonAsync<ListResponseModel<ServiceAccountProjectAccessPolicyResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.NotEmpty(result!.Data);
|
2023-07-13 18:46:01 +02:00
|
|
|
|
Assert.Equal(projectId, result.Data.First().GrantedProjectId);
|
2023-02-16 16:47:34 +01:00
|
|
|
|
|
|
|
|
|
var createdAccessPolicy =
|
|
|
|
|
await _accessPolicyRepository.GetByIdAsync(result.Data.First().Id);
|
|
|
|
|
Assert.NotNull(createdAccessPolicy);
|
|
|
|
|
Assert.Equal(result.Data.First().Read, createdAccessPolicy!.Read);
|
|
|
|
|
Assert.Equal(result.Data.First().Write, createdAccessPolicy.Write);
|
|
|
|
|
Assert.Equal(result.Data.First().Id, createdAccessPolicy.Id);
|
|
|
|
|
AssertHelper.AssertRecent(createdAccessPolicy.CreationDate);
|
|
|
|
|
AssertHelper.AssertRecent(createdAccessPolicy.RevisionDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(false, false)]
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
public async Task GetServiceAccountGrantedPolicies_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/service-accounts/{initData.ServiceAccountId}/granted-policies");
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetServiceAccountGrantedPolicies_ReturnsEmpty()
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = org.Id,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/service-accounts/{serviceAccount.Id}/granted-policies");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content
|
|
|
|
|
.ReadFromJsonAsync<ListResponseModel<ServiceAccountProjectAccessPolicyResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.Empty(result!.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetServiceAccountGrantedPolicies_NoPermission_ReturnsEmpty()
|
|
|
|
|
{
|
|
|
|
|
// Create a new account as a user
|
|
|
|
|
await _organizationHelper.Initialize(true, true);
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(orgUser.OrganizationId);
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/service-accounts/{initData.ServiceAccountId}/granted-policies");
|
|
|
|
|
|
|
|
|
|
var result = await response.Content
|
|
|
|
|
.ReadFromJsonAsync<ListResponseModel<ServiceAccountProjectAccessPolicyResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.Empty(result!.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(PermissionType.RunAsAdmin)]
|
|
|
|
|
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
|
|
|
public async Task GetServiceAccountGrantedPolicies(PermissionType permissionType)
|
|
|
|
|
{
|
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(true, true);
|
|
|
|
|
await LoginAsync(_email);
|
|
|
|
|
var initData = await SetupAccessPolicyRequest(org.Id);
|
|
|
|
|
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
var accessPolicies = new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserProjectAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedProjectId = initData.ProjectId, OrganizationUserId = orgUser.Id, Read = true, Write = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(accessPolicies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"/service-accounts/{initData.ServiceAccountId}/granted-policies");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var result = await response.Content
|
|
|
|
|
.ReadFromJsonAsync<ListResponseModel<ServiceAccountProjectAccessPolicyResponseModel>>();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result?.Data);
|
|
|
|
|
Assert.NotEmpty(result!.Data);
|
|
|
|
|
Assert.Equal(initData.ServiceAccountId, result.Data.First().ServiceAccountId);
|
|
|
|
|
Assert.NotNull(result.Data.First().ServiceAccountName);
|
|
|
|
|
Assert.NotNull(result.Data.First().GrantedProjectName);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
private async Task<RequestSetupData> SetupAccessPolicyRequest(Guid organizationId)
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var project = await _projectRepository.CreateAsync(new Project
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
OrganizationId = organizationId,
|
2023-01-20 00:31:19 +01:00
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
2023-01-20 00:31:19 +01:00
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
OrganizationId = organizationId,
|
2023-01-20 00:31:19 +01:00
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-06 18:26:06 +01:00
|
|
|
|
var accessPolicy = await _accessPolicyRepository.CreateManyAsync(
|
2023-01-20 00:31:19 +01:00
|
|
|
|
new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new ServiceAccountProjectAccessPolicy
|
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
Read = true, Write = true, ServiceAccountId = serviceAccount.Id, GrantedProjectId = project.Id,
|
|
|
|
|
},
|
2023-01-20 00:31:19 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return new RequestSetupData
|
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
ProjectId = project.Id,
|
|
|
|
|
ServiceAccountId = serviceAccount.Id,
|
|
|
|
|
AccessPolicyId = accessPolicy.First().Id,
|
2023-01-20 00:31:19 +01:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 18:46:01 +02:00
|
|
|
|
private async Task<(Guid ProjectId, Guid ServiceAccountId)> CreateProjectAndServiceAccountAsync(Guid organizationId,
|
|
|
|
|
bool misMatchOrganization = false)
|
|
|
|
|
{
|
|
|
|
|
var project = await _projectRepository.CreateAsync(new Project
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = misMatchOrganization ? Guid.NewGuid() : organizationId,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var serviceAccount = await _serviceAccountRepository.CreateAsync(new ServiceAccount
|
|
|
|
|
{
|
|
|
|
|
OrganizationId = organizationId,
|
|
|
|
|
Name = _mockEncryptedString,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (project.Id, serviceAccount.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SetupProjectAndServiceAccountPermissionAsync(PermissionType permissionType, Guid projectId,
|
|
|
|
|
Guid serviceAccountId)
|
|
|
|
|
{
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
var accessPolicies = new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserProjectAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedProjectId = projectId, OrganizationUserId = orgUser.Id, Read = true, Write = true,
|
|
|
|
|
},
|
|
|
|
|
new UserServiceAccountAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedServiceAccountId = serviceAccountId,
|
|
|
|
|
OrganizationUserId = orgUser.Id,
|
|
|
|
|
Read = true,
|
|
|
|
|
Write = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(accessPolicies);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<AccessPoliciesCreateRequest> SetupUserServiceAccountAccessPolicyRequestAsync(
|
|
|
|
|
PermissionType permissionType, Guid organizationId, Guid userId, Guid serviceAccountId)
|
|
|
|
|
{
|
|
|
|
|
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
|
|
|
{
|
|
|
|
|
var (email, newOrgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
|
|
|
await LoginAsync(email);
|
|
|
|
|
var accessPolicies = new List<BaseAccessPolicy>
|
|
|
|
|
{
|
|
|
|
|
new UserServiceAccountAccessPolicy
|
|
|
|
|
{
|
|
|
|
|
GrantedServiceAccountId = serviceAccountId,
|
|
|
|
|
OrganizationUserId = newOrgUser.Id,
|
|
|
|
|
Read = true,
|
|
|
|
|
Write = true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
await _accessPolicyRepository.CreateManyAsync(accessPolicies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new AccessPoliciesCreateRequest
|
|
|
|
|
{
|
|
|
|
|
UserAccessPolicyRequests = new List<AccessPolicyRequest>
|
|
|
|
|
{
|
|
|
|
|
new() { GranteeId = userId, Read = true, Write = true },
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 00:31:19 +01:00
|
|
|
|
private class RequestSetupData
|
|
|
|
|
{
|
2023-02-06 18:26:06 +01:00
|
|
|
|
public Guid ProjectId { get; set; }
|
|
|
|
|
public Guid AccessPolicyId { get; set; }
|
|
|
|
|
public Guid ServiceAccountId { get; set; }
|
2023-01-20 00:31:19 +01:00
|
|
|
|
}
|
|
|
|
|
}
|