Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticFiasco committed Nov 5, 2023
1 parent 61a6016 commit 3a3c48a
Show file tree
Hide file tree
Showing 46 changed files with 1,493 additions and 1,425 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ indent_size = 2

[*.{yaml,yml}]
indent_size = 2

[*.{authz,creq,req,sreq,sts}]
insert_final_newline = false
11 changes: 0 additions & 11 deletions test/Integration/ApiGateway/ApiGatewayIntegrationBase.cs

This file was deleted.

99 changes: 52 additions & 47 deletions test/Integration/ApiGateway/AwsSignatureHandlerShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,37 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using AwsSignatureVersion4.Integration.ApiGateway.Authentication;
using AwsSignatureVersion4.Integration.ApiGateway.Fixtures;
using AwsSignatureVersion4.Integration.ApiGateway.Requests;
using AwsSignatureVersion4.Private;
using AwsSignatureVersion4.TestSuite;
using AwsSignatureVersion4.TestSuite.Fixtures;
using Shouldly;
using Xunit;

namespace AwsSignatureVersion4.Integration.ApiGateway
{
[Collection("API Gateway")]
public class AwsSignatureHandlerShould : ApiGatewayIntegrationBase, IClassFixture<TestSuiteContext>
[Trait("Category", "Integration")]
public class AwsSignatureHandlerShould
{
private readonly TestSuiteContext testSuiteContext;

public AwsSignatureHandlerShould(IntegrationTestContext context, TestSuiteContext testSuiteContext)
: base(context)
private readonly Func<IamAuthenticationType, string, string, IHttpClientFactory> httpClientFactoryProvider;
private readonly string region;
private readonly string serviceName;
private readonly string apiGatewayUrl;

private readonly Func<string[], Scenario> loadScenario;
private readonly Func<HttpRequestMessage, string, HttpRequestMessage> redirectRequest;

public AwsSignatureHandlerShould(ApiGatewayFixture apiGatewayFixture, TestSuiteFixture testSuiteFixture)
{
this.testSuiteContext = testSuiteContext;
httpClientFactoryProvider = apiGatewayFixture.HttpClientFactory;
region = apiGatewayFixture.Region.SystemName;
serviceName = apiGatewayFixture.ServiceName;
apiGatewayUrl = apiGatewayFixture.ApiGatewayUrl;

loadScenario = testSuiteFixture.LoadScenario;
redirectRequest = testSuiteFixture.RedirectRequest;
}

public static IEnumerable<object[]> TestCases =>
Expand Down Expand Up @@ -73,8 +86,10 @@ public AwsSignatureHandlerShould(IntegrationTestContext context, TestSuiteContex
public async Task PassTestSuiteGivenUserWithPermissions(params string[] scenarioName)
{
// Arrange
using var httpClient = HttpClientFactory(IamAuthenticationType.User).CreateClient("integration");
var request = BuildRequest(scenarioName);
var scenario = loadScenario(scenarioName);
var request = redirectRequest(scenario.Request, apiGatewayUrl);
var httpClientFactory = httpClientFactoryProvider(IamAuthenticationType.User, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");

// Act
var response = await httpClient.SendAsync(request);
Expand Down Expand Up @@ -118,8 +133,10 @@ public async Task PassTestSuiteGivenUserWithPermissions(params string[] scenario
public async Task PassTestSuiteGivenAssumedRole(params string[] scenarioName)
{
// Arrange
using var httpClient = HttpClientFactory(IamAuthenticationType.Role).CreateClient("integration");
var request = BuildRequest(scenarioName);
var scenario = loadScenario(scenarioName);
var request = redirectRequest(scenario.Request, apiGatewayUrl);
var httpClientFactory = httpClientFactoryProvider(IamAuthenticationType.Role, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");

// Act
var response = await httpClient.SendAsync(request);
Expand All @@ -135,9 +152,10 @@ public async Task SucceedGivenPath(
HttpMethod method)
{
// Arrange
using var httpClient = HttpClientFactory(iamAuthenticationType).CreateClient("integration");
var httpClientFactory = httpClientFactoryProvider(iamAuthenticationType, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");
var path = "/path";
var request = new HttpRequestMessage(method, Context.ApiGatewayUrl + path);
var request = new HttpRequestMessage(method, apiGatewayUrl + path);

// Act
var response = await httpClient.SendAsync(request);
Expand All @@ -159,8 +177,9 @@ public async Task SucceedGivenHeaderWithDuplicateValues(
HttpMethod method)
{
// Arrange
using var httpClient = HttpClientFactory(iamAuthenticationType).CreateClient("integration");
var request = new HttpRequestMessage(method, Context.ApiGatewayUrl);
var httpClientFactory = httpClientFactoryProvider(iamAuthenticationType, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");
var request = new HttpRequestMessage(method, apiGatewayUrl);
request.AddHeaders("My-Header1", new[] { "value2", "value2" });

// Act
Expand All @@ -184,8 +203,9 @@ public async Task SucceedGivenHeaderWithUnorderedValues(
HttpMethod method)
{
// Arrange
using var httpClient = HttpClientFactory(iamAuthenticationType).CreateClient("integration");
var request = new HttpRequestMessage(method, Context.ApiGatewayUrl);
var httpClientFactory = httpClientFactoryProvider(iamAuthenticationType, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");
var request = new HttpRequestMessage(method, apiGatewayUrl);
request.AddHeaders("My-Header1", new[] { "value4", "value1", "value3", "value2" });

// Act
Expand All @@ -209,8 +229,9 @@ public async Task SucceedGivenHeaderWithWhitespaceCharacters(
HttpMethod method)
{
// Arrange
using var httpClient = HttpClientFactory(iamAuthenticationType).CreateClient("integration");
var request = new HttpRequestMessage(method, Context.ApiGatewayUrl);
var httpClientFactory = httpClientFactoryProvider(iamAuthenticationType, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");
var request = new HttpRequestMessage(method, apiGatewayUrl);
request.AddHeaders("My-Header1", new[] { "value1", "a b c" });

// Act
Expand All @@ -234,9 +255,10 @@ public async Task SucceedGivenQuery(
HttpMethod method)
{
// Arrange
using var httpClient = HttpClientFactory(iamAuthenticationType).CreateClient("integration");
var httpClientFactory = httpClientFactoryProvider(iamAuthenticationType, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");

var uriBuilder = new UriBuilder(Context.ApiGatewayUrl)
var uriBuilder = new UriBuilder(apiGatewayUrl)
{
Query = "Param1=Value1"
};
Expand All @@ -263,9 +285,10 @@ public async Task SucceedGivenOrderedQuery(
HttpMethod method)
{
// Arrange
using var httpClient = HttpClientFactory(iamAuthenticationType).CreateClient("integration");
var httpClientFactory = httpClientFactoryProvider(iamAuthenticationType, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");

var uriBuilder = new UriBuilder(Context.ApiGatewayUrl)
var uriBuilder = new UriBuilder(apiGatewayUrl)
{
Query = "Param1=Value1&Param1=Value2"
};
Expand All @@ -292,9 +315,10 @@ public async Task SucceedGivenUnorderedQuery(
HttpMethod method)
{
// Arrange
using var httpClient = HttpClientFactory(iamAuthenticationType).CreateClient("integration");
var httpClientFactory = httpClientFactoryProvider(iamAuthenticationType, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");

var uriBuilder = new UriBuilder(Context.ApiGatewayUrl)
var uriBuilder = new UriBuilder(apiGatewayUrl)
{
Query = "Param1=Value2&Param1=Value1"
};
Expand All @@ -321,8 +345,9 @@ public async Task SucceedGivenHttpCompletionOption(
HttpMethod method)
{
// Arrange
using var httpClient = HttpClientFactory(iamAuthenticationType).CreateClient("integration");
var request = new HttpRequestMessage(method, Context.ApiGatewayUrl);
var httpClientFactory = httpClientFactoryProvider(iamAuthenticationType, region, serviceName);
using var httpClient = httpClientFactory.CreateClient("integration");
var request = new HttpRequestMessage(method, apiGatewayUrl);
var completionOption = HttpCompletionOption.ResponseContentRead;

// Act
Expand All @@ -337,25 +362,5 @@ public async Task SucceedGivenHttpCompletionOption(
receivedRequest.QueryStringParameters.ShouldBeNull();
receivedRequest.Body.ShouldBeNull();
}

private HttpRequestMessage BuildRequest(string[] scenarioName)
{
var request = testSuiteContext.LoadScenario(scenarioName).Request;

if (request.RequestUri == null) throw new Exception("Test suite request URI cannot be null");

// Redirect the request to the AWS API Gateway
request.RequestUri = request.RequestUri
.ToString()
.Replace("https://example.amazonaws.com", Context.ApiGatewayUrl)
.ToUri();

// The "Host" header is now invalid since we redirected the request to the AWS API
// Gateway. Lets remove the header and have the signature implementation re-add it
// correctly.
request.Headers.Remove("Host");

return request;
}
}
}
Loading

0 comments on commit 3a3c48a

Please sign in to comment.