2020-08-20 17:28:42 -04:00
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using PoweredSoft.Storage.S3;
|
2020-10-27 16:04:07 -04:00
|
|
|
using System.Text;
|
2020-08-20 17:28:42 -04:00
|
|
|
|
|
|
|
namespace PoweredSoft.Storage.Test
|
|
|
|
{
|
|
|
|
[TestClass]
|
|
|
|
public class S3Tests
|
|
|
|
{
|
2020-10-27 16:04:07 -04:00
|
|
|
[TestMethod]
|
|
|
|
public async System.Threading.Tasks.Task S3AclWriteAsync()
|
|
|
|
{
|
|
|
|
var space = GetMockS3Space();
|
|
|
|
await space.WriteFileAsync(Encoding.UTF8.GetBytes("Hello World"), "hello-world.txt", new S3FileWriteOptions
|
|
|
|
{
|
|
|
|
Acl = "public-read",
|
|
|
|
OverrideIfExists = true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-20 17:28:42 -04:00
|
|
|
[TestMethod]
|
|
|
|
public void NameValidation()
|
|
|
|
{
|
|
|
|
var space = GetMockS3Space();
|
|
|
|
|
|
|
|
Assert.IsFalse(space.IsFileNameAllowed("Operations .pdf"), "Should not be valid");
|
|
|
|
Assert.IsFalse(space.IsFileNameAllowed("Operations$$.pdf"), "Should not be valid");
|
|
|
|
}
|
|
|
|
|
2020-08-20 19:44:08 -04:00
|
|
|
[TestMethod]
|
|
|
|
public void CanContainDash()
|
|
|
|
{
|
|
|
|
var space = GetMockS3Space();
|
|
|
|
Assert.IsTrue(space.IsFileNameAllowed("Operations-yay.pdf"), "Should be allowed");
|
|
|
|
}
|
|
|
|
|
2020-08-20 17:28:42 -04:00
|
|
|
[TestMethod]
|
|
|
|
public void NameSanitation()
|
|
|
|
{
|
|
|
|
var space = GetMockS3Space();
|
|
|
|
|
|
|
|
Assert.AreEqual("Operations_.pdf", space.SanitizeFileName("Operations .pdf", "_"), "does not match sanitation expectations");
|
|
|
|
Assert.AreEqual("Operations__.pdf", space.SanitizeFileName("Operations$$.pdf", "_"), "does not match sanitation expectations");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static S3StorageProvider GetMockS3Space()
|
|
|
|
{
|
2020-10-27 16:12:46 -04:00
|
|
|
var space = new S3StorageProvider("http://localhost:9000", "mybucket", "minioadmin", "minioadmin");
|
|
|
|
space.SetForcePathStyle(true);
|
|
|
|
space.SetS3UsEast1RegionalEndpointValue(Amazon.Runtime.S3UsEast1RegionalEndpointValue.Legacy);
|
2020-10-27 16:04:07 -04:00
|
|
|
|
2020-08-20 17:28:42 -04:00
|
|
|
return space;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|