예제 #1
0
파일: Crud.cs 프로젝트: xinix00/ravendb
        public void Transactional()
        {
            const string FirstCompany = "FirstCompany";

            var encryptedDataPath = NewDataPath("Encrypted");

            using (var server = GetNewServer(runInMemory: false, requestedStorage: "esent", dataDirectory: encryptedDataPath, activeBundles: "Encryption", configureConfig: configuration =>
            {
                configuration.Settings["Raven/Encryption/Key"] = "3w17MIVIBLSWZpzH0YarqRlR2+yHiv1Zq3TCWXLEMI8=";
            }))
                using (var documentStore = NewRemoteDocumentStore(ravenDbServer: server))
                {
                    // write in transaction
                    documentStore.DatabaseCommands.Put("docs/1", null, new RavenJObject {
                        { "Name", FirstCompany }
                    }, new RavenJObject {
                        { "Raven-Transaction-Information", Guid.NewGuid() + ", " + TimeSpan.FromMinutes(1) }
                    });

                    var jsonDocument = documentStore.DatabaseCommands.Get("docs/1");
                    Assert.True(jsonDocument.Metadata.Value <bool>(Constants.RavenDocumentDoesNotExists));
                }

            EncryptionTestUtil.AssertPlainTextIsNotSavedInAnyFileInPath(new[] { FirstCompany }, encryptedDataPath, s => true);
        }
예제 #2
0
파일: Crud.cs 프로젝트: xinix00/ravendb
        public void Transactional()
        {
            var compressedDataPath = NewDataPath("Compressed");

            const string FirstCompany = "FirstCompany";

            using (var server = GetNewServer(activeBundles: "Compression", dataDirectory: compressedDataPath, runInMemory: false, requestedStorage: "esent"))
                using (var documentStore = NewRemoteDocumentStore(ravenDbServer: server))
                {
                    // write in transaction
                    documentStore.DatabaseCommands.Put("docs/1", null, new RavenJObject {
                        { "Name", FirstCompany }
                    }, new RavenJObject {
                        { "Raven-Transaction-Information", Guid.NewGuid() + ", " + TimeSpan.FromMinutes(1) }
                    });

                    var jsonDocument = documentStore.DatabaseCommands.Get("docs/1");
                    Assert.True(jsonDocument.Metadata.Value <bool>(Constants.RavenDocumentDoesNotExists));
                }

            EncryptionTestUtil.AssertPlainTextIsNotSavedInAnyFileInPath(new [] { FirstCompany }, compressedDataPath, file => Path.GetExtension(file) != ".cfs");
        }
        public async Task CanRestoreBackupOfEncryptedFileSystem(string requestedStorage)
        {
            dataPath = NewDataPath("CanRestoreBackupOfEncryptedFileSystem", false);

            using (var server = CreateServer(Ports[0], requestedStorage: requestedStorage, runInMemory: false, dataDirectory: dataPath))
            {
                var store  = server.FilesStore;
                var fs1Doc = new FileSystemDocument()
                {
                    Id       = "FS1",
                    Settings =
                    {
                        { Constants.FileSystem.DataDirectory, Path.Combine(server.Configuration.FileSystem.DataDirectory, "FS1") },
                        { Constants.ActiveBundles,            "Encryption" }
                    },
                    SecuredSettings = new Dictionary <string, string>
                    {
                        {
                            "Raven/Encryption/Key", "arHd5ENxwieUCAGkf4Rns8oPWx3f6npDgAowtIAPox0="
                        },
                        {
                            "Raven/Encryption/Algorithm", "System.Security.Cryptography.DESCryptoServiceProvider, mscorlib"
                        },
                    },
                };
                await store.AsyncFilesCommands.Admin.CreateFileSystemAsync(fs1Doc, "FS1");

                using (var session = store.OpenAsyncSession("FS1"))
                {
                    session.RegisterUpload("test1.txt", StringToStream("Secret password"));
                    session.RegisterUpload("test2.txt", StringToStream("Security guard"));
                    await session.SaveChangesAsync();
                }

                await store.AsyncFilesCommands.ForFileSystem("FS1").Admin.StartBackup(backupDir, null, false, "FS1");

                WaitForBackup(store.AsyncFilesCommands.ForFileSystem("FS1"), true);

                string filesystemDir = Path.Combine(server.Configuration.FileSystem.DataDirectory, "FS2");

                await store.AsyncFilesCommands.Admin.StartRestore(new FilesystemRestoreRequest
                {
                    BackupLocation     = backupDir,
                    FilesystemName     = "FS2",
                    FilesystemLocation = filesystemDir
                });

                SpinWait.SpinUntil(() => store.AsyncFilesCommands.Admin.GetNamesAsync().Result.Contains("FS2"),
                                   Debugger.IsAttached ? TimeSpan.FromMinutes(10) : TimeSpan.FromMinutes(1));

                using (var session = server.DocumentStore.OpenAsyncSession(Constants.SystemDatabase))
                {
                    var fs2Doc = await session.LoadAsync <FileSystemDocument>(Constants.FileSystem.Prefix + "FS2");

                    Assert.NotEqual(fs1Doc.SecuredSettings["Raven/Encryption/Key"], fs2Doc.SecuredSettings["Raven/Encryption/Key"]);
                    Assert.NotEqual(fs1Doc.SecuredSettings["Raven/Encryption/Algorithm"], fs2Doc.SecuredSettings["Raven/Encryption/Algorithm"]);
                }

                using (var session = store.OpenAsyncSession("FS2"))
                {
                    var test1 = StreamToString(await session.DownloadAsync("test1.txt"));

                    Assert.Equal("Secret password", test1);

                    var test2 = StreamToString(await session.DownloadAsync("test2.txt"));

                    Assert.Equal("Security guard", test2);
                }
            }

            Close();

            EncryptionTestUtil.AssertPlainTextIsNotSavedInAnyFileInPath(new[]
            {
                "Secret password", "Security guard"
            }, dataPath, s => true);
        }
예제 #4
0
 protected void AssertPlainTextIsNotSavedInDatabase(params string[] plaintext)
 {
     Close();
     EncryptionTestUtil.AssertPlainTextIsNotSavedInAnyFileInPath(plaintext, path, s => true);
 }
예제 #5
0
 protected void AssertPlainTextIsNotSavedInDatabase_ExceptIndexes(params string[] plaintext)
 {
     documentStore.Dispose();
     ravenDbServer.Dispose();
     EncryptionTestUtil.AssertPlainTextIsNotSavedInAnyFileInPath(plaintext, path, file => Path.GetExtension(file) != ".cfs");
 }