Skip to content
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

Add logging to Http.Sys tests #50883

Merged
merged 1 commit into from
Sep 22, 2023
Merged
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
34 changes: 17 additions & 17 deletions src/Servers/HttpSys/test/FunctionalTests/AuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Microsoft.AspNetCore.Server.HttpSys;

public class AuthenticationTests
public class AuthenticationTests : LoggedTest
{
private static bool AllowAnoymous = true;
private static bool DenyAnoymous = false;
Expand All @@ -33,7 +33,7 @@ public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationSchemes aut
Assert.NotNull(httpContext.User.Identity);
Assert.False(httpContext.User.Identity.IsAuthenticated);
return Task.FromResult(0);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -51,7 +51,7 @@ public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes aut
using (var server = Utilities.CreateDynamicHost(authType, DenyAnoymous, out var address, httpContext =>
{
throw new NotImplementedException();
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Expand All @@ -73,7 +73,7 @@ public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(Authentic
Assert.False(httpContext.User.Identity.IsAuthenticated);
httpContext.Response.StatusCode = 401;
return Task.FromResult(0);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Expand All @@ -99,7 +99,7 @@ public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded(
Assert.False(httpContext.User.Identity.IsAuthenticated);
httpContext.Response.StatusCode = 401;
return Task.FromResult(0);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Expand Down Expand Up @@ -135,7 +135,7 @@ public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationSc
}
requestId++;
return Task.FromResult(0);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address, useDefaultCredentials: true);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -156,7 +156,7 @@ public async Task AuthTypes_RequireAuth_Success(AuthenticationSchemes authType)
Assert.NotNull(httpContext.User.Identity);
Assert.True(httpContext.User.Identity.IsAuthenticated);
return Task.FromResult(0);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address, useDefaultCredentials: true);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -182,7 +182,7 @@ public async Task AuthTypes_AccessUserInOnCompleted_Success()
return Task.CompletedTask;
});
return Task.FromResult(0);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address, useDefaultCredentials: true);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -208,7 +208,7 @@ public async Task AuthTypes_AuthenticateWithNoUser_NoResults(AuthenticationSchem
var authResults = await httpContext.AuthenticateAsync(HttpSysDefaults.AuthenticationScheme);
Assert.False(authResults.Succeeded);
Assert.True(authResults.None);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -231,7 +231,7 @@ public async Task AuthTypes_AuthenticateWithUser_OneResult(AuthenticationSchemes
Assert.True(httpContext.User.Identity.IsAuthenticated);
var authResults = await httpContext.AuthenticateAsync(HttpSysDefaults.AuthenticationScheme);
Assert.True(authResults.Succeeded);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address, useDefaultCredentials: true);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -253,7 +253,7 @@ public async Task AuthTypes_ChallengeWithoutAuthTypes_AllChallengesSent(Authenti
Assert.NotNull(httpContext.User.Identity);
Assert.False(httpContext.User.Identity.IsAuthenticated);
return httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Expand All @@ -276,7 +276,7 @@ public async Task AuthTypes_ChallengeWithAllAuthTypes_AllChallengesSent(Authenti
Assert.NotNull(httpContext.User.Identity);
Assert.False(httpContext.User.Identity.IsAuthenticated);
await httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Expand All @@ -294,7 +294,7 @@ public async Task AuthTypes_OneChallengeSent()
Assert.NotNull(httpContext.User.Identity);
Assert.False(httpContext.User.Identity.IsAuthenticated);
return httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Expand All @@ -320,7 +320,7 @@ public async Task AuthTypes_ChallengeWillAskForAllEnabledSchemes(AuthenticationS
Assert.NotNull(httpContext.User.Identity);
Assert.False(httpContext.User.Identity.IsAuthenticated);
return httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Expand All @@ -338,7 +338,7 @@ public async Task AuthTypes_Forbid_Forbidden()
Assert.NotNull(httpContext.User.Identity);
Assert.False(httpContext.User.Identity.IsAuthenticated);
return httpContext.ForbidAsync(HttpSysDefaults.AuthenticationScheme);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
Expand All @@ -359,7 +359,7 @@ public async Task AuthTypes_UnathorizedAuthenticatedAuthType_Unauthorized(Authen
Assert.NotNull(httpContext.User.Identity);
Assert.True(httpContext.User.Identity.IsAuthenticated);
return httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme, null);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address, useDefaultCredentials: true);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Expand Down Expand Up @@ -393,7 +393,7 @@ public async Task AuthTypes_DisableAutomaticAuthentication(AuthenticationSchemes
Assert.NotNull(authenticateResult.Principal);
Assert.NotNull(authenticateResult.Principal.Identity);
Assert.True(authenticateResult.Principal.Identity.IsAuthenticated);
}))
}, LoggerFactory))
{
var response = await SendRequestAsync(address, useDefaultCredentials: true);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand Down
30 changes: 15 additions & 15 deletions src/Servers/HttpSys/test/FunctionalTests/DelegateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Microsoft.AspNetCore.Server.HttpSys.FunctionalTests;

public class DelegateTests
public class DelegateTests : LoggedTest
{
private static readonly string _expectedResponseString = "Hello from delegatee";

Expand Down Expand Up @@ -44,7 +44,7 @@ public async Task DelegateRequestTest()
options =>
{
options.RequestQueueName = queueName;
});
}, LoggerFactory);

DelegationRule destination = default;

Expand All @@ -53,7 +53,7 @@ public async Task DelegateRequestTest()
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
delegateFeature.DelegateRequest(destination);
return Task.CompletedTask;
});
}, LoggerFactory);

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
Expand All @@ -76,7 +76,7 @@ public async Task DelegateAfterWriteToResponseBodyShouldThrowTest()
options =>
{
options.RequestQueueName = queueName;
});
}, LoggerFactory);

DelegationRule destination = default;

Expand All @@ -86,7 +86,7 @@ public async Task DelegateAfterWriteToResponseBodyShouldThrowTest()
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
Assert.False(delegateFeature.CanDelegate);
Assert.Throws<InvalidOperationException>(() => delegateFeature.DelegateRequest(destination));
});
}, LoggerFactory);

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
Expand All @@ -108,7 +108,7 @@ public async Task WriteToBodyAfterDelegateShouldNoOp()
options =>
{
options.RequestQueueName = queueName;
});
}, LoggerFactory);

DelegationRule destination = default;

Expand All @@ -119,7 +119,7 @@ public async Task WriteToBodyAfterDelegateShouldNoOp()
Assert.False(delegateFeature.CanDelegate);
httpContext.Response.WriteAsync(_expectedResponseString);
return Task.CompletedTask;
});
}, LoggerFactory);

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
Expand All @@ -142,7 +142,7 @@ public async Task DelegateAfterRequestBodyReadShouldThrow()
options =>
{
options.RequestQueueName = queueName;
});
}, LoggerFactory);

DelegationRule destination = default;

Expand All @@ -152,7 +152,7 @@ public async Task DelegateAfterRequestBodyReadShouldThrow()
await httpContext.Request.Body.CopyToAsync(memoryStream);
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
Assert.Throws<InvalidOperationException>(() => delegateFeature.DelegateRequest(destination));
});
}, LoggerFactory);

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
Expand All @@ -173,7 +173,7 @@ public async Task DelegationFeaturesAreNull()
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
Assert.Null(delegateFeature);
return Task.CompletedTask;
});
}, LoggerFactory);

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
Assert.Null(delegationProperty);
Expand All @@ -193,7 +193,7 @@ public async Task UpdateDelegationRuleTest()
options =>
{
options.RequestQueueName = queueName;
});
}, LoggerFactory);

DelegationRule destination = default;

Expand All @@ -202,7 +202,7 @@ public async Task UpdateDelegationRuleTest()
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
delegateFeature.DelegateRequest(destination);
return Task.CompletedTask;
});
}, LoggerFactory);

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
Expand All @@ -227,15 +227,15 @@ public async Task DelegateAfterReceiverRestart()
options =>
{
options.RequestQueueName = queueName;
});
}, LoggerFactory);

DelegationRule destination = default;
using var delegator = Utilities.CreateHttpServer(out var delegatorAddress, httpContext =>
{
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
delegateFeature.DelegateRequest(destination);
return Task.CompletedTask;
});
}, LoggerFactory);

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
Expand All @@ -257,7 +257,7 @@ public async Task DelegateAfterReceiverRestart()
options.RequestQueueMode = RequestQueueMode.CreateOrAttach;
options.UrlPrefixes.Clear();
options.UrlPrefixes.Add(receiverAddress);
});
}, LoggerFactory);

responseString = await SendRequestAsync(delegatorAddress);
Assert.Equal(_expectedResponseString, responseString);
Expand Down
Loading
Loading