mirror of
https://github.com/bitwarden/server.git
synced 2024-11-24 12:35:25 +01:00
Revert "[SM-1197] - Duplicate GUIDS Show a more detailed error message if dup…" (#4190)
This reverts commit 43b34c433c
.
This commit is contained in:
parent
43b34c433c
commit
41ed38080f
@ -1,22 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Bit.Api.SecretsManager.Models.Request;
|
namespace Bit.Api.SecretsManager.Models.Request;
|
||||||
|
|
||||||
public class GetSecretsRequestModel : IValidatableObject
|
public class GetSecretsRequestModel
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public IEnumerable<Guid> Ids { get; set; }
|
public IEnumerable<Guid> Ids { get; set; }
|
||||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
||||||
{
|
|
||||||
var isDistinct = Ids.Distinct().Count() == Ids.Count();
|
|
||||||
if (!isDistinct)
|
|
||||||
{
|
|
||||||
var duplicateGuids = Ids.GroupBy(x => x)
|
|
||||||
.Where(g => g.Count() > 1)
|
|
||||||
.Select(g => g.Key);
|
|
||||||
|
|
||||||
yield return new ValidationResult(
|
|
||||||
$"The following GUIDs were duplicated {string.Join(", ", duplicateGuids)} ",
|
|
||||||
new[] { nameof(GetSecretsRequestModel) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -788,47 +788,6 @@ public class SecretsControllerTests : IClassFixture<ApiApplicationFactory>, IAsy
|
|||||||
Assert.Equal(secretIds.Count, result.Data.Count());
|
Assert.Equal(secretIds.Count, result.Data.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(PermissionType.RunAsAdmin)]
|
|
||||||
[InlineData(PermissionType.RunAsUserWithPermission)]
|
|
||||||
public async Task GetSecretsByIds_DuplicateIds_BadRequest(PermissionType permissionType)
|
|
||||||
{
|
|
||||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
|
||||||
await _loginHelper.LoginAsync(_email);
|
|
||||||
|
|
||||||
var (project, secretIds) = await CreateSecretsAsync(org.Id);
|
|
||||||
|
|
||||||
secretIds.Add(secretIds[0]);
|
|
||||||
|
|
||||||
if (permissionType == PermissionType.RunAsUserWithPermission)
|
|
||||||
{
|
|
||||||
var (email, orgUser) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
|
||||||
await _loginHelper.LoginAsync(email);
|
|
||||||
|
|
||||||
var accessPolicies = new List<BaseAccessPolicy>
|
|
||||||
{
|
|
||||||
new UserProjectAccessPolicy
|
|
||||||
{
|
|
||||||
GrantedProjectId = project.Id, OrganizationUserId = orgUser.Id, Read = true, Write = true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
await _accessPolicyRepository.CreateManyAsync(accessPolicies);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.Admin, true);
|
|
||||||
await _loginHelper.LoginAsync(email);
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = new GetSecretsRequestModel { Ids = secretIds };
|
|
||||||
var response = await _client.PostAsJsonAsync("/secrets/get-by-ids", request);
|
|
||||||
var content = await response.Content.ReadAsStringAsync();
|
|
||||||
|
|
||||||
Assert.True(response.StatusCode == HttpStatusCode.BadRequest);
|
|
||||||
Assert.Contains("The following GUIDs were duplicated", content);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(false, false, false)]
|
[InlineData(false, false, false)]
|
||||||
[InlineData(false, false, true)]
|
[InlineData(false, false, true)]
|
||||||
|
Loading…
Reference in New Issue
Block a user