コード例 #1
0
        public async Task InviteUser_NonAdminConfiguringAdmin_Throws(Organization organization, OrganizationUserInvite invite,
                                                                     OrganizationUser invitor, SutProvider <OrganizationService> sutProvider)
        {
            var organizationRepository     = sutProvider.GetDependency <IOrganizationRepository>();
            var organizationUserRepository = sutProvider.GetDependency <IOrganizationUserRepository>();

            organizationRepository.GetByIdAsync(organization.Id).Returns(organization);
            organizationUserRepository.GetManyByUserAsync(invitor.Id).Returns(new List <OrganizationUser> {
                invitor
            });

            var exception = await Assert.ThrowsAsync <BadRequestException>(
                () => sutProvider.Sut.InviteUserAsync(organization.Id, invitor.UserId, null, invite));

            Assert.Contains("only owners and admins", exception.Message.ToLowerInvariant());
        }
コード例 #2
0
 public async Task UpgradePlan_OrganizationIsNull_Throws(Guid organizationId, OrganizationUpgrade upgrade,
                                                         SutProvider <OrganizationService> sutProvider)
 {
     sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(organizationId).Returns(Task.FromResult <Organization>(null));
     var exception = await Assert.ThrowsAsync <NotFoundException>(
         () => sutProvider.Sut.UpgradePlanAsync(organizationId, upgrade));
 }
コード例 #3
0
        public async Task SaveAsync_NonExistingOrganizationId_ThrowsBadRequest(Group group, Organization organization, SutProvider <GroupService> sutProvider)
        {
            var exception = await Assert.ThrowsAsync <BadRequestException>(
                () => sutProvider.Sut.SaveAsync(group));

            Assert.Contains("Organization not found", exception.Message);
            await sutProvider.GetDependency <IGroupRepository>().DidNotReceiveWithAnyArgs().CreateAsync(default);
コード例 #4
0
        public async Task SaveWithServerAsync_PrefersFileUploadService(SutProvider <CipherService> sutProvider,
                                                                       Cipher cipher, string fileName, byte[] data, AttachmentUploadDataResponse uploadDataResponse, CipherString encKey)
        {
            sutProvider.GetDependency <ICryptoService>().EncryptAsync(fileName, Arg.Any <SymmetricCryptoKey>())
            .Returns(new CipherString(fileName));
            sutProvider.GetDependency <ICryptoService>().EncryptToBytesAsync(data, Arg.Any <SymmetricCryptoKey>())
            .Returns(data);
            sutProvider.GetDependency <ICryptoService>().MakeEncKeyAsync(Arg.Any <SymmetricCryptoKey>()).Returns(new Tuple <SymmetricCryptoKey, CipherString>(null, encKey));
            sutProvider.GetDependency <IApiService>().PostCipherAttachmentAsync(cipher.Id, Arg.Any <AttachmentRequest>())
            .Returns(uploadDataResponse);

            await sutProvider.Sut.SaveAttachmentRawWithServerAsync(cipher, fileName, data);

            await sutProvider.GetDependency <IFileUploadService>().Received(1)
            .UploadCipherAttachmentFileAsync(uploadDataResponse, fileName, data);
        }
コード例 #5
0
ファイル: CollectionServiceTests.cs プロジェクト: xq2/server
        public async Task SaveAsync_DefaultId_CreatesCollectionInTheRepository(Collection collection, Organization organization, SutProvider <CollectionService> sutProvider)
        {
            collection.Id = default;
            sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
            var utcNow = DateTime.UtcNow;

            await sutProvider.Sut.SaveAsync(collection);

            await sutProvider.GetDependency <ICollectionRepository>().Received().CreateAsync(collection);

            await sutProvider.GetDependency <IEventService>().Received()
            .LogCollectionEventAsync(collection, EventType.Collection_Created);

            Assert.True(collection.CreationDate - utcNow < TimeSpan.FromSeconds(1));
            Assert.True(collection.RevisionDate - utcNow < TimeSpan.FromSeconds(1));
        }
コード例 #6
0
        public async Task DeleteWithServerAsync_Success(SutProvider <SendService> sutProvider, string userId, IEnumerable <SendData> sendDatas)
        {
            var initialSendDatas = sendDatas.ToDictionary(d => d.Id, d => d);
            var idToDelete       = initialSendDatas.First().Key;
            var expectedSends    = initialSendDatas.Skip(1).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            sutProvider.GetDependency <IStateService>().GetActiveUserIdAsync().Returns(userId);
            sutProvider.GetDependency <IStateService>()
            .GetEncryptedSendsAsync(Arg.Any <string>()).Returns(initialSendDatas);

            await sutProvider.Sut.DeleteWithServerAsync(idToDelete);

            await sutProvider.GetDependency <IApiService>().Received(1).DeleteSendAsync(idToDelete);

            await sutProvider.GetDependency <IStateService>().SetEncryptedSendsAsync(
                Arg.Is <Dictionary <string, SendData> >(s => TestHelper.AssertEqualExpectedPredicate(expectedSends)(s)));
        }
コード例 #7
0
        public async Task SaveAsync_PremiumCannotUpdate(
            SutProvider <EmergencyAccessService> sutProvider, User savingUser)
        {
            savingUser.Premium = false;
            var emergencyAccess = new EmergencyAccess
            {
                Type      = Enums.EmergencyAccessType.Takeover,
                GrantorId = savingUser.Id,
            };

            sutProvider.GetDependency <IUserService>().GetUserByIdAsync(savingUser.Id).Returns(savingUser);

            var exception = await Assert.ThrowsAsync <BadRequestException>(
                () => sutProvider.Sut.SaveAsync(emergencyAccess, savingUser));

            Assert.Contains("Not a premium user.", exception.Message);
            await sutProvider.GetDependency <IEmergencyAccessRepository>().DidNotReceiveWithAnyArgs().ReplaceAsync(default);
コード例 #8
0
        public async Task SaveAsync_DefaultGroupIdAndCollections_CreatesGroupInRepository(Group group, Organization organization, List <SelectionReadOnly> collections, SutProvider <GroupService> sutProvider)
        {
            group.Id = default(Guid);
            sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
            organization.UseGroups = true;
            var utcNow = DateTime.UtcNow;

            await sutProvider.Sut.SaveAsync(group, collections);

            await sutProvider.GetDependency <IGroupRepository>().Received().CreateAsync(group, collections);

            await sutProvider.GetDependency <IEventService>().Received()
            .LogGroupEventAsync(group, EventType.Group_Created);

            Assert.True(group.CreationDate - utcNow < TimeSpan.FromSeconds(1));
            Assert.True(group.RevisionDate - utcNow < TimeSpan.FromSeconds(1));
        }
コード例 #9
0
        public async Task CreateAsync_CallsCreate(OrganizationConnectionData<BillingSyncConfig> data,
            SutProvider<CreateOrganizationConnectionCommand> sutProvider)
        {
            await sutProvider.Sut.CreateAsync(data);

            await sutProvider.GetDependency<IOrganizationConnectionRepository>().Received(1)
                .CreateAsync(Arg.Is(AssertHelper.AssertPropertyEqual(data.ToEntity())));
        }
コード例 #10
0
 public async Task InviteUser_NoEmails_Throws(Organization organization, OrganizationUser invitor,
                                              OrganizationUserInvite invite, SutProvider <OrganizationService> sutProvider)
 {
     invite.Emails = null;
     sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
     await Assert.ThrowsAsync <NotFoundException>(
         () => sutProvider.Sut.InviteUserAsync(organization.Id, invitor.UserId, null, invite));
 }
コード例 #11
0
        public async Task CreateConnection_OnlyOneConnectionOfEachType(OrganizationConnectionType type,
                                                                       OrganizationConnectionRequestModel model, BillingSyncConfig config, Guid existingEntityId,
                                                                       SutProvider <OrganizationConnectionsController> sutProvider)
        {
            model.Type   = type;
            model.Config = JsonDocumentFromObject(config);
            var typedModel = new OrganizationConnectionRequestModel <BillingSyncConfig>(model);
            var existing   = typedModel.ToData(existingEntityId).ToEntity();

            sutProvider.GetDependency <ICurrentContext>().OrganizationOwner(model.OrganizationId).Returns(true);

            sutProvider.GetDependency <IOrganizationConnectionRepository>().GetByOrganizationIdTypeAsync(model.OrganizationId, type).Returns(new[] { existing });

            var exception = await Assert.ThrowsAsync <BadRequestException>(() => sutProvider.Sut.CreateConnection(model));

            Assert.Contains($"The requested organization already has a connection of type {model.Type}. Only one of each connection type may exist per organization.", exception.Message);
        }
コード例 #12
0
        public async Task SaveAsync_OrganizationNotUseGroup_CreateCollectionWithoutGroupsInRepository(Collection collection, IEnumerable <SelectionReadOnly> groups,
                                                                                                      Organization organization, SutProvider <CollectionService> sutProvider)
        {
            collection.Id = default;
            sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
            var utcNow = DateTime.UtcNow;

            await sutProvider.Sut.SaveAsync(collection, groups);

            await sutProvider.GetDependency <ICollectionRepository>().Received().CreateAsync(collection);

            await sutProvider.GetDependency <IEventService>().Received()
            .LogCollectionEventAsync(collection, EventType.Collection_Created);

            Assert.True(collection.CreationDate - utcNow < TimeSpan.FromSeconds(1));
            Assert.True(collection.RevisionDate - utcNow < TimeSpan.FromSeconds(1));
        }
コード例 #13
0
        public async Task DeleteAsync_CallsDelete(OrganizationConnection connection,
                                                  SutProvider <DeleteOrganizationConnectionCommand> sutProvider)
        {
            await sutProvider.Sut.DeleteAsync(connection);

            await sutProvider.GetDependency <IOrganizationConnectionRepository>().Received(1)
            .DeleteAsync(connection);
        }
コード例 #14
0
        public async Task Put_CanNotEditAssignedCollection_ThrowsNotFound(Guid orgId, Guid collectionId, Guid userId, CollectionRequestModel collectionRequest,
                                                                          SutProvider <CollectionsController> sutProvider)
        {
            sutProvider.GetDependency <ICurrentContext>()
            .EditAssignedCollections(orgId)
            .Returns(true);

            sutProvider.GetDependency <ICurrentContext>()
            .UserId
            .Returns(userId);

            sutProvider.GetDependency <ICollectionRepository>()
            .GetByIdAsync(collectionId, userId)
            .Returns(Task.FromResult <CollectionDetails>(null));

            _ = await Assert.ThrowsAsync <NotFoundException>(async() => await sutProvider.Sut.Put(orgId, collectionId, collectionRequest));
        }
コード例 #15
0
ファイル: SendServiceTests.cs プロジェクト: usaweili/mobile
        public async Task SaveWithServerAsync_PutSend_Success(SutProvider <SendService> sutProvider, string userId, SendResponse response, Send send)
        {
            sutProvider.GetDependency <IUserService>().GetUserIdAsync().Returns(userId);
            sutProvider.GetDependency <IApiService>().PutSendAsync(send.Id, Arg.Any <SendRequest>()).Returns(response);

            await sutProvider.Sut.SaveWithServerAsync(send, null);

            Predicate <SendRequest> sendRequestPredicate = r =>
            {
                // Note Send -> SendRequest tested in SendRequestTests
                TestHelper.AssertPropertyEqual(new SendRequest(send, null), r);
                return(true);
            };

            await sutProvider.GetDependency <IApiService>().Received(1)
            .PutSendAsync(send.Id, Arg.Is <SendRequest>(r => sendRequestPredicate(r)));
        }
コード例 #16
0
        public async void HasPremiumFromOrganization_Returns_True_If_Org_Eligible(SutProvider <UserService> sutProvider, User user, OrganizationUser orgUser, Organization organization)
        {
            orgUser.OrganizationId       = organization.Id;
            organization.Enabled         = true;
            organization.UsersGetPremium = true;
            var orgAbilities = new Dictionary <Guid, OrganizationAbility>()
            {
                { organization.Id, new OrganizationAbility(organization) }
            };

            sutProvider.GetDependency <IOrganizationUserRepository>().GetManyByUserAsync(user.Id).Returns(new List <OrganizationUser>()
            {
                orgUser
            });
            sutProvider.GetDependency <IApplicationCacheService>().GetOrganizationAbilitiesAsync().Returns(orgAbilities);

            Assert.True(await sutProvider.Sut.HasPremiumFromOrganization(user));
        }
コード例 #17
0
        public void CanEditDeviceVerificationSettings_ReturnsFalse_When_Email_Is_Not_Verified(SutProvider <UserService> sutProvider, User user)
        {
            user.EmailVerified      = false;
            user.TwoFactorProviders = null;

            sutProvider.GetDependency <Settings.IGlobalSettings>().TwoFactorAuth.EmailOnNewDeviceLogin.Returns(true);

            Assert.False(sutProvider.Sut.CanEditDeviceVerificationSettings(user));
        }
コード例 #18
0
ファイル: SendServiceTests.cs プロジェクト: usaweili/mobile
        public async Task DeleteAsync_Success(int numberToDelete, SutProvider <SendService> sutProvider, string userId, IEnumerable <SendData> sendDatas)
        {
            var actualSendDataDict = sendDatas.ToDictionary(d => d.Id, d => d);

            sutProvider.GetDependency <IUserService>().GetUserIdAsync().Returns(userId);
            sutProvider.GetDependency <IStorageService>()
            .GetAsync <Dictionary <string, SendData> >(GetSendKey(userId)).Returns(actualSendDataDict);

            var idsToDelete   = actualSendDataDict.Take(numberToDelete).Select(kvp => kvp.Key).ToArray();
            var expectedSends = actualSendDataDict.Skip(numberToDelete).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            await sutProvider.Sut.DeleteAsync(idsToDelete);


            await sutProvider.GetDependency <IStorageService>().Received(1)
            .SaveAsync(GetSendKey(userId),
                       Arg.Is <Dictionary <string, SendData> >(s => TestHelper.AssertEqualExpectedPredicate(expectedSends)(s)));
        }
コード例 #19
0
        public async void SaveSendAsync_DisableSend_DoesntApply_success(SendType sendType,
                                                                        SutProvider <SendService> sutProvider, Send send)
        {
            SaveSendAsync_Setup(sendType, disableSendPolicyAppliesToUser: false, sutProvider, send);

            await sutProvider.Sut.SaveSendAsync(send);

            await sutProvider.GetDependency <ISendRepository>().Received(1).CreateAsync(send);
        }
コード例 #20
0
        public async Task ValidateSponsorshipAsync_SponsoringOrgNotEnterprise_UpdatesStripePlan(PlanType planType,
                                                                                                Organization sponsoredOrg, OrganizationSponsorship existingSponsorship, Organization sponsoringOrg,
                                                                                                SutProvider <ValidateSponsorshipCommand> sutProvider)
        {
            sponsoringOrg.PlanType = planType;
            existingSponsorship.SponsoringOrganizationId = sponsoringOrg.Id;

            sutProvider.GetDependency <IOrganizationSponsorshipRepository>()
            .GetBySponsoredOrganizationIdAsync(sponsoredOrg.Id).Returns(existingSponsorship);
            sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(sponsoredOrg.Id).Returns(sponsoredOrg);
            sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(sponsoringOrg.Id).Returns(sponsoringOrg);

            var result = await sutProvider.Sut.ValidateSponsorshipAsync(sponsoredOrg.Id);

            Assert.False(result);
            await AssertRemovedSponsoredPaymentAsync(sponsoredOrg, existingSponsorship, sutProvider);
            await AssertDeletedSponsorshipAsync(existingSponsorship, sutProvider);
        }
コード例 #21
0
        public async Task OfferSponsorship_BadSponsoringOrgPlan_ThrowsBadRequest(PlanType sponsoringOrgPlan,
                                                                                 Organization org, OrganizationUser orgUser, SutProvider <OrganizationSponsorshipService> sutProvider)
        {
            org.PlanType = sponsoringOrgPlan;

            sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(org.Id).Returns(org);

            var exception = await Assert.ThrowsAsync <BadRequestException>(() =>
                                                                           sutProvider.Sut.OfferSponsorshipAsync(org, orgUser, PlanSponsorshipType.FamiliesForEnterprise, default, default, "*****@*****.**"));
コード例 #22
0
        public async Task ValidateBillingSyncKeyAsync_KeyDoesNotEqual_ReturnsFalse(SutProvider <ValidateBillingSyncKeyCommand> sutProvider,
                                                                                   Organization organization, OrganizationApiKey orgApiKey, string billingSyncKey)
        {
            sutProvider.GetDependency <IOrganizationApiKeyRepository>()
            .GetManyByOrganizationIdTypeAsync(organization.Id, OrganizationApiKeyType.BillingSync)
            .Returns(new[] { orgApiKey });

            Assert.False(await sutProvider.Sut.ValidateBillingSyncKeyAsync(organization, billingSyncKey));
        }
コード例 #23
0
        public async void SaveSendAsync_ExistingSend_Updates(SutProvider <SendService> sutProvider,
                                                             Send send)
        {
            send.Id = Guid.NewGuid();

            var now = DateTime.UtcNow;
            await sutProvider.Sut.SaveSendAsync(send);

            Assert.True(send.RevisionDate - now < TimeSpan.FromSeconds(1));

            await sutProvider.GetDependency <ISendRepository>()
            .Received(1)
            .UpsertAsync(send);

            await sutProvider.GetDependency <IPushNotificationService>()
            .Received(1)
            .PushSyncSendUpdateAsync(send);
        }
コード例 #24
0
        private void SaveSendAsync_Setup(SendType sendType, bool disableSendPolicyAppliesToUser,
                                         SutProvider <SendService> sutProvider, Send send)
        {
            send.Id   = default;
            send.Type = sendType;

            sutProvider.GetDependency <IPolicyRepository>().GetCountByTypeApplicableToUserIdAsync(
                Arg.Any <Guid>(), PolicyType.DisableSend).Returns(disableSendPolicyAppliesToUser ? 1 : 0);
        }
コード例 #25
0
        public async void SaveSendAsync_DisableSend_CanManagePolicies_success(SendType sendType,
                                                                              SutProvider <SendService> sutProvider, Send send, List <Policy> policies)
        {
            SaveSendAsync_DisableSend_Setup(sendType, canManagePolicies: true, sutProvider, send, policies);

            await sutProvider.Sut.SaveSendAsync(send);

            await sutProvider.GetDependency <ISendRepository>().Received(1).CreateAsync(send);
        }
コード例 #26
0
        public async Task UpgradePlan_UpgradeFromPaidPlan_Throws(Organization organization, OrganizationUpgrade upgrade,
                                                                 SutProvider <OrganizationService> sutProvider)
        {
            sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
            var exception = await Assert.ThrowsAsync <BadRequestException>(
                () => sutProvider.Sut.UpgradePlanAsync(organization.Id, upgrade));

            Assert.Contains("can only upgrade", exception.Message);
        }
コード例 #27
0
        // SendOptionsPolicy.DisableHideEmail check

        private void SaveSendAsync_DisableHideEmail_Setup(SendType sendType, bool canManagePolicies,
                                                          SutProvider <SendService> sutProvider, Send send, List <Policy> policies)
        {
            send.Id        = default;
            send.Type      = sendType;
            send.HideEmail = true;

            var dataObj = new SendOptionsPolicyData();

            dataObj.DisableHideEmail = true;

            policies.First().Type    = PolicyType.SendOptions;
            policies.First().Enabled = true;
            policies.First().Data    = JsonConvert.SerializeObject(dataObj);

            sutProvider.GetDependency <IPolicyRepository>().GetManyByUserIdAsync(send.UserId.Value).Returns(policies);
            sutProvider.GetDependency <ICurrentContext>().ManagePolicies(Arg.Any <Guid>()).Returns(canManagePolicies);
        }
コード例 #28
0
ファイル: CipherServiceTests.cs プロジェクト: ebell451/core
        public async Task SaveDetailsAsync_CorrectRevisionDate_Passes(string revisionDateString,
                                                                      SutProvider <CipherService> sutProvider, CipherDetails cipherDetails)
        {
            var lastKnownRevisionDate = string.IsNullOrEmpty(revisionDateString) ? (DateTime?)null : cipherDetails.RevisionDate;

            await sutProvider.Sut.SaveDetailsAsync(cipherDetails, cipherDetails.UserId.Value, lastKnownRevisionDate);

            await sutProvider.GetDependency <ICipherRepository>().Received(1).ReplaceAsync(cipherDetails);
        }
コード例 #29
0
        public async Task CreateConnection_Success(OrganizationConnectionRequestModel model, BillingSyncConfig config,
                                                   Guid cloudOrgId, SutProvider <OrganizationConnectionsController> sutProvider)
        {
            model.Config = JsonDocumentFromObject(config);
            var typedModel = new OrganizationConnectionRequestModel <BillingSyncConfig>(model);

            typedModel.ParsedConfig.CloudOrganizationId = cloudOrgId;

            sutProvider.GetDependency <ICreateOrganizationConnectionCommand>().CreateAsync <BillingSyncConfig>(default)
コード例 #30
0
        public async Task UpdateAsync_NoId_Fails(OrganizationConnectionData <BillingSyncConfig> data,
                                                 SutProvider <UpdateOrganizationConnectionCommand> sutProvider)
        {
            data.Id = null;

            var exception = await Assert.ThrowsAsync <Exception>(() => sutProvider.Sut.UpdateAsync(data));

            Assert.Contains("Cannot update connection, Connection does not exist.", exception.Message);
            await sutProvider.GetDependency <IOrganizationConnectionRepository>().DidNotReceiveWithAnyArgs()
            .UpsertAsync(default);