Skip to content

[SDK-531] add v4 support and uts #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ecs-object-client-dotnet-test/ECSSDK.Test.BucketTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void Initialize(TestContext testContext)
{
ForcePathStyle = true,
ServiceURL = ConfigurationManager.AppSettings["S3_ENDPOINT"],
SignatureVersion = "2",
SignatureVersion = ConfigurationManager.AppSettings["SIGNATURE_VERSION"],
SignatureMethod = SigningAlgorithm.HmacSHA1,
UseHttp = false,
};
Expand Down
2 changes: 1 addition & 1 deletion ecs-object-client-dotnet-test/ECSSDK.Test.MDSearchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void Initialize(TestContext testContext)
{
ForcePathStyle = true,
ServiceURL = ConfigurationManager.AppSettings["S3_ENDPOINT"],
SignatureVersion = "2",
SignatureVersion = ConfigurationManager.AppSettings["SIGNATURE_VERSION"],
SignatureMethod = SigningAlgorithm.HmacSHA1,
UseHttp = false,
};
Expand Down
47 changes: 40 additions & 7 deletions ecs-object-client-dotnet-test/ECSSDK.Test.ObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void Initialize(TestContext testContext)
{
ForcePathStyle = true,
ServiceURL = ConfigurationManager.AppSettings["S3_ENDPOINT"],
SignatureVersion = "2",
SignatureVersion = ConfigurationManager.AppSettings["SIGNATURE_VERSION"],
SignatureMethod = SigningAlgorithm.HmacSHA1,
UseHttp = false,
};
Expand Down Expand Up @@ -147,6 +147,14 @@ public void TestUpdateObjectWithRange()
// update the object
client.PutObject(por);

GetObjectResponse respone = client.GetObject(temp_bucket, key);
Stream responeStream = respone.ResponseStream;
StreamReader reader1 = new StreamReader(responeStream);
string readContent1 = reader1.ReadToEnd();

Assert.AreEqual(content.Length, readContent1.Length);
Assert.AreEqual("The dog crossed the road.", readContent1);

// verify update
GetObjectResponse response = client.GetObject(temp_bucket, key);
Stream responseStream = response.ResponseStream;
Expand Down Expand Up @@ -436,13 +444,13 @@ public void TestObjectWithMetadata()

por.Metadata.Add("555", "55555");
por.Metadata.Add("bbb", "bbbbb");
por.Metadata.Add("b_b_b", "bubub");
//Invalid, v4 not supported por.Metadata.Add("b_b_b", "bubub");
por.Metadata.Add("aaa", "aaaaa");
por.Metadata.Add("b-b-b", "bdbdbd");
por.Metadata.Add("a_a_a", "auaua");
//Invalid, v4 not supported por.Metadata.Add("a_a_a", "auaua");
por.Metadata.Add("111", "11111");
por.Metadata.Add("a-a-a", "adadad");
por.Metadata.Add("a^a^a", "acacac");
//Invalid, v4 not supported por.Metadata.Add("a^a^a", "acacac");
por.Metadata.Add("a|a|a", "apapap");

PutObjectResponse response = client.PutObject(por);
Expand Down Expand Up @@ -512,9 +520,9 @@ public void TestObjectWithMetadata()
//Invalid, not supported [DataRow(91)]
//Invalid, not supported [DataRow(92)]
//Invalid, not supported [DataRow(93)]
[DataRow(94)]
[DataRow(95)]
[DataRow(96)]
//Invalid, v4 not supported [DataRow(94)]
//Invalid, v4 not supported [DataRow(95)]
//Invalid, v4 not supported [DataRow(96)]
[DataRow(97)]
[DataRow(98)]
[DataRow(99)]
Expand Down Expand Up @@ -565,5 +573,30 @@ public void TestObjectMetadataAscii(int asciiCharacter)
Assert.AreEqual(response.HttpStatusCode, System.Net.HttpStatusCode.OK,
string.Format("Issue with character: {0}", asciiCharacter));
}

[TestMethod]
public void TestPutObject()
{
string key = "key-1";
string content = "TestPutObject";

PutObjectRequestECS por = new PutObjectRequestECS()
{
BucketName = temp_bucket,
Key = key,
ContentBody = content
};

// create the object
client.PutObject(por);

GetObjectResponse respone = client.GetObject(temp_bucket, key);
Stream responeStream = respone.ResponseStream;
StreamReader reader = new StreamReader(responeStream);
string readContent = reader.ReadToEnd();

Assert.AreEqual(content.Length, readContent.Length);
Assert.AreEqual("TestPutObject", readContent);
}
}
}
11 changes: 6 additions & 5 deletions ecs-object-client-dotnet-test/app.config
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="S3_ACCESS_KEY_ID" value="" />
<add key="S3_SECRET_KEY" value="" />
<add key="S3_ENDPOINT" value="" />
<add key="ECS_NAMESPACE" value="" />
<add key="VPOOL_ID" value="" />
<add key="S3_ACCESS_KEY_ID" value="" />
<add key="S3_SECRET_KEY" value="" />
<add key="S3_ENDPOINT" value="" />
<add key="ECS_NAMESPACE" value="" />
<add key="VPOOL_ID" value="" />
<add key="SIGNATURE_VERSION" value="" />
</appSettings>
</configuration>
5 changes: 4 additions & 1 deletion ecs-object-client-dotnet/Internal/S3SignerECS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public override void Sign(IRequest request, IClientConfig clientConfig, RequestM

if (useV4)
{
throw new ArgumentException("Use of AWS V4 signature is not supported in this library.");
var signingResult = aws4Signer.SignRequest(request, clientConfig, metrics, awsAccessKeyId, awsSecretAccessKey);
request.Headers[HeaderKeys.AuthorizationHeader] = signingResult.ForAuthorizationHeader;
if (request.UseChunkEncoding)
request.AWS4SignerResult = signingResult;
}
else
SignRequest(request, metrics, awsAccessKeyId, awsSecretAccessKey);
Expand Down