Skip to content

Commit

Permalink
Adding passing test for copying files on encrypted fs
Browse files Browse the repository at this point in the history
  • Loading branch information
arekpalinski committed Apr 25, 2017
1 parent d969a74 commit 9c90c24
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
79 changes: 79 additions & 0 deletions Raven.Tests.FileSystem/Bundles/Encryption/CopyFile.cs
@@ -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());
}
}
}
}
}
1 change: 1 addition & 0 deletions Raven.Tests.FileSystem/Raven.Tests.FileSystem.csproj
Expand Up @@ -142,6 +142,7 @@
<Compile Include="Bugs\UpdatingMetadata.cs" />
<Compile Include="Bugs\UploadFilesWithTheSameContentConcurrently.cs" />
<Compile Include="Bugs\UploadDownload.cs" />
<Compile Include="Bundles\Encryption\CopyFile.cs" />
<Compile Include="Bundles\Versioning\RavenDB_3295.cs" />
<Compile Include="Bundles\Versioning\RavenDB_3979_files.cs" />
<Compile Include="Bundles\Versioning\VersioningAndSynchronization.cs" />
Expand Down

0 comments on commit 9c90c24

Please sign in to comment.