Skip to content

Commit

Permalink
Changing to Ordinal sort and lowercasing all keys in separate diction…
Browse files Browse the repository at this point in the history
…ary first. All supported ascii keys working now. (#5)
  • Loading branch information
ben-schumacher authored Apr 17, 2019
1 parent ba62f95 commit 7fa34d8
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 12 deletions.
120 changes: 120 additions & 0 deletions ecs-object-client-dotnet-test/ECSSDK.Test.ObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,132 @@ public void TestObjectWithMetadata()
por.Metadata.Add("bbb", "bbbbb");
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");
por.Metadata.Add("111", "11111");
por.Metadata.Add("a-a-a", "adadad");
por.Metadata.Add("a^a^a", "acacac");
por.Metadata.Add("a|a|a", "apapap");

PutObjectResponse response = client.PutObject(por);
Assert.AreEqual(response.HttpStatusCode, System.Net.HttpStatusCode.OK);

}

[DataTestMethod]
[DataRow(33)]
//Invalid, not supported [DataRow(34)]
[DataRow(35)]
[DataRow(36)]
[DataRow(37)]
[DataRow(38)]
//Invalid, not supported [DataRow(39)]
//Invalid, not supported [DataRow(40)]
//Invalid, not supported [DataRow(41)]
[DataRow(42)]
[DataRow(43)]
//Invalid, not supported [DataRow(44)]
[DataRow(45)]
[DataRow(46)]
//Invalid, not supported [DataRow(47)]
[DataRow(48)]
[DataRow(49)]
[DataRow(50)]
[DataRow(51)]
[DataRow(52)]
[DataRow(53)]
[DataRow(54)]
[DataRow(55)]
[DataRow(56)]
[DataRow(57)]
//Invalid, not supported [DataRow(58)]
//Invalid, not supported [DataRow(59)]
//Invalid, not supported [DataRow(60)]
//Invalid, not supported [DataRow(61)]
//Invalid, not supported [DataRow(62)]
//Invalid, not supported [DataRow(63)]
//Invalid, not supported [DataRow(64)]
[DataRow(65)]
[DataRow(66)]
[DataRow(67)]
[DataRow(68)]
[DataRow(69)]
[DataRow(70)]
[DataRow(71)]
[DataRow(72)]
[DataRow(73)]
[DataRow(74)]
[DataRow(75)]
[DataRow(76)]
[DataRow(77)]
[DataRow(78)]
[DataRow(79)]
[DataRow(80)]
[DataRow(81)]
[DataRow(82)]
[DataRow(83)]
[DataRow(84)]
[DataRow(85)]
[DataRow(86)]
[DataRow(87)]
[DataRow(88)]
[DataRow(89)]
[DataRow(90)]
//Invalid, not supported [DataRow(91)]
//Invalid, not supported [DataRow(92)]
//Invalid, not supported [DataRow(93)]
[DataRow(94)]
[DataRow(95)]
[DataRow(96)]
[DataRow(97)]
[DataRow(98)]
[DataRow(99)]
[DataRow(100)]
[DataRow(101)]
[DataRow(102)]
[DataRow(103)]
[DataRow(104)]
[DataRow(105)]
[DataRow(106)]
[DataRow(107)]
[DataRow(108)]
[DataRow(109)]
[DataRow(110)]
[DataRow(111)]
[DataRow(112)]
[DataRow(113)]
[DataRow(114)]
[DataRow(115)]
[DataRow(116)]
[DataRow(117)]
[DataRow(118)]
[DataRow(119)]
[DataRow(120)]
[DataRow(121)]
[DataRow(122)]
//Invalid, not supported [DataRow(123)]
[DataRow(124)]
//Invalid, not supported [DataRow(125)]
[DataRow(126)]
//Invalid, not supported [DataRow(127)]
public void TestObjectMetadataAscii(int asciiCharacter)
{
string key = "meta-1";
string content = "sample object data content ...";

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

por.Metadata.Add("aaa", "aaaaa");
por.Metadata.Add("a_a_a".Replace("_", ((char)asciiCharacter).ToString()), "trick");

PutObjectResponse response = client.PutObject(por);
Assert.AreEqual(response.HttpStatusCode, System.Net.HttpStatusCode.OK,
string.Format("Issue with character: {0}", asciiCharacter));
}
}
}
23 changes: 18 additions & 5 deletions ecs-object-client-dotnet-test/ECSSDK.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -16,6 +17,8 @@
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -43,6 +46,12 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\AWSSDK.S3.3.3.7\lib\net45\AWSSDK.S3.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
</ItemGroup>
Expand All @@ -52,11 +61,7 @@
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="ECSSDK.Test.BucketTest.cs" />
Expand Down Expand Up @@ -100,6 +105,14 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 2 additions & 0 deletions ecs-object-client-dotnet-test/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<packages>
<package id="AWSSDK.Core" version="3.3.14.2" targetFramework="net45" />
<package id="AWSSDK.S3" version="3.3.7" targetFramework="net45" />
<package id="MSTest.TestAdapter" version="1.4.0" targetFramework="net45" />
<package id="MSTest.TestFramework" version="1.4.0" targetFramework="net45" />
</packages>
19 changes: 12 additions & 7 deletions ecs-object-client-dotnet/Internal/S3SignerECS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,22 @@ static string BuildStringToSign(IRequest request)

static string BuildCanonicalizedHeaders(IDictionary<string, string> headers)
{
var sb = new StringBuilder(256);
foreach (var key in headers.Keys.OrderBy(x => x, StringComparer.InvariantCultureIgnoreCase))
IDictionary<string, string> canonicalizedAmzHeaders =
new Dictionary<string, string>();
foreach (var item in headers)
{
var lowerKey = key.ToLowerInvariant();
if (!lowerKey.StartsWith("x-amz-", StringComparison.Ordinal) &&
var lowerKey = item.Key.ToLowerInvariant();
if (!lowerKey.StartsWith("x-amz-", StringComparison.Ordinal) &&
!lowerKey.StartsWith("x-emc-", StringComparison.Ordinal))
continue;

sb.Append(String.Concat(lowerKey, ":", headers[key], "\n"));
canonicalizedAmzHeaders.Add(lowerKey, item.Key);
}
var sb = new StringBuilder(256);
foreach (var key in canonicalizedAmzHeaders.Keys.OrderBy(x => x, StringComparer.Ordinal))
{
var pointer = canonicalizedAmzHeaders[key];
sb.Append(String.Concat(key, ":", headers[pointer], "\n"));
}

return sb.ToString();
}

Expand Down

0 comments on commit 7fa34d8

Please sign in to comment.