Skip to content

Commit

Permalink
Retain custom uri port.
Browse files Browse the repository at this point in the history
  • Loading branch information
klementi authored and dscpinheiro committed Oct 26, 2022
1 parent 5fc4b13 commit c4a108e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public virtual void ProcessRequestHandlers(IExecutionContext executionContext)
var uriBuilder = new UriBuilder(requestContext.Request.Endpoint)
{
Scheme = Uri.UriSchemeHttp,
Port = -1 // default port for scheme
Port = requestContext.Request.Endpoint.IsDefaultPort ? -1 : requestContext.Request.Endpoint.Port
};
requestContext.Request.Endpoint = uriBuilder.Uri;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@

<ItemGroup>
<Compile Remove="**\**" />
<Compile Include="EndpointsTests.cs" />
<Compile Include="EndpointsStandardLibraryTests.cs" />
<Compile Include="Runtime\DeprecatedCodeTest.cs" />
<Compile Include="Runtime\EC2InstanceMetadataServlet.cs" />
<Compile Include="Runtime\HttpHandlerTests.cs" />
<Compile Include="Mocking\TestUtils.cs" />
<Compile Include="Runtime\MockAmazonWebServiceRequest.cs" />
<Compile Include="Runtime\MockClientConfig.cs" />
<Compile Include="Utils.cs" />
<Compile Include="ConstantClassTestBase.cs" />
<Compile Include="CapacityManagerTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
<ItemGroup>
<Compile Remove="**\**" />
<Compile Include="EndpointsStandardLibraryTests.cs" />
<Compile Include="EndpointsTests.cs" />
<Compile Include="Mocking\TestUtils.cs" />
<Compile Include="Runtime\DeprecatedCodeTest.cs" />
<Compile Include="Runtime\EC2InstanceMetadataServlet.cs" />
<Compile Include="Runtime\HttpHandlerTests.cs" />
<Compile Include="Runtime\MockAmazonWebServiceRequest.cs" />
<Compile Include="Runtime\MockClientConfig.cs" />
<Compile Include="Runtime\MockFileSystem.cs" />
<Compile Include="Runtime\TerminatePipeline.cs" />
Expand Down
55 changes: 55 additions & 0 deletions sdk/test/UnitTests/Custom/EndpointsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
using Amazon.Runtime.Endpoints;
using Amazon.Runtime.Internal;
using Amazon.Runtime.Internal.Auth;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AWSSDK.UnitTests
{
[TestClass]
public class EndpointsTests
{
public class TestEndpointProvider : IEndpointProvider
{
public Endpoint ResolveEndpoint(EndpointParameters parameters)
{
return new Endpoint("https://localhost:7777");
}
}

[TestMethod]
[TestCategory("Endpoints")]
public void EndpointResolverRetainsUriPortNumberWhenHttpIsEnforced()
{
var config = new MockClientConfig
{
EndpointProvider = new TestEndpointProvider(),
UseHttp = true
};
var requestContext = new RequestContext(false, new NullSigner())
{
ClientConfig = config,
Request = new DefaultRequest(new MockAmazonWebServiceRequest(), "test-service")
};
var executionContext = new ExecutionContext(requestContext, null);
var resolver = new BaseEndpointResolver();
resolver.ProcessRequestHandlers(executionContext);
var endpoint = executionContext.RequestContext.Request.Endpoint;
Assert.AreEqual(7777, endpoint.Port);
Assert.AreEqual("http", endpoint.Scheme);
}
}
}
23 changes: 23 additions & 0 deletions sdk/test/UnitTests/Custom/Runtime/MockAmazonWebServiceRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using Amazon.Runtime;

namespace AWSSDK.UnitTests
{
public class MockAmazonWebServiceRequest : AmazonWebServiceRequest
{
}
}

0 comments on commit c4a108e

Please sign in to comment.