Skip to content

Commit a0b6b5f

Browse files
Add logging to Http.Sys tests (#50883)
1 parent 2fce01d commit a0b6b5f

19 files changed

+316
-292
lines changed

src/Servers/HttpSys/test/FunctionalTests/AuthenticationTests.cs

+17-17
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.AspNetCore.Server.HttpSys;
1515

16-
public class AuthenticationTests
16+
public class AuthenticationTests : LoggedTest
1717
{
1818
private static bool AllowAnoymous = true;
1919
private static bool DenyAnoymous = false;
@@ -33,7 +33,7 @@ public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationSchemes aut
3333
Assert.NotNull(httpContext.User.Identity);
3434
Assert.False(httpContext.User.Identity.IsAuthenticated);
3535
return Task.FromResult(0);
36-
}))
36+
}, LoggerFactory))
3737
{
3838
var response = await SendRequestAsync(address);
3939
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -51,7 +51,7 @@ public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes aut
5151
using (var server = Utilities.CreateDynamicHost(authType, DenyAnoymous, out var address, httpContext =>
5252
{
5353
throw new NotImplementedException();
54-
}))
54+
}, LoggerFactory))
5555
{
5656
var response = await SendRequestAsync(address);
5757
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
@@ -73,7 +73,7 @@ public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(Authentic
7373
Assert.False(httpContext.User.Identity.IsAuthenticated);
7474
httpContext.Response.StatusCode = 401;
7575
return Task.FromResult(0);
76-
}))
76+
}, LoggerFactory))
7777
{
7878
var response = await SendRequestAsync(address);
7979
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
@@ -99,7 +99,7 @@ public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded(
9999
Assert.False(httpContext.User.Identity.IsAuthenticated);
100100
httpContext.Response.StatusCode = 401;
101101
return Task.FromResult(0);
102-
}))
102+
}, LoggerFactory))
103103
{
104104
var response = await SendRequestAsync(address);
105105
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
@@ -135,7 +135,7 @@ public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationSc
135135
}
136136
requestId++;
137137
return Task.FromResult(0);
138-
}))
138+
}, LoggerFactory))
139139
{
140140
var response = await SendRequestAsync(address, useDefaultCredentials: true);
141141
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -156,7 +156,7 @@ public async Task AuthTypes_RequireAuth_Success(AuthenticationSchemes authType)
156156
Assert.NotNull(httpContext.User.Identity);
157157
Assert.True(httpContext.User.Identity.IsAuthenticated);
158158
return Task.FromResult(0);
159-
}))
159+
}, LoggerFactory))
160160
{
161161
var response = await SendRequestAsync(address, useDefaultCredentials: true);
162162
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -182,7 +182,7 @@ public async Task AuthTypes_AccessUserInOnCompleted_Success()
182182
return Task.CompletedTask;
183183
});
184184
return Task.FromResult(0);
185-
}))
185+
}, LoggerFactory))
186186
{
187187
var response = await SendRequestAsync(address, useDefaultCredentials: true);
188188
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -208,7 +208,7 @@ public async Task AuthTypes_AuthenticateWithNoUser_NoResults(AuthenticationSchem
208208
var authResults = await httpContext.AuthenticateAsync(HttpSysDefaults.AuthenticationScheme);
209209
Assert.False(authResults.Succeeded);
210210
Assert.True(authResults.None);
211-
}))
211+
}, LoggerFactory))
212212
{
213213
var response = await SendRequestAsync(address);
214214
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -231,7 +231,7 @@ public async Task AuthTypes_AuthenticateWithUser_OneResult(AuthenticationSchemes
231231
Assert.True(httpContext.User.Identity.IsAuthenticated);
232232
var authResults = await httpContext.AuthenticateAsync(HttpSysDefaults.AuthenticationScheme);
233233
Assert.True(authResults.Succeeded);
234-
}))
234+
}, LoggerFactory))
235235
{
236236
var response = await SendRequestAsync(address, useDefaultCredentials: true);
237237
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -253,7 +253,7 @@ public async Task AuthTypes_ChallengeWithoutAuthTypes_AllChallengesSent(Authenti
253253
Assert.NotNull(httpContext.User.Identity);
254254
Assert.False(httpContext.User.Identity.IsAuthenticated);
255255
return httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme);
256-
}))
256+
}, LoggerFactory))
257257
{
258258
var response = await SendRequestAsync(address);
259259
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
@@ -276,7 +276,7 @@ public async Task AuthTypes_ChallengeWithAllAuthTypes_AllChallengesSent(Authenti
276276
Assert.NotNull(httpContext.User.Identity);
277277
Assert.False(httpContext.User.Identity.IsAuthenticated);
278278
await httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme);
279-
}))
279+
}, LoggerFactory))
280280
{
281281
var response = await SendRequestAsync(address);
282282
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
@@ -294,7 +294,7 @@ public async Task AuthTypes_OneChallengeSent()
294294
Assert.NotNull(httpContext.User.Identity);
295295
Assert.False(httpContext.User.Identity.IsAuthenticated);
296296
return httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme);
297-
}))
297+
}, LoggerFactory))
298298
{
299299
var response = await SendRequestAsync(address);
300300
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
@@ -320,7 +320,7 @@ public async Task AuthTypes_ChallengeWillAskForAllEnabledSchemes(AuthenticationS
320320
Assert.NotNull(httpContext.User.Identity);
321321
Assert.False(httpContext.User.Identity.IsAuthenticated);
322322
return httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme);
323-
}))
323+
}, LoggerFactory))
324324
{
325325
var response = await SendRequestAsync(address);
326326
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
@@ -338,7 +338,7 @@ public async Task AuthTypes_Forbid_Forbidden()
338338
Assert.NotNull(httpContext.User.Identity);
339339
Assert.False(httpContext.User.Identity.IsAuthenticated);
340340
return httpContext.ForbidAsync(HttpSysDefaults.AuthenticationScheme);
341-
}))
341+
}, LoggerFactory))
342342
{
343343
var response = await SendRequestAsync(address);
344344
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
@@ -359,7 +359,7 @@ public async Task AuthTypes_UnathorizedAuthenticatedAuthType_Unauthorized(Authen
359359
Assert.NotNull(httpContext.User.Identity);
360360
Assert.True(httpContext.User.Identity.IsAuthenticated);
361361
return httpContext.ChallengeAsync(HttpSysDefaults.AuthenticationScheme, null);
362-
}))
362+
}, LoggerFactory))
363363
{
364364
var response = await SendRequestAsync(address, useDefaultCredentials: true);
365365
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
@@ -393,7 +393,7 @@ public async Task AuthTypes_DisableAutomaticAuthentication(AuthenticationSchemes
393393
Assert.NotNull(authenticateResult.Principal);
394394
Assert.NotNull(authenticateResult.Principal.Identity);
395395
Assert.True(authenticateResult.Principal.Identity.IsAuthenticated);
396-
}))
396+
}, LoggerFactory))
397397
{
398398
var response = await SendRequestAsync(address, useDefaultCredentials: true);
399399
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

src/Servers/HttpSys/test/FunctionalTests/DelegateTests.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.AspNetCore.Server.HttpSys.FunctionalTests;
1515

16-
public class DelegateTests
16+
public class DelegateTests : LoggedTest
1717
{
1818
private static readonly string _expectedResponseString = "Hello from delegatee";
1919

@@ -44,7 +44,7 @@ public async Task DelegateRequestTest()
4444
options =>
4545
{
4646
options.RequestQueueName = queueName;
47-
});
47+
}, LoggerFactory);
4848

4949
DelegationRule destination = default;
5050

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

5858
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
5959
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
@@ -76,7 +76,7 @@ public async Task DelegateAfterWriteToResponseBodyShouldThrowTest()
7676
options =>
7777
{
7878
options.RequestQueueName = queueName;
79-
});
79+
}, LoggerFactory);
8080

8181
DelegationRule destination = default;
8282

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

9191
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
9292
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
@@ -108,7 +108,7 @@ public async Task WriteToBodyAfterDelegateShouldNoOp()
108108
options =>
109109
{
110110
options.RequestQueueName = queueName;
111-
});
111+
}, LoggerFactory);
112112

113113
DelegationRule destination = default;
114114

@@ -119,7 +119,7 @@ public async Task WriteToBodyAfterDelegateShouldNoOp()
119119
Assert.False(delegateFeature.CanDelegate);
120120
httpContext.Response.WriteAsync(_expectedResponseString);
121121
return Task.CompletedTask;
122-
});
122+
}, LoggerFactory);
123123

124124
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
125125
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
@@ -142,7 +142,7 @@ public async Task DelegateAfterRequestBodyReadShouldThrow()
142142
options =>
143143
{
144144
options.RequestQueueName = queueName;
145-
});
145+
}, LoggerFactory);
146146

147147
DelegationRule destination = default;
148148

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

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

178178
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
179179
Assert.Null(delegationProperty);
@@ -193,7 +193,7 @@ public async Task UpdateDelegationRuleTest()
193193
options =>
194194
{
195195
options.RequestQueueName = queueName;
196-
});
196+
}, LoggerFactory);
197197

198198
DelegationRule destination = default;
199199

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

207207
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
208208
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
@@ -227,15 +227,15 @@ public async Task DelegateAfterReceiverRestart()
227227
options =>
228228
{
229229
options.RequestQueueName = queueName;
230-
});
230+
}, LoggerFactory);
231231

232232
DelegationRule destination = default;
233233
using var delegator = Utilities.CreateHttpServer(out var delegatorAddress, httpContext =>
234234
{
235235
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
236236
delegateFeature.DelegateRequest(destination);
237237
return Task.CompletedTask;
238-
});
238+
}, LoggerFactory);
239239

240240
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
241241
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
@@ -257,7 +257,7 @@ public async Task DelegateAfterReceiverRestart()
257257
options.RequestQueueMode = RequestQueueMode.CreateOrAttach;
258258
options.UrlPrefixes.Clear();
259259
options.UrlPrefixes.Add(receiverAddress);
260-
});
260+
}, LoggerFactory);
261261

262262
responseString = await SendRequestAsync(delegatorAddress);
263263
Assert.Equal(_expectedResponseString, responseString);

0 commit comments

Comments
 (0)