1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
|
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using Microsoft.TestCommon;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Net.Http.Formatting.Parsers
{
public class InternetMessageFormatHeaderParserTests
{
[Fact]
[Trait("Description", "HeaderParser is internal class")]
public void TypeIsCorrect()
{
Assert.Type.HasProperties<InternetMessageFormatHeaderParser>(TypeAssert.TypeProperties.IsClass);
}
private static IEnumerable<HttpHeaders> CreateHttpHeaders()
{
return new HttpHeaders[]
{
new HttpRequestMessage().Headers,
new HttpResponseMessage().Headers,
new StringContent(String.Empty).Headers,
};
}
private static InternetMessageFormatHeaderParser CreateHeaderParser(int maximumHeaderLength, out HttpHeaders headers)
{
headers = new HttpRequestMessage().Headers;
return new InternetMessageFormatHeaderParser(headers, maximumHeaderLength);
}
internal static byte[] CreateBuffer(params string[] headers)
{
const string CRLF = "\r\n";
StringBuilder header = new StringBuilder();
foreach (var h in headers)
{
header.Append(h + CRLF);
}
header.Append(CRLF);
return Encoding.UTF8.GetBytes(header.ToString());
}
private static void RunRfc5322SampleTest(string[] testHeaders, Action<HttpHeaders> validation)
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer(testHeaders);
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int totalBytesConsumed = 0;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.Done, state);
Assert.Equal(data.Length, totalBytesConsumed);
validation(headers);
}
}
private static ParserState ParseBufferInSteps(InternetMessageFormatHeaderParser parser, byte[] buffer, int readsize, out int totalBytesConsumed)
{
ParserState state = ParserState.Invalid;
totalBytesConsumed = 0;
while (totalBytesConsumed <= buffer.Length)
{
int size = Math.Min(buffer.Length - totalBytesConsumed, readsize);
byte[] parseBuffer = new byte[size];
Buffer.BlockCopy(buffer, totalBytesConsumed, parseBuffer, 0, size);
int bytesConsumed = 0;
state = parser.ParseBuffer(parseBuffer, parseBuffer.Length, ref bytesConsumed);
totalBytesConsumed += bytesConsumed;
if (state != ParserState.NeedMoreData)
{
return state;
}
}
return state;
}
[Fact]
[Trait("Description", "HeaderParser constructor throws on invalid arguments")]
public void HeaderParserConstructorTest()
{
IEnumerable<HttpHeaders> headers = InternetMessageFormatHeaderParserTests.CreateHttpHeaders();
foreach (var header in headers)
{
InternetMessageFormatHeaderParser parser = new InternetMessageFormatHeaderParser(header, ParserData.MinHeaderSize);
Assert.NotNull(parser);
}
Assert.ThrowsArgumentGreaterThanOrEqualTo(() => new InternetMessageFormatHeaderParser(headers.ElementAt(0), ParserData.MinHeaderSize - 1),
"maxHeaderSize", ParserData.MinHeaderSize.ToString(), ParserData.MinHeaderSize - 1);
Assert.ThrowsArgumentNull(() => { new InternetMessageFormatHeaderParser(null, ParserData.MinHeaderSize); }, "headers");
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer throws on null buffer.")]
public void HeaderParserNullBuffer()
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(128, out headers);
Assert.NotNull(parser);
int bytesConsumed = 0;
Assert.ThrowsArgumentNull(() => { parser.ParseBuffer(null, 0, ref bytesConsumed); }, "buffer");
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses empty header.")]
public void HeaderParserEmptyBuffer()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer();
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int bytesConsumed = 0;
ParserState state = parser.ParseBuffer(data, data.Length, ref bytesConsumed);
Assert.Equal(ParserState.Done, state);
Assert.Equal(data.Length, bytesConsumed);
Assert.Equal(0, headers.Count());
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses single header field.")]
public void HeaderParserSingleNameValueHeader()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer("N:V");
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int totalBytesConsumed;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.Done, state);
Assert.Equal(data.Length, totalBytesConsumed);
Assert.Equal(1, headers.Count());
IEnumerable<string> parsedValues = headers.GetValues("N");
Assert.Equal(1, parsedValues.Count());
Assert.Equal(parsedValues.ElementAt(0), "V");
}
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses single header field with name only.")]
public void HeaderParserSingleNameHeader()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer("N:");
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int totalBytesConsumed;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.Done, state);
Assert.Equal(data.Length, totalBytesConsumed);
Assert.Equal(1, headers.Count());
IEnumerable<string> parsedValues = headers.GetValues("N");
Assert.Equal(1, parsedValues.Count());
Assert.Equal("", parsedValues.ElementAt(0));
}
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses multiple header fields.")]
public void HeaderParserMultipleNameHeader()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer("N:V1", "N:V2");
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int totalBytesConsumed;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.Done, state);
Assert.Equal(data.Length, totalBytesConsumed);
Assert.Equal(1, headers.Count());
IEnumerable<string> parsedValues = headers.GetValues("N");
Assert.Equal(2, parsedValues.Count());
Assert.Equal("V1", parsedValues.ElementAt(0));
Assert.Equal("V2", parsedValues.ElementAt(1));
}
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses multiple header fields with linear white space.")]
public void HeaderParserLwsHeader()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer("N1:V1", "N2: V2", "N3:\tV3");
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int totalBytesConsumed = 0;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.Done, state);
Assert.Equal(data.Length, totalBytesConsumed);
Assert.Equal(3, headers.Count());
IEnumerable<string> parsedValues = headers.GetValues("N1");
Assert.Equal(1, parsedValues.Count());
Assert.Equal("V1", parsedValues.ElementAt(0));
parsedValues = headers.GetValues("N2");
Assert.Equal(1, parsedValues.Count());
Assert.Equal("V2", parsedValues.ElementAt(0));
parsedValues = headers.GetValues("N3");
Assert.Equal(1, parsedValues.Count());
Assert.Equal("V3", parsedValues.ElementAt(0));
}
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses invalid header field.")]
public void HeaderParserInvalidHeader()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer("N1 :V1");
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int totalBytesConsumed = 0;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.Invalid, state);
Assert.Equal(data.Length - 2, totalBytesConsumed);
}
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses various specialized header fields including JSON, P3P, etc.")]
public void HeaderParserSpecializedHeaders()
{
Dictionary<string, string> headerData = new Dictionary<string, string>
{
{ @"JsonProperties0", @"{ ""SessionId"": ""{27729E1-B37B-4D29-AA0A-E367906C206E}"", ""MessageId"": ""{701332E1-B37B-4D29-AA0A-E367906C206E}"", ""TimeToLive"" : 90, ""CorrelationId"": ""{701332F3-B37B-4D29-AA0A-E367906C206E}"", ""SequenceNumber"" : 12345, ""DeliveryCount"" : 2, ""To"" : ""http://contoso.com/path1"", ""ReplyTo"" : ""http://fabrikam.com/path1"", ""SentTimeUtc"" : ""Sun, 06 Nov 1994 08:49:37 GMT"", ""ScheduledEnqueueTimeUtc"" : ""Sun, 06 Nov 1994 08:49:37 GMT""}" },
{ @"JsonProperties1", @"{ ""SessionId"": ""{2813D4D2-46A9-4F4D-8904-E9BDE3712B70}"", ""MessageId"": ""{24AE31D6-63B8-46F3-9975-A3DAF1B6D3F4}"", ""TimeToLive"" : 80, ""CorrelationId"": ""{896DD5BD-1645-44D7-9E7C-D7F70958ECD6}"", ""SequenceNumber"" : 54321, ""DeliveryCount"" : 4, ""To"" : ""http://contoso.com/path2"", ""ReplyTo"" : ""http://fabrikam.com/path2"", ""SentTimeUtc"" : ""Sun, 06 Nov 1994 10:49:37 GMT"", ""ScheduledEnqueueTimeUtc"" : ""Sun, 06 Nov 1994 10:49:37 GMT""}" },
{ @"P3P", @"CP=""ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI""" },
{ @"Cookie", @"omniID=1297715979621_9f45_1519_3f8a_f22f85346ac6; WT_FPC=id=65.55.227.138-2323234032.30136233:lv=1309374389020:ss=1309374389020; A=I&I=AxUFAAAAAACNCAAADYEZ7CFPss7Swnujy4PXZA!!&M=1&CS=126mAa0002ZB51a02gZB51a; MC1=GUID=568428660ad44d4ab8f46133f4b03738&HASH=6628&LV=20113&V=3; WT_NVR_RU=0=msdn:1=:2=; MUID=A44DE185EA1B4E8088CCF7B348C5D65F; MSID=Microsoft.CreationDate=03/04/2011 23:38:15&Microsoft.LastVisitDate=06/20/2011 04:15:08&Microsoft.VisitStartDate=06/20/2011 04:15:08&Microsoft.CookieId=f658f3f2-e6d6-42ab-b86b-96791b942b6f&Microsoft.TokenId=ffffffff-ffff-ffff-ffff-ffffffffffff&Microsoft.NumberOfVisits=106&Microsoft.CookieFirstVisit=1&Microsoft.IdentityToken=AA==&Microsoft.MicrosoftId=0441-6141-1523-9969; msresearch=%7B%22version%22%3A%224.6%22%2C%22state%22%3A%7B%22name%22%3A%22IDLE%22%2C%22url%22%3Aundefined%2C%22timestamp%22%3A1299281911415%7D%2C%22lastinvited%22%3A1299281911415%2C%22userid%22%3A%2212992819114151265672533023080%22%2C%22vendorid%22%3A1%2C%22surveys%22%3A%5Bundefined%5D%7D; CodeSnippetContainerLang=C#; msdn=L=1033; ADS=SN=175A21EF; s_cc=true; s_sq=%5B%5BB%5D%5D; TocHashCookie=ms310241(n)/aa187916(n)/aa187917(n)/dd273952(n)/dd295083(n)/ff472634(n)/ee667046(n)/ee667070(n)/gg259047(n)/gg618436(n)/; WT_NVR=0=/:1=query|library|en-us:2=en-us/vcsharp|en-us/library" },
{ @"Set-Cookie", @"A=I&I=AxUFAAAAAADsBgAA1sWZz4FGun/kOeyV4LGZVg!!&M=1; domain=.microsoft.com; expires=Sun, 30-Jun-2041 00:14:40 GMT; path=/" },
};
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer(headerData.Select((kv) => { return String.Format("{0}: {1}", kv.Key, kv.Value); }).ToArray());
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int totalBytesConsumed = 0;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.Done, state);
Assert.Equal(data.Length, totalBytesConsumed);
Assert.Equal(headerData.Count, headers.Count());
for (int hCnt = 0; hCnt < headerData.Count; hCnt++)
{
Assert.Equal(headerData.Keys.ElementAt(hCnt), headers.ElementAt(hCnt).Key);
Assert.Equal(headerData.Values.ElementAt(hCnt), headers.ElementAt(hCnt).Value.ElementAt(0));
}
}
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses multi-line header field.")]
public void HeaderParserSplitHeader()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer("N:V1,", " V2,", "\tV3,", " V4,", " \tV5");
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(data.Length, out headers);
Assert.NotNull(parser);
int totalBytesConsumed = 0;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.Done, state);
Assert.Equal(data.Length, totalBytesConsumed);
Assert.Equal(1, headers.Count());
IEnumerable<string> parsedValues = headers.GetValues("N");
Assert.Equal(1, parsedValues.Count());
Assert.Equal("V1, V2, V3, V4, \tV5", parsedValues.ElementAt(0));
}
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses too big header with single header field.")]
public void HeaderParserDataTooBigSingle()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer("N:V");
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(ParserData.MinHeaderSize, out headers);
Assert.NotNull(parser);
int totalBytesConsumed = 0;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.DataTooBig, state);
Assert.Equal(ParserData.MinHeaderSize, totalBytesConsumed);
}
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer parses too big header with multiple header field.")]
public void HeaderParserTestDataTooBigMulti()
{
byte[] data = InternetMessageFormatHeaderParserTests.CreateBuffer("N1:V1", "N2:V2", "N3:V3");
for (var cnt = 1; cnt <= data.Length; cnt++)
{
HttpHeaders headers;
InternetMessageFormatHeaderParser parser = InternetMessageFormatHeaderParserTests.CreateHeaderParser(10, out headers);
Assert.NotNull(parser);
int totalBytesConsumed = 0;
ParserState state = InternetMessageFormatHeaderParserTests.ParseBufferInSteps(parser, data, cnt, out totalBytesConsumed);
Assert.Equal(ParserState.DataTooBig, state);
Assert.Equal(10, totalBytesConsumed);
}
}
// Set of samples from RFC 5322 with times adjusted to GMT following HTTP style for date time format.
static readonly string[] Rfc5322Sample1 = new string[] {
@"From: John Doe <jdoe@machine.example>",
@"To: Mary Smith <mary@example.net>",
@"Subject: Saying Hello",
@"Date: Fri, 21 Nov 1997 09:55:06 GMT",
@"Message-ID: <1234@local.machine.example>",
};
static readonly string[] Rfc5322Sample2 = new string[] {
@"From: John Doe <jdoe@machine.example>",
@"Sender: Michael Jones <mjones@machine.example>",
@"To: Mary Smith <mary@example.net>",
@"Subject: Saying Hello",
@"Date: Fri, 21 Nov 1997 09:55:06 GMT",
@"Message-ID: <1234@local.machine.example>",
};
static readonly string[] Rfc5322Sample3 = new string[] {
@"From: ""Joe Q. Public"" <john.q.public@example.com>",
@"To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test>",
@"Cc: <boss@nil.test>, ""Giant; \""Big\"" Box"" <sysservices@example.net>",
@"Date: Tue, 01 Jul 2003 10:52:37 GMT",
@"Message-ID: <5678.21-Nov-1997@example.com>",
};
static readonly string[] Rfc5322Sample4 = new string[] {
@"From: Pete <pete@silly.example>",
@"To: A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>;",
@"Cc: Undisclosed recipients:;",
@"Date: Thu, 13 Feb 1969 23:32:54 GMT",
@"Message-ID: <testabcd.1234@silly.example>",
};
static readonly string[] Rfc5322Sample5 = new string[] {
@"From: John Doe <jdoe@machine.example>",
@"To: Mary Smith <mary@example.net>",
@"Subject: Saying Hello",
@"Date: Fri, 21 Nov 1997 09:55:06 GMT",
@"Message-ID: <1234@local.machine.example>",
};
static readonly string[] Rfc5322Sample6 = new string[] {
@"From: Mary Smith <mary@example.net>",
@"To: John Doe <jdoe@machine.example>",
@"Reply-To: ""Mary Smith: Personal Account"" <smith@home.example>",
@"Subject: Re: Saying Hello",
@"Date: Fri, 21 Nov 1997 10:01:10 GMT",
@"Message-ID: <3456@example.net>",
@"In-Reply-To: <1234@local.machine.example>",
@"References: <1234@local.machine.example>",
};
static readonly string[] Rfc5322Sample7 = new string[] {
@"To: ""Mary Smith: Personal Account"" <smith@home.example>",
@"From: John Doe <jdoe@machine.example>",
@"Subject: Re: Saying Hello",
@"Date: Fri, 21 Nov 1997 11:00:00 GMT",
@"Message-ID: <abcd.1234@local.machine.test>",
@"In-Reply-To: <3456@example.net>",
@"References: <1234@local.machine.example> <3456@example.net>",
};
static readonly string[] Rfc5322Sample8 = new string[] {
@"From: John Doe <jdoe@machine.example>",
@"To: Mary Smith <mary@example.net>",
@"Subject: Saying Hello",
@"Date: Fri, 21 Nov 1997 09:55:06 GMT",
@"Message-ID: <1234@local.machine.example>",
};
static readonly string[] Rfc5322Sample9 = new string[] {
@"Resent-From: Mary Smith <mary@example.net>",
@"Resent-To: Jane Brown <j-brown@other.example>",
@"Resent-Date: Mon, 24 Nov 1997 14:22:01 GMT",
@"Resent-Message-ID: <78910@example.net>",
@"From: John Doe <jdoe@machine.example>",
@"To: Mary Smith <mary@example.net>",
@"Subject: Saying Hello",
@"Date: Fri, 21 Nov 1997 09:55:06 GMT",
@"Message-ID: <1234@local.machine.example>",
};
static readonly string[] Rfc5322Sample10 = new string[] {
@"Received: from x.y.test",
@" by example.net",
@" via TCP",
@" with ESMTP",
@" id ABC12345",
@" for <mary@example.net>; 21 Nov 1997 10:05:43 GMT",
@"Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 GMT",
@"From: John Doe <jdoe@node.example>",
@"To: Mary Smith <mary@example.net>",
@"Subject: Saying Hello",
@"Date: Fri, 21 Nov 1997 09:55:06 GMT",
@"Message-ID: <1234@local.node.example>",
};
static readonly string[] Rfc5322Sample11 = new string[] {
@"From: Pete(A nice \) chap) <pete(his account)@silly.test(his host)>",
@"To:A Group(Some people)",
@" :Chris Jones <c@(Chris's host.)public.example>,",
@" joe@example.org,",
@" John <jdoe@one.test> (my dear friend); (the end of the group)",
@"Cc:(Empty list)(start)Hidden recipients :(nobody(that I know)) ;",
@"Date: Thu,",
@" 13",
@" Feb",
@" 1969",
@" 23:32:00",
@" GMT",
@"Message-ID: <testabcd.1234@silly.test>",
};
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample1 header.")]
public void Rfc5322Sample1Test()
{
RunRfc5322SampleTest(Rfc5322Sample1,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("subject"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample2 header.")]
public void Rfc5322Sample2Test()
{
RunRfc5322SampleTest(Rfc5322Sample2,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("sender"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("subject"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample3 header.")]
public void Rfc5322Sample3Test()
{
RunRfc5322SampleTest(Rfc5322Sample3,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("cc"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample4 header.")]
public void Rfc5322Sample4Test()
{
RunRfc5322SampleTest(Rfc5322Sample4,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("cc"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample5 header.")]
public void Rfc5322Sample5Test()
{
RunRfc5322SampleTest(Rfc5322Sample5,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("subject"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample6 header.")]
public void Rfc5322Sample6Test()
{
RunRfc5322SampleTest(Rfc5322Sample6,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("reply-to"));
Assert.True(headers.Contains("subject"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
Assert.True(headers.Contains("in-reply-to"));
Assert.True(headers.Contains("references"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample7 header.")]
public void Rfc5322Sample7Test()
{
RunRfc5322SampleTest(Rfc5322Sample7,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("subject"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
Assert.True(headers.Contains("in-reply-to"));
Assert.True(headers.Contains("references"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample8 header.")]
public void Rfc5322Sample8Test()
{
RunRfc5322SampleTest(Rfc5322Sample8,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("subject"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample9 header.")]
public void Rfc5322Sample9Test()
{
RunRfc5322SampleTest(Rfc5322Sample9,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("resent-from"));
Assert.True(headers.Contains("resent-to"));
Assert.True(headers.Contains("resent-date"));
Assert.True(headers.Contains("resent-message-id"));
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("subject"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample10 header.")]
public void Rfc5322Sample10Test()
{
RunRfc5322SampleTest(Rfc5322Sample10,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("received"));
Assert.Equal(2, headers.GetValues("received").Count());
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("subject"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
[Fact]
[Trait("Description", "HeaderParser.ParseBuffer Rfc5322Sample11 header.")]
public void Rfc5322Sample11Test()
{
RunRfc5322SampleTest(Rfc5322Sample11,
(headers) =>
{
Assert.NotNull(headers);
Assert.True(headers.Contains("from"));
Assert.True(headers.Contains("to"));
Assert.True(headers.Contains("cc"));
Assert.True(headers.Contains("date"));
Assert.True(headers.Contains("message-id"));
});
}
}
}
|