|
4 | 4 | using System;
|
5 | 5 | using System.Globalization;
|
6 | 6 | using System.Net.Http;
|
7 |
| -using System.Net.Sockets; |
8 |
| -using System.Text; |
9 | 7 | using System.Threading.Tasks;
|
10 | 8 | using Microsoft.AspNetCore.Builder;
|
11 | 9 | using Microsoft.AspNetCore.Hosting;
|
12 | 10 | using Microsoft.AspNetCore.Http;
|
13 |
| -using Microsoft.AspNetCore.Http.Features; |
14 | 11 | using Microsoft.AspNetCore.Testing.xunit;
|
15 | 12 | using Newtonsoft.Json;
|
16 | 13 | using Newtonsoft.Json.Linq;
|
@@ -159,166 +156,6 @@ public async Task DoesNotHangOnConnectionCloseRequest()
|
159 | 156 | }
|
160 | 157 | }
|
161 | 158 |
|
162 |
| - [Fact] |
163 |
| - public void RequestPathIsNormalized() |
164 |
| - { |
165 |
| - var builder = new WebHostBuilder() |
166 |
| - .UseKestrel() |
167 |
| - .UseUrls($"http://127.0.0.1:0/\u0041\u030A") |
168 |
| - .Configure(app => |
169 |
| - { |
170 |
| - app.Run(async context => |
171 |
| - { |
172 |
| - var connection = context.Connection; |
173 |
| - Assert.Equal("/\u00C5", context.Request.PathBase.Value); |
174 |
| - Assert.Equal("/B/\u00C5", context.Request.Path.Value); |
175 |
| - await context.Response.WriteAsync("hello, world"); |
176 |
| - }); |
177 |
| - }); |
178 |
| - |
179 |
| - using (var host = builder.Build()) |
180 |
| - { |
181 |
| - host.Start(); |
182 |
| - |
183 |
| - using (var socket = TestConnection.CreateConnectedLoopbackSocket(host.GetPort())) |
184 |
| - { |
185 |
| - socket.Send(Encoding.ASCII.GetBytes("GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1\r\n\r\n")); |
186 |
| - socket.Shutdown(SocketShutdown.Send); |
187 |
| - |
188 |
| - var response = new StringBuilder(); |
189 |
| - var buffer = new byte[4096]; |
190 |
| - while (true) |
191 |
| - { |
192 |
| - var length = socket.Receive(buffer); |
193 |
| - if (length == 0) |
194 |
| - { |
195 |
| - break; |
196 |
| - } |
197 |
| - |
198 |
| - response.Append(Encoding.ASCII.GetString(buffer, 0, length)); |
199 |
| - } |
200 |
| - |
201 |
| - Assert.StartsWith("HTTP/1.1 200 OK", response.ToString()); |
202 |
| - } |
203 |
| - } |
204 |
| - } |
205 |
| - |
206 |
| - [Theory] |
207 |
| - [InlineData("/")] |
208 |
| - [InlineData("/.")] |
209 |
| - [InlineData("/..")] |
210 |
| - [InlineData("/./.")] |
211 |
| - [InlineData("/./..")] |
212 |
| - [InlineData("/../.")] |
213 |
| - [InlineData("/../..")] |
214 |
| - [InlineData("/path")] |
215 |
| - [InlineData("/path?foo=1&bar=2")] |
216 |
| - [InlineData("/hello%20world")] |
217 |
| - [InlineData("/hello%20world?foo=1&bar=2")] |
218 |
| - [InlineData("/base/path")] |
219 |
| - [InlineData("/base/path?foo=1&bar=2")] |
220 |
| - [InlineData("/base/hello%20world")] |
221 |
| - [InlineData("/base/hello%20world?foo=1&bar=2")] |
222 |
| - public void RequestFeatureContainsRawTarget(string requestTarget) |
223 |
| - { |
224 |
| - var builder = new WebHostBuilder() |
225 |
| - .UseKestrel() |
226 |
| - .UseUrls($"http://127.0.0.1:0/base") |
227 |
| - .Configure(app => |
228 |
| - { |
229 |
| - app.Run(async context => |
230 |
| - { |
231 |
| - var connection = context.Connection; |
232 |
| - Assert.Equal(requestTarget, context.Features.Get<IHttpRequestFeature>().RawTarget); |
233 |
| - await context.Response.WriteAsync("hello, world"); |
234 |
| - }); |
235 |
| - }); |
236 |
| - |
237 |
| - using (var host = builder.Build()) |
238 |
| - { |
239 |
| - host.Start(); |
240 |
| - |
241 |
| - using (var socket = TestConnection.CreateConnectedLoopbackSocket(host.GetPort())) |
242 |
| - { |
243 |
| - socket.Send(Encoding.ASCII.GetBytes($"GET {requestTarget} HTTP/1.1\r\n\r\n")); |
244 |
| - socket.Shutdown(SocketShutdown.Send); |
245 |
| - |
246 |
| - var response = new StringBuilder(); |
247 |
| - var buffer = new byte[4096]; |
248 |
| - while (true) |
249 |
| - { |
250 |
| - var length = socket.Receive(buffer); |
251 |
| - if (length == 0) |
252 |
| - { |
253 |
| - break; |
254 |
| - } |
255 |
| - |
256 |
| - response.Append(Encoding.ASCII.GetString(buffer, 0, length)); |
257 |
| - } |
258 |
| - |
259 |
| - Assert.StartsWith("HTTP/1.1 200 OK", response.ToString()); |
260 |
| - } |
261 |
| - } |
262 |
| - } |
263 |
| - |
264 |
| - [Theory] |
265 |
| - [InlineData("*")] |
266 |
| - [InlineData("*/?arg=value")] |
267 |
| - [InlineData("*?arg=value")] |
268 |
| - [InlineData("DoesNotStartWith/")] |
269 |
| - [InlineData("DoesNotStartWith/?arg=value")] |
270 |
| - [InlineData("DoesNotStartWithSlash?arg=value")] |
271 |
| - [InlineData("./")] |
272 |
| - [InlineData("../")] |
273 |
| - [InlineData("../.")] |
274 |
| - [InlineData(".././")] |
275 |
| - [InlineData("../..")] |
276 |
| - [InlineData("../../")] |
277 |
| - public void NonPathRequestTargetSetInRawTarget(string requestTarget) |
278 |
| - { |
279 |
| - var builder = new WebHostBuilder() |
280 |
| - .UseKestrel() |
281 |
| - .UseUrls($"http://127.0.0.1:0/") |
282 |
| - .Configure(app => |
283 |
| - { |
284 |
| - app.Run(async context => |
285 |
| - { |
286 |
| - var connection = context.Connection; |
287 |
| - Assert.Equal(requestTarget, context.Features.Get<IHttpRequestFeature>().RawTarget); |
288 |
| - Assert.Empty(context.Request.Path.Value); |
289 |
| - Assert.Empty(context.Request.PathBase.Value); |
290 |
| - Assert.Empty(context.Request.QueryString.Value); |
291 |
| - await context.Response.WriteAsync("hello, world"); |
292 |
| - }); |
293 |
| - }); |
294 |
| - |
295 |
| - using (var host = builder.Build()) |
296 |
| - { |
297 |
| - host.Start(); |
298 |
| - |
299 |
| - using (var socket = TestConnection.CreateConnectedLoopbackSocket(host.GetPort())) |
300 |
| - { |
301 |
| - socket.Send(Encoding.ASCII.GetBytes($"GET {requestTarget} HTTP/1.1\r\n\r\n")); |
302 |
| - socket.Shutdown(SocketShutdown.Send); |
303 |
| - |
304 |
| - var response = new StringBuilder(); |
305 |
| - var buffer = new byte[4096]; |
306 |
| - while (true) |
307 |
| - { |
308 |
| - var length = socket.Receive(buffer); |
309 |
| - if (length == 0) |
310 |
| - { |
311 |
| - break; |
312 |
| - } |
313 |
| - |
314 |
| - response.Append(Encoding.ASCII.GetString(buffer, 0, length)); |
315 |
| - } |
316 |
| - |
317 |
| - Assert.StartsWith("HTTP/1.1 200 OK", response.ToString()); |
318 |
| - } |
319 |
| - } |
320 |
| - } |
321 |
| - |
322 | 159 | private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress)
|
323 | 160 | {
|
324 | 161 | var builder = new WebHostBuilder()
|
|
0 commit comments