示例#1
0
文件: Reading.cs 项目: JPT123/ravendb
		public void CanReadDocumentWhichWasNotSecured()
		{
			var company = new Company
			{
				Name = "Hibernating Rhinos"
			};
			using (var s = store.OpenSession())
			{
				s.Store(new AuthorizationUser
				{
					Id = UserId,
					Name = "Ayende Rahien",
				});

				s.Store(company);

				// by not specifying that, we say that anyone can read this
				//s.SetAuthorizationFor(company, new DocumentAuthorization());

				s.SaveChanges();
			}

			using (var s = store.OpenSession())
			{
				s.SecureFor(UserId, "Company/Bid");

				Assert.NotNull(s.Load<Company>(company.Id));
			}
		}
示例#2
0
		public void Will_limit_replication_history_size_on_items_marked_with_not_for_replication()
		{
			var store1 = CreateStore();

			using (var session = store1.OpenSession())
			{
				var entity = new Company {Name = "Hibernating Rhinos"};
				session.Store(entity);
				session.Advanced.GetMetadataFor(entity)["Raven-Not-For-Replication"] = "true";
				session.SaveChanges();
			}

			for (int i = 0; i < 100; i++)
			{
				using (var session = store1.OpenSession())
				{
					var company = session.Load<Company>(1);
					company.Name = i%2 == 0 ? "a" : "b";
					session.SaveChanges();
				}
			}

			using (var session = store1.OpenSession())
			{
				var company = session.Load<Company>(1);
				var ravenJArray = session.Advanced.GetMetadataFor(company).Value<RavenJArray>(Constants.RavenReplicationHistory);
				Assert.Equal(50, ravenJArray.Length);
			}

		}
示例#3
0
		public void WillAbortDeleteIfUserDoesNotHavePermissions()
		{
			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();
			}

			using (var s = store.OpenSession())
			{
				s.SecureFor(UserId, "Company/Rename");

				Assert.Throws<InvalidOperationException>(() => s.Advanced.DatabaseCommands.Delete(company.Id, null));
			}
		}
示例#4
0
文件: Reading.cs 项目: JPT123/ravendb
		public void CannotReadDocumentWithoutPermissionToIt()
		{
			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();
			}

			using (var s = store.OpenSession())
			{
				s.SecureFor(UserId, "Company/Bid");

				var readVetoException = Assert.Throws<ReadVetoException>(() => s.Load<Company>(company.Id));

				Assert.Equal(@"Document could not be read because of a read veto.
The read was vetoed by: Raven.Bundles.Authorization.Triggers.AuthorizationReadTrigger
Veto reason: Could not find any permissions for operation: Company/Bid on companies/1 for user Authorization/Users/Ayende.
No one may perform operation Company/Bid on companies/1
", readVetoException.Message);
			}
		}
示例#5
0
        public void BugWhenSavingDocumentWithPreviousAuthorization_WithQuery()
        {
            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
                {
                    Permissions =
                                       {
                                               new DocumentPermission
                                               {
                                                       User = UserId,
                                                       Allow = true,
                                                       Operation = "Company/Bid"
                                               }
                                       }
                });

                s.SaveChanges();
            }

            for (int i = 0; i < 15; i++)
            {
                using (var s = store.OpenSession())
                {
                    s.SecureFor(UserId, "Company/Bid");

                    var c = s.Query<Company>().Customize(x => x.WaitForNonStaleResults()).First();
                    c.Name = "other " + i;

                    s.SaveChanges();
                }

            }

            using (var s = store.OpenSession())
            {
                s.SecureFor(UserId, "Company/Bid");

                var load = s.Load<Company>(company.Id);
                Assert.NotNull(load);
                Assert.Equal("other 14", load.Name);
            }
        }
示例#6
0
		public void BugWhenUpdatingUserRolesQuery()
		{
			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
				{
					Permissions =
                        {
                            new DocumentPermission
                            {
                                Role = "Admins",
                                Allow = true,
                                Operation = "Company/Bid"
                            }
                        }
				});

				s.SaveChanges();
			}

			using (var s = store.OpenSession())
			{
				s.SecureFor(UserId, "Company/Bid");

				Assert.Empty(s.Query<Company>().ToArray());
			}

			using (var s = store.OpenSession())
			{
				var user = s.Load<AuthorizationUser>(UserId);
				user.Roles = new List<string> { "Admins" };
				s.SaveChanges();
			}

			using (var s = store.OpenSession())
			{
				s.SecureFor(UserId, "Company/Bid");

				Assert.NotEmpty(s.Query<Company>().ToArray());
		
			}
		}
		public void CanAskWhateverUserHavePermissions()
		{
			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
				{
					Permissions =
						{
							new DocumentPermission
							{
								Role = "Admins",
								Allow = true,
								Operation = "Company/Bid"
							}
						}
				});

				s.SaveChanges();
			}

			using (var s = store.OpenSession())
			{
				var isOperationAllowedOnDocument = s.Advanced.IsOperationAllowedOnDocument(UserId, "Company/Bid", "companies/1");
				Assert.False(isOperationAllowedOnDocument.IsAllowed);
				Assert.Equal("Could not find any permissions for operation: Company/Bid on companies/1 for user Authorization/Users/Ayende.\r\nOnly the following may perform operation Company/Bid on companies/1:\r\n\tOperation: Company/Bid, User: , Role: Admins, Allow: True, Priority: 0\r\n",
					isOperationAllowedOnDocument.Reasons[0]);
			}

			using (var s = store.OpenSession())
			{
				var user = s.Load<AuthorizationUser>(UserId);
				user.Roles = new List<string> { "Admins" };
				s.SaveChanges();
			}

			using (var s = store.OpenSession())
			{
				var isOperationAllowedOnDocument = s.Advanced.IsOperationAllowedOnDocument(UserId, "Company/Bid", "companies/1");
				Assert.True(isOperationAllowedOnDocument.IsAllowed);
				Assert.Equal(new[] { "Operation: Company/Bid, User: , Role: Admins, Allow: True, Priority: 0" }, isOperationAllowedOnDocument.Reasons.ToArray());
			}
		}
示例#8
0
        public void Will_automatically_set_metadata()
        {
            var company = new Company {Name = "Company Name"};
            using (var session = documentStore.OpenSession())
            {
                session.Store(company);
                session.SaveChanges();
            }

            using (var session = documentStore.OpenSession())
            {
                var company2 = session.Load<Company>(company.Id);
                var metadata = session.Advanced.GetMetadataFor(company2);
                Assert.Equal("Current", metadata.Value<string>("Raven-Document-Revision-Status"));
                Assert.Equal(1, metadata.Value<int>("Raven-Document-Revision"));
            }
        }
示例#9
0
		public void Will_automatically_craete_duplicate_on_first_insert()
		{
			var company = new Company {Name = "Company Name"};
			using (var session = documentStore.OpenSession())
			{
				session.Store(company);
				session.SaveChanges();
			}

			using (var session = documentStore.OpenSession())
			{
				var company2 = session.Load<Company>(company.Id + "/revisions/1");
				var metadata = session.Advanced.GetMetadataFor(company2);
				Assert.Equal(company.Name, company2.Name);
				Assert.Equal("Historical", metadata.Value<string>("Raven-Document-Revision-Status"));
			}
		}
示例#10
0
文件: Crud.cs 项目: arelee/ravendb
		public void StoreAndLoad()
		{
			const string CompanyName = "Company Name";
			var company = new Company { Name = CompanyName };
			using (var session = documentStore.OpenSession())
			{
				session.Store(company);
				session.SaveChanges();
			}

			using (var session = documentStore.OpenSession())
			{
				Assert.Equal(CompanyName, session.Load<Company>(1).Name);
			}

			AssertPlainTextIsNotSavedInDatabase_ExceptIndexes(CompanyName);
		}
示例#11
0
		public void Can_add_entity_with_expiry_then_read_it_before_it_expires()
		{
			var company = new Company {Name = "Company Name"};
			var expiry = DateTime.UtcNow.AddMinutes(5);
			using (var session = documentStore.OpenSession())
			{
				session.Store(company);
				session.Advanced.GetMetadataFor(company)["Raven-Expiration-Date"] = new RavenJValue(expiry);
				session.SaveChanges();
			}

			using (var session = documentStore.OpenSession())
			{
				var company2 = session.Load<Company>(company.Id);
				Assert.NotNull(company2);
				var metadata = session.Advanced.GetMetadataFor(company2);
				Assert.Equal(expiry.ToString(), metadata.Value<DateTime>("Raven-Expiration-Date").ToString());
			}
		}
示例#12
0
        public void GivingPermissionToRoleOnTagAssociatedWithRoleWillAllow()
        {
            var company = new Company
            {
                Name = "Hibernating Rhinos"
            };
            using (var s = store.OpenSession())
            {
                s.Store(new AuthorizationUser
                {
                    Id = userId,
                    Name = "Ayende Rahien",
                    Roles = { "Authorization/Roles/Managers" }
                });

                s.Store(new AuthorizationRole
                {
                    Id = "Authorization/Roles/Managers",
                    Permissions =
						{
							new OperationPermission
							{
								Allow = true,
								Operation = operation,
								Tag = "Fortune 500"
							}
						}
                });

                s.Store(company);

                s.SetAuthorizationFor(company, new DocumentAuthorization
                {
                    Tags = { "Fortune 500" }
                });

                s.SaveChanges();
            }

            var jsonDocument = server.Database.Get(company.Id, null);
            var isAllowed = authorizationDecisions.IsAllowed(userId, operation, company.Id, jsonDocument.Metadata, null);
            Assert.True(isAllowed);
        }
示例#13
0
        public void After_expiry_passed_document_will_be_physically_deleted()
        {
            var company = new Company
            {
                Id = "companies/1",
                Name = "Company Name"
            };
            var expiry = DateTime.UtcNow.AddMinutes(5);
            using (var session = documentStore.OpenSession())
            {
                session.Store(company);
                session.Advanced.GetMetadataFor(company)["Raven-Expiration-Date"] = new JValue(expiry);
                session.SaveChanges();

                session.Advanced.LuceneQuery<Company>("Raven/DocumentsByExpirationDate")
                    .WaitForNonStaleResults()
                    .ToList();
            }
            ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow.AddMinutes(10);

            using (var session = documentStore.OpenSession())
            {
                session.Store(new Company
                {
                    Id = "companies/2",
                    Name = "Company Name"
                });
                session.SaveChanges(); // this forces the background task to run
            }

            JsonDocument documentByKey = null;
            for (int i = 0; i < 15; i++)
            {
                ravenDbServer.Database.TransactionalStorage.Batch(accessor =>
                {
                    documentByKey = accessor.Documents.DocumentByKey("companies/1", null);
                });
                if (documentByKey == null)
                    return;
                Thread.Sleep(100);
            }
            Assert.False(true, "Document was not deleted");
        }
示例#14
0
		public void BugWhenSavingDocumentOnDatabase()
		{
			string database = "test_auth";
			store.DatabaseCommands.EnsureDatabaseExists(database);

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

				s.Store(company);

				s.SetAuthorizationFor(company, new DocumentAuthorization
				{
					Permissions =
						{
							new DocumentPermission
							{
								User = UserId,
								Allow = true,
								Operation = "Company/Bid"
							}
						}
				});

				s.SaveChanges();
			}

			using (var s = store.OpenSession(database))
			{
				s.SecureFor(UserId, "Company/Bid");

				Assert.NotNull(s.Load<Company>(company.Id));
			}
		}
示例#15
0
        public void Can_add_entity_with_expiry_then_read_it_before_it_expires()
        {
            var company = new Company {Name = "Company Name"};
            var expiry = DateTime.UtcNow.AddMinutes(5);
            using (var session = documentStore.OpenSession())
            {
                session.Store(company);
                session.Advanced.GetMetadataFor(company)["Raven-Expiration-Date"] = new JValue(expiry);
                session.SaveChanges();
            }

            using (var session = documentStore.OpenSession())
            {
                var company2 = session.Load<Company>(company.Id);
                Assert.NotNull(company2);
                var metadata = session.Advanced.GetMetadataFor(company2);
                var dateAsJsStr = @"\/Date("+(long)( expiry - new DateTime(1970,1,1) ).TotalMilliseconds+@")\/";
                Assert.Equal(dateAsJsStr, metadata.Value<string>("Raven-Expiration-Date"));
            }
        }
示例#16
0
		public void WillDeleteIfUserHavePermissions()
		{
			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
				{
					Permissions =
						{
							new DocumentPermission
							{
								Allow = true,
								User = UserId,
								Operation = "Company/Rename"
							}
						}
				});// deny everyone

				s.SaveChanges();
			}

			using (var s = store.OpenSession())
			{
				s.SecureFor(UserId, "Company/Rename");
				company.Name = "Stampading Rhinos";
				s.Store(company);

				Assert.DoesNotThrow(() => s.Advanced.DatabaseCommands.Delete(company.Id, null));
			}
		}
示例#17
0
文件: Reading.cs 项目: vinone/ravendb
        public void CanReadDocumentWhichUserHavePermissionsTo()
        {
            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
                {
                    Permissions =
                        {
                            new DocumentPermission
                            {
                                User = UserId,
                                Allow = true,
                                Operation = "Company/Bid"
                            }
                        }
                });

                s.SaveChanges();
            }

            using (var s = store.OpenSession())
            {
                s.SecureFor(UserId, "Company/Bid");

                Assert.NotNull(s.Load<Company>(company.Id));
            }
        }
示例#18
0
		public void WhenGivingPermissionOnDocumentRoleAndAssociatingUserWithRoleWillAllow()
		{
			var company = new Company
			{
				Name = "Hibernating Rhinos"
			};
			using (var s = store.OpenSession())
			{
				s.Store(new AuthorizationUser
				{
					Id = userId,
					Name = "Ayende Rahien",
					Roles = { "/Raven/Authorization/Roles/Managers" }
				});

				s.Store(company);

				s.SetAuthorizationFor(company, new DocumentAuthorization
				{
					Permissions =
						{
							new DocumentPermission
							{
								Allow = true,
								Operation = operation,
								Role = "/Raven/Authorization/Roles/Managers"
							}
						}
				});

				s.SaveChanges();
			}

			var jsonDocument = server.Database.Get(company.Id, null);
			var isAllowed = authorizationDecisions.IsAllowed(userId, operation, company.Id, jsonDocument.Metadata, null);
			Assert.True(isAllowed);
		}
示例#19
0
        public void CanGiveUserExplicitPermissionOnDoc()
        {
            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
                {
                    Permissions =
                        {
                            new DocumentPermission
                            {
                                Allow = true,
                                Operation = operation,
                                User = userId
                            }
                        }
                });

                s.SaveChanges();
            }

            var jsonDocument = server.Database.Get(company.Id, null);
            var isAllowed = authorizationDecisions.IsAllowed(userId, operation, company.Id, jsonDocument.Metadata, null);
            Assert.True(isAllowed);
        }
示例#20
0
        public void GivingPermissionToRoleOnTagAssociatedWithRoleWillAllow_OnClient()
        {
            var company = new Company
            {
                Name = "Hibernating Rhinos"
            };
            using (var s = store.OpenSession())
            {
                s.Store(new AuthorizationUser
                {
                    Id = userId,
                    Name = "Ayende Rahien",
                    Roles = { "Authorization/Roles/Managers" }
                });

                s.Store(new AuthorizationRole
                {
                    Id = "Authorization/Roles/Managers",
                    Permissions =
						{
							new OperationPermission
							{
								Allow = true,
								Operation = operation,
								Tag = "Fortune 500"
							}
						}
                });

                s.Store(company);

                s.SetAuthorizationFor(company, new DocumentAuthorization
                {
                    Tags = { "Fortune 500" }
                });

                s.SaveChanges();

            }

            using (var s = store.OpenSession())
            {
                var authorizationUser = s.Load<AuthorizationUser>(userId);
                Assert.True(s.IsAllowed(authorizationUser, operation));
            }
        }
示例#21
0
文件: Reading.cs 项目: JPT123/ravendb
		public void DocumentWithoutPermissionWillBeFilteredOutSiltently()
		{
			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();
			}

			using (var s = store.OpenSession())
			{
				s.SecureFor(UserId, "Company/Bid");

				Assert.Equal(0, s.Advanced.LuceneQuery<Company>()
									.WaitForNonStaleResults()
				                	.ToList().Count);
			}
		}
示例#22
0
        public void Will_delete_old_revisions()
        {
            var company = new Company {Name = "Company #1"};
            using (var session = documentStore.OpenSession())
            {
                session.Store(company);
                session.SaveChanges();
                for (int i = 0; i < 10; i++)
                {
                    company.Name = "Company #" + i + 2;
                    session.SaveChanges();
                }
            }

            using (var session = documentStore.OpenSession())
            {
                for (int i = 1; i < 6; i++)
                {
                    Assert.Null(session.Load<Company>(company.Id + "/revisions/" + i));
                }

                for (int i = 6; i < 11; i++)
                {
                    Assert.NotNull(session.Load<Company>(company.Id + "/revisions/" + i));
                }
            }
        }
示例#23
0
		public void Can_get_all_revisions()
		{
			var company = new Company { Name = "Company Name" };
			using (var session = documentStore.OpenSession())
			{
				session.Store(company);
				session.SaveChanges();
				Assert.Equal(1, session.Advanced.GetMetadataFor(company).Value<int>("Raven-Document-Revision"));
			}
			using (var session = documentStore.OpenSession())
			{
				var company3 = session.Load<Company>(company.Id);
				company3.Name = "Hibernating Rhinos";
				session.SaveChanges();
				Assert.Equal(2, session.Advanced.GetMetadataFor(company3).Value<int>("Raven-Document-Revision"));
			}
			using (var session = documentStore.OpenSession())
			{
				var companiesRevisions = session.Advanced.GetRevisionsFor<Company>(company.Id, 0, 25);
				Assert.Equal("Company Name", companiesRevisions[0].Name);
				Assert.Equal("Hibernating Rhinos", companiesRevisions[1].Name);
			}
		}
示例#24
0
        public void Will_automatically_craete_duplicate_on_next_insert()
        {
            var company = new Company {Name = "Company Name"};
            using (var session = documentStore.OpenSession())
            {
                session.Store(company);
                session.SaveChanges();
                Assert.Equal(1, session.Advanced.GetMetadataFor(company).Value<int>("Raven-Document-Revision"));
            }
            using (var session = documentStore.OpenSession())
            {
                var company3 = session.Load<Company>(company.Id);
                company3.Name = "Hibernating Rhinos";
                session.SaveChanges();
                Assert.Equal(2, session.Advanced.GetMetadataFor(company3).Value<int>("Raven-Document-Revision"));
            }
            using (var session = documentStore.OpenSession())
            {
                var company2 = session.Load<Company>(company.Id + "/revisions/1");
                var metadata = session.Advanced.GetMetadataFor(company2);
                Assert.Equal("Company Name", company2.Name);
                Assert.Equal("Historical", metadata.Value<string>("Raven-Document-Revision-Status"));
                Assert.Null(metadata.Value<string>("Raven-Document-Parent-Revision"));

                company2 = session.Load<Company>(company.Id + "/revisions/2");
                metadata = session.Advanced.GetMetadataFor(company2);
                Assert.Equal("Hibernating Rhinos", company2.Name);
                Assert.Equal("Historical", metadata.Value<string>("Raven-Document-Revision-Status"));
                Assert.Equal("companies/1/revisions/1", metadata.Value<string>("Raven-Document-Parent-Revision"));
            }
        }
示例#25
0
        public void WhenThereIsNoAuthorizationWillAllow()
        {
            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.SaveChanges();
            }

            var jsonDocument = server.Database.Get(company.Id, null);
            var isAllowed = authorizationDecisions.IsAllowed(userId, operation, company.Id, jsonDocument.Metadata, null);
            Assert.True(isAllowed);
        }
示例#26
0
        public void WhenGivingUserPermissionForParentTagAndTaggingDocumentWillAllow()
        {
            var company = new Company
            {
                Name = "Hibernating Rhinos"
            };
            using (var s = store.OpenSession())
            {
                s.Store(new AuthorizationUser
                {
                    Id = userId,
                    Name = "Ayende Rahien",
                    Permissions =
						{
							new OperationPermission
							{
								Allow = true,
								Operation = operation,
								Tag = "Companies"
							}
						}
                });

                s.Store(company);

                s.SetAuthorizationFor(company, new DocumentAuthorization
                {
                    Tags = { "Companies/Important" }
                });

                s.SaveChanges();
            }

            var jsonDocument = server.Database.Get(company.Id, null);
            var isAllowed = authorizationDecisions.IsAllowed(userId, operation, company.Id, jsonDocument.Metadata, null);
            Assert.True(isAllowed);
        }
示例#27
0
		public void WillWriteIfUserHavePermissions_CaseInsensitive()
		{
			var company = new Company
			{
				Name = "Hibernating Rhinos"
			};
			using (var s = store.OpenSession())
			{
				s.Store(new AuthorizationUser
				{
					Id = UserId.ToUpper(),
					Name = "Ayende Rahien",
				});

				s.Store(company);

				s.SetAuthorizationFor(company, new DocumentAuthorization
				{
					Permissions =
						{
							new DocumentPermission
							{
								Allow = true,
								User = UserId.ToUpper(),
								Operation = "Company/Rename"
							}
						}
				});// deny everyone

				s.SaveChanges();
			}

			using (var s = store.OpenSession())
			{
				s.SecureFor(UserId.ToLower(), "Company/Rename");
				company.Name = "Stampading Rhinos";
				s.Store(company);

				Assert.DoesNotThrow(s.SaveChanges);
			}
		}
示例#28
0
		public void Will_not_replicate_replicated_documents()
		{
			var store1 = CreateStore();
			var store2 = CreateStore();

			TellFirstInstanceToReplicateToSecondInstance();

			TellSecondInstanceToReplicateToFirstInstance();
			Company company = null;

			string etag;
			string id;
			using (var session = store1.OpenAsyncSession())
			{
				 company = new Company { Name = "Hibernating Rhinos" };
				session.Store(company);
				session.SaveChangesAsync().Wait();
				id = company.Id;
				session.Advanced.Clear();
				company = session.LoadAsync<Company>(id).Result;
				etag = session.Advanced.GetMetadataFor(company).Value<string>("@etag");
			}



			for (int i = 0; i < RetriesCount; i++)
			{
				using (var session = store2.OpenAsyncSession()) // waiting for document to show up.
				{
					company = session.LoadAsync<Company>(id).Result;
					if (company != null)
						break;
					Thread.Sleep(100);

				}
			}
			Assert.NotNull(company);
			Assert.Equal("Hibernating Rhinos", company.Name);

			// assert that the etag haven't changed (we haven't replicated)
			for (int i = 0; i < 15; i++)
			{
				using (var session = store1.OpenAsyncSession())
				{
					company = session.LoadAsync<Company>(id).Result;
					Assert.Equal(etag, session.Advanced.GetMetadataFor(company).Value<string>("@etag"));
				}
				Thread.Sleep(100);
			}
		}
示例#29
0
		public void Can_add_entity_with_expiry_but_will_not_be_able_to_read_it_after_expiry()
		{
			var company = new Company { Name = "Company Name" };
			var expiry = DateTime.UtcNow.AddMinutes(5);
			using (var session = documentStore.OpenSession())
			{
				session.Store(company);
				session.Advanced.GetMetadataFor(company)["Raven-Expiration-Date"] = new RavenJValue(expiry);
				session.SaveChanges();
			}
			ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow.AddMinutes(10);
		   
			using (var session = documentStore.OpenSession())
			{
				var company2 = session.Load<Company>(company.Id);
				Assert.Null(company2);
			}
		}
示例#30
0
        public void GivingPermissionForAllowAndDenyOnSameLevelWithReturnDeny()
        {
            var company = new Company
            {
                Name = "Hibernating Rhinos"
            };
            using (var s = store.OpenSession())
            {
                s.Store(new AuthorizationUser
                {
                    Id = userId,
                    Name = "Ayende Rahien",
                    Roles = { "Authorization/Roles/Managers" },
                    Permissions =
						{
							new OperationPermission
							{
								Allow = false,
								Operation = operation,
								Tag = "Important"
							}
						}
                });

                s.Store(company);

                s.SetAuthorizationFor(company, new DocumentAuthorization
                {
                    Tags = { "Important" },
                    Permissions =
						{
							new DocumentPermission
							{
								Allow = true,
								Operation = operation,
								Role = "Authorization/Roles/Managers"
							}
						}
                });

                s.SaveChanges();
            }

            var jsonDocument = server.Database.Get(company.Id, null);
            var isAllowed = authorizationDecisions.IsAllowed(userId, operation, company.Id, jsonDocument.Metadata, null);
            Assert.False(isAllowed);
        }