Skip to content

Commit

Permalink
Set prefix, delimiter params even when empty
Browse files Browse the repository at this point in the history
We have never set values which are empty on the request
because they are perhaps not useful in the List query,
but this assumption is wrong when there are restricted
policies for a given user, because empty is actually
a valid value in IAM or Bucket policy conditions.

For example following condition would never work with our
ListObjects call and AWS cli would work fine.

            "Condition": {
                "StringEquals": {
                    "s3:prefix": [
                        "",
                        "data/",
                        "data"
                    ],
                    "s3:delimiter": [
                        "/",
                        ""
                    ]
                }
            }

The reason is empty or not prefix and delimiter should be
added to the query param in List operation, such that server
can use the value to validate the policies for the incoming
request.

Refer minio/minio-go#1064
  • Loading branch information
harshavardhana committed Feb 28, 2019
1 parent 329940b commit aa8e0f6
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 309 deletions.
192 changes: 96 additions & 96 deletions Docs/API.md

Large diffs are not rendered by default.

186 changes: 93 additions & 93 deletions Docs/zh_CN/API.md

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Minio.Examples/Cases/ListObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

namespace Minio.Examples.Cases
{

class ListObjects
{
// List objects matching optional prefix in a specified bucket.
public static void Run(Minio.MinioClient minio,
string bucketName = "my-bucket-name",
string prefix = null,
bool recursive = false)
bool recursive = true)
{
try
{
Console.Out.WriteLine("Running example for API: ListObjectsAsync");
IObservable<Item> observable = minio.ListObjectsAsync(bucketName, prefix, recursive);

IDisposable subscription = observable.Subscribe(
item => Console.WriteLine("Object: {0}", item.Key),
ex => Console.WriteLine("OnError: {0}", ex),
Expand All @@ -47,4 +47,3 @@ public static void Run(Minio.MinioClient minio,
}
}
}

73 changes: 38 additions & 35 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Minio .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 Minio, Inc.
* Minio .NET Library for Amazon S3 Compatible Cloud Storage,
* (C) 2017, 2018, 2019 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,7 +46,7 @@ public class FunctionalTest
private static string listBucketsSignature = "Task<ListAllMyBucketsResult> ListBucketsAsync(CancellationToken cancellationToken = default(CancellationToken))";
private static string bucketExistsSignature = "Task<bool> BucketExistsAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))";
private static string removeBucketSignature = "Task RemoveBucketAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))";
private static string listObjectsSignature = "IObservable<Item> ListObjectsAsync(string bucketName, string prefix = null, bool recursive = true, CancellationToken cancellationToken = default(CancellationToken))";
private static string listObjectsSignature = "IObservable<Item> ListObjectsAsync(string bucketName, string prefix = null, bool recursive = false, CancellationToken cancellationToken = default(CancellationToken))";
private static string listIncompleteUploadsSignature = "IObservable<Upload> ListIncompleteUploads(string bucketName, string prefix, bool recursive, CancellationToken cancellationToken = default(CancellationToken))";
private static string getObjectSignature1 = "Task GetObjectAsync(string bucketName, string objectName, Action<Stream> callback, CancellationToken cancellationToken = default(CancellationToken))";
private static string getObjectSignature2 = "Task GetObjectAsync(string bucketName, string objectName, Action<Stream> callback, CancellationToken cancellationToken = default(CancellationToken))";
Expand Down Expand Up @@ -80,7 +81,7 @@ private static String CreateFile(int size, string dataFileName = null)
File.WriteAllBytes(fileName, data);
return GetFilePath(fileName);
}

return GetFilePath(dataFileName);
}

Expand All @@ -98,8 +99,8 @@ public static String GetRandomName(int length = 5)
}
return "miniodotnet" + result.ToString();
}
// Return true if running in Mint mode
public static bool IsMintEnv()
// Return true if running in Mint mode
public static bool IsMintEnv()
{
return !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MINT_DATA_DIR"));
}
Expand Down Expand Up @@ -150,13 +151,13 @@ public static void Main(string[] args)
else
minioClient = new MinioClient(endPoint, accessKey, secretKey);

// Assign parameters before starting the test
// Assign parameters before starting the test
string bucketName = GetRandomName();
string objectName = GetRandomName();
string destBucketName = GetRandomName();
string destObjectName = GetRandomName();

// Set app Info
// Set app Info
minioClient.SetAppInfo("app-name", "app-version");
// Set HTTP Tracing On
// minioClient.SetTraceOn(new JsonNetLogger());
Expand Down Expand Up @@ -268,7 +269,7 @@ public static void Main(string[] args)
EncryptedCopyObject_Test3(minioClient).Wait();
EncryptedCopyObject_Test4(minioClient).Wait();
}

}
private static void runCoreTests(MinioClient minioClient)
{
Expand All @@ -282,7 +283,7 @@ private static void runCoreTests(MinioClient minioClient)
ListObjects_Test1(minioClient).Wait();
RemoveObject_Test1(minioClient).Wait();
CopyObject_Test1(minioClient).Wait();

// Test SetPolicyAsync function
SetBucketPolicy_Test1(minioClient).Wait();

Expand Down Expand Up @@ -318,7 +319,7 @@ private async static Task BucketExists_Test(MinioClient minio)
catch (MinioException ex)
{
new MintLogger("BucketExists_Test",bucketExistsSignature,"Tests whether BucketExists passes",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(),args).Log();
}
}
}

private async static Task MakeBucket_Test1(MinioClient minio)
Expand All @@ -342,7 +343,7 @@ private async static Task MakeBucket_Test1(MinioClient minio)
catch (MinioException ex)
{
new MintLogger("MakeBucket_Test1",makeBucketSignature,"Tests whether MakeBucket passes",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message,ex.ToString(),args).Log();
}
}
}

private async static Task MakeBucket_Test2(MinioClient minio)
Expand All @@ -368,7 +369,7 @@ private async static Task MakeBucket_Test2(MinioClient minio)
{
new MintLogger("MakeBucket_Test2",makeBucketSignature,testType,TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(),args).Log();
}

}
private async static Task MakeBucket_Test3(MinioClient minio, bool aws = false)
{
Expand Down Expand Up @@ -509,7 +510,7 @@ private async static Task PutObject_Test1(MinioClient minio)
}
}


private async static Task PutObject_Test2(MinioClient minio)
{
DateTime startTime = DateTime.Now;
Expand Down Expand Up @@ -676,7 +677,7 @@ private async static Task PutObject_Test7(MinioClient minio)
await Setup_Test(minio, bucketName);
using (System.IO.MemoryStream filestream = rsg.GenerateStreamFromSeed(10 * KB))
{

long size = -1;
long file_write_size = filestream.Length;

Expand Down Expand Up @@ -749,7 +750,7 @@ private async static Task PutGetStatEncryptedObject_Test1(MinioClient minio)
};
try
{
// Putobject with SSE-C encryption.
// Putobject with SSE-C encryption.
await Setup_Test(minio, bucketName);
Aes aesEncryption = Aes.Create();
aesEncryption.KeySize = 256;
Expand Down Expand Up @@ -1273,7 +1274,7 @@ await minio.PutObjectAsync(bucketName,
new MintLogger("CopyObject_Test5",copyObjectSignature,"Tests whether CopyObject multi-part copy upload for large files works",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(),args).Log();
}
}

}

private async static Task CopyObject_Test6(MinioClient minio)
Expand Down Expand Up @@ -1708,7 +1709,7 @@ await minio.GetObjectAsync(bucketName, objectName,
{
new MintLogger("GetObject_Test1",getObjectSignature1,"Tests whether GetObject as stream works",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(),args).Log();
}

}
private async static Task GetObject_Test2(MinioClient minio)
{
Expand Down Expand Up @@ -1742,7 +1743,7 @@ private async static Task GetObject_Test2(MinioClient minio)
{
new MintLogger("GetObject_Test2",getObjectSignature1,"Tests for non-existent GetObject",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(),args).Log();
}

}
private async static Task GetObject_Test3(MinioClient minio)
{
Expand Down Expand Up @@ -1828,7 +1829,7 @@ await minio.PutObjectAsync(bucketName,
{
new MintLogger("FGetObject_Test1",getObjectSignature3,"Tests whether FGetObject passes for small upload",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(),args).Log();
}

}

private async static Task FPutObject_Test1(MinioClient minio)
Expand Down Expand Up @@ -1919,9 +1920,10 @@ private async static Task ListObjects_Test1(MinioClient minio)
tasks[i]= PutObject_Task(minio, bucketName, objectName + i.ToString(), null, null, 0, null, rsg.GenerateStreamFromSeed(1));
}
await Task.WhenAll(tasks);

ListObjects_Test(minio, bucketName, prefix, 2,false).Wait();
System.Threading.Thread.Sleep(2000);

await minio.RemoveObjectAsync(bucketName, objectName + "0");
await minio.RemoveObjectAsync(bucketName, objectName + "1");
await TearDown(minio, bucketName);
Expand All @@ -1945,7 +1947,7 @@ private async static Task ListObjects_Test2(MinioClient minio)
{
await Setup_Test(minio, bucketName);

ListObjects_Test(minio, bucketName, null, 0).Wait(1000);
ListObjects_Test(minio, bucketName, "", 0).Wait(1000);
await TearDown(minio, bucketName);
new MintLogger("ListObjects_Test2",listObjectsSignature,"Tests whether ListObjects passes when bucket is empty",TestStatus.PASS,(DateTime.Now - startTime),args:args).Log();
}
Expand Down Expand Up @@ -1977,7 +1979,7 @@ private async static Task ListObjects_Test3(MinioClient minio)
}
await Task.WhenAll(tasks);

ListObjects_Test(minio, bucketName, prefix, 2,true).Wait();
ListObjects_Test(minio, bucketName, prefix, 2, true).Wait();
System.Threading.Thread.Sleep(2000);
await minio.RemoveObjectAsync(bucketName, objectName + "0");
await minio.RemoveObjectAsync(bucketName, objectName + "1");
Expand Down Expand Up @@ -2009,9 +2011,10 @@ private async static Task ListObjects_Test4(MinioClient minio)
tasks[i]= PutObject_Task(minio, bucketName, objectName + i.ToString(), null, null, 0, null, rsg.GenerateStreamFromSeed(1*KB));
}
await Task.WhenAll(tasks);
ListObjects_Test(minio, bucketName, null, 2,false).Wait();

ListObjects_Test(minio, bucketName, "", 2, false).Wait();
System.Threading.Thread.Sleep(2000);

await minio.RemoveObjectAsync(bucketName, objectName + "0");
await minio.RemoveObjectAsync(bucketName, objectName + "1");
await TearDown(minio, bucketName);
Expand Down Expand Up @@ -2046,8 +2049,8 @@ private async static Task ListObjects_Test5(MinioClient minio)
}
}
await Task.WhenAll(tasks);
ListObjects_Test(minio, bucketName, objectNamePrefix, numObjects,false).Wait();

ListObjects_Test(minio, bucketName, objectNamePrefix, numObjects, false).Wait();
System.Threading.Thread.Sleep(5000);
for(int index=1; index <= numObjects; index++)
{
Expand Down Expand Up @@ -2366,7 +2369,7 @@ await minio.PutObjectAsync(bucketName,
new MintLogger("PresignedPutObject_Test2",presignedPutObjectSignature,"Tests whether PresignedPutObject url retrieves object from bucket when invalid expiry is set.",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(),args).Log();
}
}

private static async Task UploadObjectAsync(string url, string filePath)
{
HttpWebRequest httpRequest = WebRequest.Create(url) as HttpWebRequest;
Expand Down Expand Up @@ -2408,7 +2411,7 @@ private async static Task PresignedPostPolicy_Test1(MinioClient minio)
await Setup_Test(minio, bucketName);
await minio.PutObjectAsync(bucketName,
objectName,
fileName);
fileName);
var pairs = new List<KeyValuePair<string, string>>();
string url = "https://s3.amazonaws.com/" + bucketName;
Tuple<string, System.Collections.Generic.Dictionary<string, string>> policyTuple = await minio.PresignedPostPolicyAsync(form);
Expand Down Expand Up @@ -2479,7 +2482,7 @@ await minio.PutObjectAsync(bucketName,

IDisposable subscription = observable.Subscribe(
item => Assert.AreEqual(item.Key, objectName),
ex => Assert.Fail());
ex => Assert.Fail());

await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
}
Expand All @@ -2500,7 +2503,7 @@ private async static Task ListIncompleteUpload_Test2(MinioClient minio)
{
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(15);
string prefix = "minioprefix/";
string prefix = "minioprefix/";
string objectName = prefix + GetRandomName(10);
string contentType = "gzip";
Dictionary<string,string> args = new Dictionary<string,string>
Expand Down Expand Up @@ -2529,11 +2532,11 @@ await minio.PutObjectAsync(bucketName,
}
catch (OperationCanceledException)
{
IObservable<Upload> observable = minio.ListIncompleteUploads(bucketName,"minioprefix",false);
IObservable<Upload> observable = minio.ListIncompleteUploads(bucketName, "minioprefix", false);

IDisposable subscription = observable.Subscribe(
item => Assert.AreEqual(item.Key, objectName),
ex => Assert.Fail());
ex => Assert.Fail());

await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
}
Expand Down Expand Up @@ -2579,11 +2582,11 @@ await minio.PutObjectAsync(bucketName,
}
catch (OperationCanceledException)
{
IObservable<Upload> observable = minio.ListIncompleteUploads(bucketName,prefix,true);
IObservable<Upload> observable = minio.ListIncompleteUploads(bucketName, prefix, true);

IDisposable subscription = observable.Subscribe(
item => Assert.AreEqual(item.Key, objectName),
ex => Assert.Fail());
ex => Assert.Fail());

await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
}
Expand Down Expand Up @@ -2633,7 +2636,7 @@ await minio.PutObjectAsync(bucketName,

IDisposable subscription = observable.Subscribe(
item => Assert.Fail(),
ex => Assert.Fail());
ex => Assert.Fail());
}
await TearDown(minio, bucketName);
new MintLogger("RemoveIncompleteUpload_Test",removeIncompleteUploadSignature,"Tests whether RemoveIncompleteUpload passes.",TestStatus.PASS,(DateTime.Now - startTime), args:args).Log();
Expand Down
Loading

0 comments on commit aa8e0f6

Please sign in to comment.