Пример #1
0
        public void DocumentWithoutPermissionWillBeFilteredOutSilentlyWithStreaming()
        {
            new CompanyIndex().Execute(store);
            var company = new Company
            {
                Name = "Hibernating Rhinos"
            };

            using (var s = store.OpenSession())
            {
                s.Store(new AuthorizationUser
                {
                    Id   = UserId,
                    Name = "Ayende Rahien",
                });

                s.Store(company);

                s.SetAuthorizationFor(company, new DocumentAuthorization());// deny everyone

                s.SaveChanges();
            }
            WaitForIndexing(store);
            using (var s = store.OpenSession())
            {
                s.SecureFor(UserId, "Company/Bid");
                var results = QueryExtensions.StreamAllFrom(s.Advanced.LuceneQuery <Company, CompanyIndex>(), s);

                Assert.Equal(0, results.Count());
            }
        }
Пример #2
0
        public void DocumentWithoutPermissionWillBeFilteredOutSilentlyWithQueryStreaming()
        {
            new CompanyIndex().Execute(store);
            var rhinosCompany = new Company
            {
                Name = "Hibernating Rhinos"
            };

            var secretCompany = new Company
            {
                Name = "Secret Co."
            };

            var authorizationUser = new AuthorizationUser
            {
                Id   = UserId,
                Name = "Ayende Rahien",
            };

            var operation = "Company/Bid";

            using (var s = store.OpenSession())
            {
                s.Store(authorizationUser);
                s.Store(rhinosCompany);
                s.Store(secretCompany);

                var documentAuthorization = new DocumentAuthorization();
                documentAuthorization.Permissions.Add(new DocumentPermission()
                {
                    Allow     = true,
                    Operation = operation,
                    User      = UserId
                });

                s.SetAuthorizationFor(rhinosCompany, documentAuthorization);                 // allow Ayende Rahien
                s.SetAuthorizationFor(secretCompany, new DocumentAuthorization());           // deny everyone

                s.SaveChanges();
            }

            WaitForIndexing(store);

            using (var s = store.OpenSession())
            {
                s.SecureFor(UserId, operation);
                var expected = s.Advanced.LuceneQuery <Company, CompanyIndex>().ToList().Count();

                var results = QueryExtensions.StreamAllFrom(s.Advanced.LuceneQuery <Company, CompanyIndex>(), s);

                Assert.Equal(expected, results.Count());
            }
        }