forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding passing test for copying files on encrypted fs
- Loading branch information
1 parent
d969a74
commit 9c90c24
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="CopyFile.cs" company="Hibernating Rhinos LTD"> | ||
// Copyright (c) Hibernating Rhinos LTD. All rights reserved. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Raven.Abstractions.Data; | ||
using Raven.Abstractions.Extensions; | ||
using Raven.Abstractions.FileSystem; | ||
using Raven.Tests.Helpers; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Raven.Tests.FileSystem.Bundles.Encryption | ||
{ | ||
public class CopyFile : RavenFilesTestBase | ||
{ | ||
[Theory] | ||
[PropertyData("Storages")] | ||
public async Task Copy_file_should_not_broke_source_file(string requestedStorage) | ||
{ | ||
using (var server = CreateServer(8079, requestedStorage: requestedStorage, runInMemory: false)) | ||
{ | ||
var store = server.FilesStore; | ||
|
||
var fs1Doc = new FileSystemDocument | ||
{ | ||
Id = Constants.FileSystem.Prefix + "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.AesCryptoServiceProvider, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" | ||
}, | ||
}, | ||
}; | ||
await store.AsyncFilesCommands.Admin.CreateFileSystemAsync(fs1Doc); | ||
|
||
var r = new Random(); | ||
|
||
var bytes = new byte[43234]; | ||
|
||
r.NextBytes(bytes); | ||
|
||
using (var session = store.OpenAsyncSession("FS1")) | ||
{ | ||
session.RegisterUpload("test1.txt", StringToStream("Secret password")); | ||
session.RegisterUpload("test2.txt", new MemoryStream(bytes)); | ||
await session.SaveChangesAsync(); | ||
} | ||
|
||
using (var session = store.OpenAsyncSession("FS1")) | ||
{ | ||
await session.Commands.CopyAsync("test1.txt", "test1-copy.txt"); | ||
await session.Commands.CopyAsync("test1.txt", "test2-copy.txt"); | ||
} | ||
|
||
using (var session = store.OpenAsyncSession("FS1")) | ||
{ | ||
var test1 = StreamToString(await session.DownloadAsync("test1.txt")); | ||
Assert.Equal("Secret password", test1); | ||
|
||
var test2 = await session.DownloadAsync("test2.txt"); | ||
Assert.Equal(bytes, test2.ReadData()); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters