|
|
|
|
@ -3,6 +3,7 @@ using Bit.Api.Models.Request;
@@ -3,6 +3,7 @@ using Bit.Api.Models.Request;
|
|
|
|
|
using Bit.Core.AdminConsole.Entities; |
|
|
|
|
using Bit.Core.Context; |
|
|
|
|
using Bit.Core.Entities; |
|
|
|
|
using Bit.Core.Enums; |
|
|
|
|
using Bit.Core.Exceptions; |
|
|
|
|
using Bit.Core.Models.Data; |
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationCollections.Interfaces; |
|
|
|
|
@ -12,6 +13,8 @@ using Bit.Test.Common.AutoFixture;
@@ -12,6 +13,8 @@ using Bit.Test.Common.AutoFixture;
|
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes; |
|
|
|
|
using NSubstitute; |
|
|
|
|
using Xunit; |
|
|
|
|
using Collection = Bit.Core.Entities.Collection; |
|
|
|
|
using User = Bit.Core.Entities.User; |
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Test.Controllers; |
|
|
|
|
|
|
|
|
|
@ -24,8 +27,11 @@ namespace Bit.Api.Test.Controllers;
@@ -24,8 +27,11 @@ namespace Bit.Api.Test.Controllers;
|
|
|
|
|
public class LegacyCollectionsControllerTests |
|
|
|
|
{ |
|
|
|
|
[Theory, BitAutoData] |
|
|
|
|
public async Task Post_Success(Guid orgId, SutProvider<CollectionsController> sutProvider) |
|
|
|
|
public async Task Post_Manager_AssignsToCollection_Success(Guid orgId, OrganizationUser orgUser, SutProvider<CollectionsController> sutProvider) |
|
|
|
|
{ |
|
|
|
|
orgUser.Type = OrganizationUserType.Manager; |
|
|
|
|
orgUser.Status = OrganizationUserStatusType.Confirmed; |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>() |
|
|
|
|
.OrganizationManager(orgId) |
|
|
|
|
.Returns(true); |
|
|
|
|
@ -34,6 +40,53 @@ public class LegacyCollectionsControllerTests
@@ -34,6 +40,53 @@ public class LegacyCollectionsControllerTests
|
|
|
|
|
.EditAnyCollection(orgId) |
|
|
|
|
.Returns(false); |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>() |
|
|
|
|
.EditAssignedCollections(orgId) |
|
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().UserId = orgUser.UserId; |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(orgId, orgUser.UserId.Value) |
|
|
|
|
.Returns(orgUser); |
|
|
|
|
|
|
|
|
|
var collectionRequest = new CollectionRequestModel |
|
|
|
|
{ |
|
|
|
|
Name = "encrypted_string", |
|
|
|
|
ExternalId = "my_external_id" |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
_ = await sutProvider.Sut.Post(orgId, collectionRequest); |
|
|
|
|
|
|
|
|
|
var test = sutProvider.GetDependency<ICollectionService>().ReceivedCalls(); |
|
|
|
|
await sutProvider.GetDependency<ICollectionService>() |
|
|
|
|
.Received(1) |
|
|
|
|
.SaveAsync(Arg.Any<Collection>(), Arg.Any<IEnumerable<CollectionAccessSelection>>(), |
|
|
|
|
Arg.Is<IEnumerable<CollectionAccessSelection>>(users => users.Any(u => u.Id == orgUser.Id && !u.ReadOnly && !u.HidePasswords && !u.Manage))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Theory, BitAutoData] |
|
|
|
|
public async Task Post_Owner_DoesNotAssignToCollection_Success(Guid orgId, OrganizationUser orgUser, SutProvider<CollectionsController> sutProvider) |
|
|
|
|
{ |
|
|
|
|
orgUser.Type = OrganizationUserType.Owner; |
|
|
|
|
orgUser.Status = OrganizationUserStatusType.Confirmed; |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>() |
|
|
|
|
.OrganizationManager(orgId) |
|
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>() |
|
|
|
|
.EditAnyCollection(orgId) |
|
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>() |
|
|
|
|
.EditAssignedCollections(orgId) |
|
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().UserId = orgUser.UserId; |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(orgId, orgUser.UserId.Value) |
|
|
|
|
.Returns(orgUser); |
|
|
|
|
|
|
|
|
|
var collectionRequest = new CollectionRequestModel |
|
|
|
|
{ |
|
|
|
|
Name = "encrypted_string", |
|
|
|
|
@ -42,9 +95,11 @@ public class LegacyCollectionsControllerTests
@@ -42,9 +95,11 @@ public class LegacyCollectionsControllerTests
|
|
|
|
|
|
|
|
|
|
_ = await sutProvider.Sut.Post(orgId, collectionRequest); |
|
|
|
|
|
|
|
|
|
var test = sutProvider.GetDependency<ICollectionService>().ReceivedCalls(); |
|
|
|
|
await sutProvider.GetDependency<ICollectionService>() |
|
|
|
|
.Received(1) |
|
|
|
|
.SaveAsync(Arg.Any<Collection>(), Arg.Any<IEnumerable<CollectionAccessSelection>>(), null); |
|
|
|
|
.SaveAsync(Arg.Any<Collection>(), Arg.Any<IEnumerable<CollectionAccessSelection>>(), |
|
|
|
|
Arg.Is<IEnumerable<CollectionAccessSelection>>(users => !users.Any())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Theory, BitAutoData] |
|
|
|
|
|