public SynchronizationStorageTests() { source = (IAsyncFilesCommandsImpl)NewAsyncClient(0); destination = (IAsyncFilesCommandsImpl) NewAsyncClient(1); sourceRfs = GetFileSystem(0); destinationRfs = GetFileSystem(1); }
/// <summary> /// Uses an encrypted document to verify that the encryption key is correct and decodes it to the right value. /// </summary> public static void VerifyEncryptionKey(RavenFileSystem fileSystem, EncryptionSettings settings) { RavenJObject config = null; try { fileSystem.Storage.Batch(accessor => { try { config = accessor.GetConfig(Constants.InResourceKeyVerificationDocumentName); } catch (FileNotFoundException) { } }); } catch (CryptographicException e) { throw new ConfigurationErrorsException("The file system is encrypted with a different key and/or algorithm than the ones " + "currently in the configuration file.", e); } if (config != null) { if (!RavenJTokenEqualityComparer.Default.Equals(config, Constants.InResourceKeyVerificationDocumentContents)) throw new ConfigurationErrorsException("The file system is encrypted with a different key and/or algorithm than the ones is currently configured"); } else { // This is the first time the file system is loaded. if (EncryptedFileExist(fileSystem)) throw new InvalidOperationException("The file system already has existing files, you cannot start using encryption now."); var clonedDoc = (RavenJObject)Constants.InResourceKeyVerificationDocumentContents.CreateSnapshot(); fileSystem.Storage.Batch(accessor => accessor.SetConfig(Constants.InResourceKeyVerificationDocumentName, clonedDoc)); } }
private static bool EncryptedFileExist(RavenFileSystem fileSystem) { const int pageSize = 10; var start = Guid.Empty; bool foundEncryptedDoc = false; while (true) { var foundMoreDocs = false; fileSystem.Storage.Batch(accessor => { var fileHeaders = accessor.GetFilesAfter(start, pageSize); foreach (var fileHeader in fileHeaders) { foundMoreDocs = true; if (EncryptionSettings.DontEncrypt(fileHeader.Name) == false) { foundEncryptedDoc = true; break; } start = fileHeader.Etag; } }); if (foundEncryptedDoc || foundMoreDocs == false) break; } return foundEncryptedDoc; }
public StorageStreamTest() { NewAsyncClient(); fs = GetFileSystem(); transactionalStorage = fs.Storage; }