|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 | // See the LICENSE file in the project root for more information.
|
4 | 4 |
|
5 |
| -using System; |
6 | 5 | using System.Collections.Generic;
|
| 6 | +using System.Diagnostics; |
7 | 7 | using System.Linq;
|
8 | 8 | using System.IO;
|
9 |
| -using System.Net.Http.Headers; |
10 | 9 | using System.Net.Test.Common;
|
11 | 10 | using System.Security.Authentication.ExtendedProtection;
|
12 | 11 | using System.Text;
|
@@ -465,6 +464,65 @@ public async Task GetAsync_RequestHeadersAddCustomHeaders_HeaderAndValueSent(str
|
465 | 464 | }
|
466 | 465 | }
|
467 | 466 |
|
| 467 | + private static KeyValuePair<string, string> GenerateCookie(string name, char repeat, int overallHeaderValueLength) |
| 468 | + { |
| 469 | + string emptyHeaderValue = $"{name}=; Path=/"; |
| 470 | + |
| 471 | + Debug.Assert(overallHeaderValueLength > emptyHeaderValue.Length); |
| 472 | + |
| 473 | + int valueCount = overallHeaderValueLength - emptyHeaderValue.Length; |
| 474 | + string value = new string(repeat, valueCount); |
| 475 | + |
| 476 | + return new KeyValuePair<string, string>(name, value); |
| 477 | + } |
| 478 | + |
| 479 | + public static object[][] CookieNameValues = |
| 480 | + { |
| 481 | + new object[] { GenerateCookie(name: "foo", repeat: 'a', overallHeaderValueLength: 254) }, |
| 482 | + new object[] { GenerateCookie(name: "foo", repeat: 'a', overallHeaderValueLength: 255) }, |
| 483 | + new object[] { GenerateCookie(name: "foo", repeat: 'a', overallHeaderValueLength: 256) }, |
| 484 | + new object[] { GenerateCookie(name: "foo", repeat: 'a', overallHeaderValueLength: 257) }, |
| 485 | + new object[] |
| 486 | + { |
| 487 | + new KeyValuePair<string, string>( |
| 488 | + ".AspNetCore.Antiforgery.Xam7_OeLcN4", |
| 489 | + "CfDJ8NGNxAt7CbdClq3UJ8_6w_4661wRQZT1aDtUOIUKshbcV4P0NdS8klCL5qGSN-PNBBV7w23G6MYpQ81t0PMmzIN4O04fqhZ0u1YPv66mixtkX3iTi291DgwT3o5kozfQhe08-RAExEmXpoCbueP_QYM") |
| 490 | + } |
| 491 | + }; |
| 492 | + |
| 493 | + [Theory] |
| 494 | + [MemberData(nameof(CookieNameValues))] |
| 495 | + public async Task GetAsync_ResponseWithSetCookieHeaders_AllCookiesRead(KeyValuePair<string, string> cookie1) |
| 496 | + { |
| 497 | + var cookie2 = new KeyValuePair<string, string>(".AspNetCore.Session", "RAExEmXpoCbueP_QYM"); |
| 498 | + var cookie3 = new KeyValuePair<string, string>("name", "value"); |
| 499 | + |
| 500 | + string url = string.Format( |
| 501 | + "http://httpbin.org/cookies/set?{0}={1}&{2}={3}&{4}={5}", |
| 502 | + cookie1.Key, |
| 503 | + cookie1.Value, |
| 504 | + cookie2.Key, |
| 505 | + cookie2.Value, |
| 506 | + cookie3.Key, |
| 507 | + cookie3.Value); |
| 508 | + |
| 509 | + var handler = new HttpClientHandler() |
| 510 | + { |
| 511 | + AllowAutoRedirect = false |
| 512 | + }; |
| 513 | + |
| 514 | + using (var client = new HttpClient(handler)) |
| 515 | + using (HttpResponseMessage response = await client.GetAsync(url)) |
| 516 | + { |
| 517 | + CookieCollection cookies = handler.CookieContainer.GetCookies(new Uri(url)); |
| 518 | + |
| 519 | + Assert.Equal(3, handler.CookieContainer.Count); |
| 520 | + Assert.Equal(cookie1.Value, cookies[cookie1.Key].Value); |
| 521 | + Assert.Equal(cookie2.Value, cookies[cookie2.Key].Value); |
| 522 | + Assert.Equal(cookie3.Value, cookies[cookie3.Key].Value); |
| 523 | + } |
| 524 | + } |
| 525 | + |
468 | 526 | [Fact]
|
469 | 527 | public async Task GetAsync_ResponseHeadersRead_ReadFromEachIterativelyDoesntDeadlock()
|
470 | 528 | {
|
|
0 commit comments