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
|
#!/usr/bin/perl
use strict;
use warnings;
use lib 't/010-resources/';
use Test::More;
use Test::Fatal;
use Test::FailWarnings;
use Plack::Request;
use Plack::Response;
use Plack::Util;
use Web::Machine::Util qw[ inflate_headers ];
BEGIN {
use_ok('Web::Machine');
}
my $fsm = Web::Machine::FSM->new( tracing => 1 );
isa_ok( $fsm, 'Web::Machine::FSM' );
my @tests = (
{
resource => 'B13',
request => { REQUEST_METHOD => 'GET' },
response => [ 503, [ 'Content-Type' => 'text/plain' ], ['Service Unavailable'] ],
trace => 'b13'
},
{
resource => 'B12',
request => { REQUEST_METHOD => 'GET' },
response => [ 501, [ 'Content-Type' => 'text/plain' ], ['Not Implemented'] ],
trace => 'b13,b12'
},
{
resource => 'B11',
request => { REQUEST_METHOD => 'GET' },
response => [ 414, [ 'Content-Type' => 'text/plain' ], ['Request-URI Too Large'] ],
trace => 'b13,b12,b11'
},
{
resource => 'B10',
request => { REQUEST_METHOD => 'GET' },
response => [ 405, [ 'Content-Type' => 'text/plain', 'Allow' => 'PUT, DELETE' ], ['Method Not Allowed'] ],
trace => 'b13,b12,b11,b10'
},
{
resource => 'B9',
request => { REQUEST_METHOD => 'GET' },
response => [ 400, [ 'Content-Type' => 'text/plain' ], ['Bad Request'] ],
trace => 'b13,b12,b11,b10,b9'
},
{
resource => 'B8',
request => { REQUEST_METHOD => 'GET' },
response => [ 401, [ 'Content-Type' => 'text/plain', 'WWW-Authenticate' => 'Basic realm="Test"' ], ['Unauthorized'] ],
trace => 'b13,b12,b11,b10,b9,b8'
},
{
resource => 'B8b',
request => { REQUEST_METHOD => 'GET' },
response => [ 500, [ 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8'
},
{
resource => 'B8c',
request => { REQUEST_METHOD => 'GET' },
response => [ 401, [ 'Content-Type' => 'text/plain' ], ['Unauthorized'] ],
trace => 'b13,b12,b11,b10,b9,b8'
},
{
resource => 'B8d',
request => { REQUEST_METHOD => 'GET' },
response => [ 401, [ 'Content-Type' => 'text/plain' ], ['Unauthorized'] ],
trace => 'b13,b12,b11,b10,b9,b8'
},
{
resource => 'B7',
request => { REQUEST_METHOD => 'GET' },
response => [ 403, [ 'Content-Type' => 'text/plain' ], ['Forbidden'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7'
},
{
resource => 'B7b',
request => { REQUEST_METHOD => 'GET' },
response => [ 403, [ 'Content-Type' => 'text/plain' ], ['Forbidden'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7'
},
{
resource => 'B6',
request => { REQUEST_METHOD => 'GET' },
response => [ 501, [ 'Content-Type' => 'text/plain' ], ['Not Implemented'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6'
},
{
resource => 'B5',
request => { REQUEST_METHOD => 'GET' },
response => [ 415, [ 'Content-Type' => 'text/plain' ], ['Unsupported Media Type'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5'
},
{
resource => 'B4',
request => { REQUEST_METHOD => 'GET' },
response => [ 413, [ 'Content-Type' => 'text/plain' ], ['Request Entity Too Large'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4'
},
{
resource => 'B3',
request => { REQUEST_METHOD => 'OPTIONS' },
response => [ 200, [ 'X-Hello' => 'OH HAI!' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3'
},
{
resource => 'C4',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/html' },
response => [ 406, [ 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4'
},
# ... (langauge doesn't match, but content type does)
{
resource => 'D5',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT_LANGUAGE => 'en' },
response => [ 406, [ 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,d5'
},
{
resource => 'D5',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'en' },
response => [ 406, [ 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ], # won't have written the content type header yet
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5'
},
# ... (content type and language match, but charset doesn't)
{
resource => 'E6',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'iso-8859-5' },
response => [ 406, [ 'Content-Type' => 'text/plain', 'Content-Language' => 'de' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,d5,e5,e6'
},
{
resource => 'E6',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'iso-8859-5' },
response => [ 406, [ 'Content-Type' => 'text/plain', 'Content-Language' => 'de' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6'
},
# ... (no encoding asked for, and no identity provided, but content-type, language and charset matches)
{
resource => 'F6',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8' },
response => [ 406, [ 'Content-Language' => 'de', 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6,f6'
},
{
resource => 'F6',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8' },
response => [ 406, [ 'Content-Language' => 'de', 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,d5,e5,e6,f6'
},
{
resource => 'F6',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT_LANGUAGE => 'de' },
response => [ 406, [ 'Content-Language' => 'de', 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,d5,e5,f6'
},
{
resource => 'F6',
request => { REQUEST_METHOD => 'GET' },
response => [ 406, [ 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6'
},
# ... (same as F6, but now we are asking for an encoding)
{
resource => 'F7',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8', HTTP_ACCEPT_ENCODING => 'gzip' },
response => [ 406, [ 'Content-Language' => 'de', 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6,f6,f7'
},
{
resource => 'F7',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8', HTTP_ACCEPT_ENCODING => 'gzip' },
response => [ 406, [ 'Content-Language' => 'de', 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,d5,e5,e6,f6,f7'
},
{
resource => 'F7',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_ENCODING => 'gzip' },
response => [ 406, [ 'Content-Language' => 'de', 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,d5,e5,f6,f7'
},
{
resource => 'F7',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT_ENCODING => 'gzip' },
response => [ 406, [ 'Content-Type' => 'text/plain' ], ['Not Acceptable'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,f7'
},
# ... (test out all the different variance scenarios, this really is testing G7, but H7 is the terminal node)
{
resource => 'H7',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8', HTTP_ACCEPT_ENCODING => 'gzip', HTTP_IF_MATCH => '*' },
response => [ 412, [ 'Vary' => 'Accept, Accept-Encoding, Accept-Charset, Accept-Language', 'Content-Encoding' => 'gzip', 'Content-Language' => 'de', 'Content-Type' => 'text/plain', ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6,f6,f7,g7,h7'
},
{
resource => 'H7b',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8', HTTP_ACCEPT_ENCODING => 'gzip', HTTP_IF_MATCH => '*' },
response => [ 412, [ 'Vary' => 'Accept-Encoding, Accept-Charset, Accept-Language', 'Content-Encoding' => 'gzip', 'Content-Language' => 'de', 'Content-Type' => 'text/plain', ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6,f6,f7,g7,h7'
},
{
resource => 'H7c',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8', HTTP_ACCEPT_ENCODING => 'gzip', HTTP_IF_MATCH => '*' },
response => [ 412, [ 'Vary' => 'Accept-Encoding, Accept-Charset', 'Content-Encoding' => 'gzip', 'Content-Language' => 'de', 'Content-Type' => 'text/plain', ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6,f6,f7,g7,h7'
},
{
resource => 'H7d',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8', HTTP_ACCEPT_ENCODING => 'gzip', HTTP_IF_MATCH => '*' },
response => [ 412, [ 'Vary' => 'Accept-Encoding', 'Content-Encoding' => 'gzip', 'Content-Language' => 'de', 'Content-Type' => 'text/plain', ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6,f6,f7,g7,h7'
},
{
resource => 'H7e',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8', HTTP_ACCEPT_ENCODING => 'gzip', HTTP_IF_MATCH => '*' },
response => [ 412, [ 'Content-Encoding' => 'gzip', 'Content-Language' => 'de', 'Content-Type' => 'text/plain', ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6,f6,f7,g7,h7'
},
{
resource => 'H7f',
request => { REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/plain', HTTP_ACCEPT_LANGUAGE => 'de', HTTP_ACCEPT_CHARSET => 'utf-8', HTTP_ACCEPT_ENCODING => 'gzip', HTTP_IF_MATCH => '*' },
response => [ 412, [ 'Vary' => 'Accept, Accept-Language', 'Content-Encoding' => 'gzip', 'Content-Language' => 'de', 'Content-Type' => 'text/plain', ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,d5,e5,e6,f6,f7,g7,h7'
},
# ...
{
resource => 'G11',
request => { REQUEST_METHOD => 'GET', HTTP_IF_MATCH => '0xDEADPORK' },
response => [ 412, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,g9,g11'
},
# ... H12 via G8->H10->H11
{
resource => 'H12',
request => { REQUEST_METHOD => 'GET', HTTP_IF_UNMODIFIED_SINCE => '18 Mar 2012 15:49:00 GMT' },
response => [ 412, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,h11,h12'
},
# ... H12 via G8->G9->H10->H11
{
resource => 'H12',
request => { REQUEST_METHOD => 'GET', HTTP_IF_MATCH => '*', HTTP_IF_UNMODIFIED_SINCE => '18 Mar 2012 15:49:00 GMT' },
response => [ 412, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,g9,h10,h11,h12'
},
# ... H12 via G8->G9->G11->H10->H11
{
resource => 'H12',
request => { REQUEST_METHOD => 'GET', HTTP_IF_UNMODIFIED_SINCE => '18 Mar 2012 15:49:00 GMT', HTTP_IF_MATCH => '0xDEADBEEF' },
response => [ 412, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,g9,g11,h10,h11,h12'
},
# ... I4 via H7->I7
{
resource => 'I4',
request => { REQUEST_METHOD => 'PUT', HTTP_IF_MATCH => '0xDEADPORK' },
response => [ 301, [ 'Location' => '/foo/bar', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,i4'
},
{
resource => 'I4b',
request => { REQUEST_METHOD => 'PUT', HTTP_IF_MATCH => '0xDEADPORK' },
response => [ 500, [ 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,i4'
},
# ... J18 via H10->I12->I13
{
resource => 'J18',
request => { REQUEST_METHOD => 'GET', HTTP_IF_NONE_MATCH => '*' },
response => [ 304, [ 'ETag' => '"0xDEADBEEF"', 'Last-Modified' => 'Sun, 18 Mar 2012 15:45:00 GMT' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,j18'
},
{
resource => 'J18',
request => { REQUEST_METHOD => 'HEAD', HTTP_IF_NONE_MATCH => '*' },
response => [ 304, [ 'ETag' => '"0xDEADBEEF"', 'Last-Modified' => 'Sun, 18 Mar 2012 15:45:00 GMT' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,j18'
},
{
resource => 'J18',
request => { REQUEST_METHOD => 'PUT', HTTP_IF_NONE_MATCH => '*' },
response => [ 412, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,j18'
},
# ... J18 via H10->H11->H12->I12->I13
{
resource => 'J18',
request => { REQUEST_METHOD => 'GET', HTTP_IF_NONE_MATCH => '*', HTTP_IF_UNMODIFIED_SINCE => '18 Mar 2012 15:49:00 GMT' },
response => [ 304, [ 'ETag' => '"0xDEADBEEF"', 'Last-Modified' => 'Sun, 18 Mar 2012 15:45:00 GMT' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,h11,h12,i12,i13,j18'
},
{
resource => 'J18',
request => { REQUEST_METHOD => 'HEAD', HTTP_IF_NONE_MATCH => '*', HTTP_IF_UNMODIFIED_SINCE => '18 Mar 2012 15:49:00 GMT' },
response => [ 304, [ 'ETag' => '"0xDEADBEEF"', 'Last-Modified' => 'Sun, 18 Mar 2012 15:45:00 GMT' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,h11,h12,i12,i13,j18'
},
{
resource => 'J18',
request => { REQUEST_METHOD => 'PUT', HTTP_IF_NONE_MATCH => '*', HTTP_IF_UNMODIFIED_SINCE => '18 Mar 2012 15:49:00 GMT' },
response => [ 412, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,h11,h12,i12,i13,j18'
},
# ... J18 via H10->I12->I13->K13
{
resource => 'J18',
request => { REQUEST_METHOD => 'GET', HTTP_IF_NONE_MATCH => '0xDEADBEEF' },
response => [ 304, [ 'ETag' => '"0xDEADBEEF"', 'Last-Modified' => 'Sun, 18 Mar 2012 15:45:00 GMT' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,j18'
},
{
resource => 'J18',
request => { REQUEST_METHOD => 'HEAD', HTTP_IF_NONE_MATCH => '0xDEADBEEF' },
response => [ 304, [ 'ETag' => '"0xDEADBEEF"', 'Last-Modified' => 'Sun, 18 Mar 2012 15:45:00 GMT' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,j18'
},
{
resource => 'J18',
request => { REQUEST_METHOD => 'PUT', HTTP_IF_NONE_MATCH => '0xDEADBEEF' },
response => [ 412, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], ['Precondition Failed'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,j18'
},
# ...
{
resource => 'P3',
request => { REQUEST_METHOD => 'PUT' },
response => [ 409, [ 'Content-Type' => 'text/plain' ], ['Conflict'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,i4,p3'
},
{
resource => 'P3b',
request => { REQUEST_METHOD => 'PUT' },
response => [ 415, [ 'Content-Type' => 'text/plain' ], ['Unsupported Media Type'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,i4,p3'
},
{
resource => 'P3b',
request => { REQUEST_METHOD => 'PUT', CONTENT_TYPE => 'text/plain' },
response => [ 500, [ 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,i4,p3'
},
# ... K5 via H7->I7->K7
{
resource => 'K5',
request => { REQUEST_METHOD => 'GET' },
response => [ 301, [ 'Location' => '/foo/bar', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5'
},
{
resource => 'K5b',
request => { REQUEST_METHOD => 'GET' },
response => [ 500, [ 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5'
},
# ... L7 via H7->I7->K7
{
resource => 'L7',
request => { REQUEST_METHOD => 'GET' },
response => [ 404, [ 'Content-Type' => 'text/plain' ], ['Not Found'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,l7'
},
# ... M7 via H7->I7->K7->L7
{
resource => 'M7',
request => { REQUEST_METHOD => 'POST' },
response => [ 404, [ 'Content-Type' => 'text/plain' ], ['Not Found'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,l7,m7'
},
# ... L5 via H7->I7->K7->K5
{
resource => 'L5',
request => { REQUEST_METHOD => 'GET' },
response => [ 307, [ 'Location' => '/foo/bar', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5'
},
{
resource => 'L5b',
request => { REQUEST_METHOD => 'GET' },
response => [ 500, [ 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5'
},
# ... M5 via H7->I7->K7->K5->L5
{
resource => 'M5',
request => { REQUEST_METHOD => 'GET' },
response => [ 410, [ 'Content-Type' => 'text/plain' ], ['Gone'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5'
},
# ... N5 via H7->I7->K7->K5->L5->M5
{
resource => 'N5',
request => { REQUEST_METHOD => 'POST' },
response => [ 410, [ 'Content-Type' => 'text/plain' ], ['Gone'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5'
},
# send a content type we dont handle
{
resource => 'N11',
request => { REQUEST_METHOD => 'POST', SCRIPT_NAME => '/bar', CONTENT_TYPE => 'text/plain' },
response => [ 415, [ 'Location' => '/bar/foo', 'Content-Type' => 'text/plain' ], ['Unsupported Media Type'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11'
},
# ...
{
resource => 'N11b',
request => { REQUEST_METHOD => 'POST' },
response => [ 500, [ 'Location' => '/baz/bar/foo', 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11'
},
# ...
{
resource => 'N11c',
request => { REQUEST_METHOD => 'POST' },
response => [ 500, [ 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11'
},
# ...
{
resource => 'N11d',
request => { REQUEST_METHOD => 'POST' },
response => qr/^Process Post Invalid/,
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11'
},
# ...
{
resource => 'N11e',
request => { REQUEST_METHOD => 'POST' },
response => qr/^Create Path Nil/,
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11'
},
# ...
{
resource => 'N11f',
request => { REQUEST_METHOD => 'POST' },
response => [ 303, [ 'Location' => '/foo/bar/baz', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11'
},
# ...
{
resource => 'N11g',
request => { REQUEST_METHOD => 'POST' },
response => qr/^Bad Redirect/,
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11'
},
# ... P11 via H7->I7->K7->K5->L5->M5->N5->N11
{
resource => 'P11',
request => { REQUEST_METHOD => 'POST' },
response => [ 201, [ 'Location' => '/foo', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11,p11'
},
# add a base to the request
{
resource => 'P11',
request => { REQUEST_METHOD => 'POST', SCRIPT_NAME => '/bar' },
response => [ 201, [ 'Location' => '/bar/foo', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11,p11'
},
# ...
{
resource => 'P11b',
request => { REQUEST_METHOD => 'POST' },
response => [ 201, [ 'Location' => '/baz/bar/foo', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11,p11'
},
# ...
{
resource => 'P11c',
request => { REQUEST_METHOD => 'POST' },
response => [ 201, [ 'Location' => '/foo/bar/baz', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11,p11'
},
# ...
{
resource => 'P11d',
request => { REQUEST_METHOD => 'PUT', CONTENT_TYPE => 'text/plain' },
response => [ 201, [ 'Location' => '/foo/bar/baz', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,i4,p3,p11'
},
# O18 via N11
{
resource => 'O18',
request => { REQUEST_METHOD => 'POST' },
response => [ 200, [ 'Content-Length' => 11, 'Content-Type' => 'text/plain' ], [ 'HELLO WORLD' ] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11,p11,o20,o18,o18b'
},
{
resource => 'O18b',
request => { REQUEST_METHOD => 'POST' },
response => [ 300, [ 'Content-Length' => 11, 'Content-Type' => 'text/plain' ], [ 'HELLO WORLD' ] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11,p11,o20,o18,o18b'
},
# ...
{
resource => 'O18d',
request => { REQUEST_METHOD => 'PUT', CONTENT_TYPE => 'text/plain' },
response => [ 200, [ 'Content-Type' => 'text/plain' ], [ 'HELLO WORLD' ] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,i4,p3,p11,o20,o18,o18b'
},
# O20 via N11
{
resource => 'O20',
request => { REQUEST_METHOD => 'POST' },
response => [ 204, [ 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,k7,k5,l5,m5,n5,n11,p11,o20'
},
{
resource => 'O20b',
request => { REQUEST_METHOD => 'PUT', CONTENT_TYPE => 'text/plain' },
response => [ 204, [ 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,h7,i7,i4,p3,p11,o20'
},
# L17 via L13,L14,L15,L16
{
resource => 'L17',
request => { REQUEST_METHOD => 'GET', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2001 15:49:00 GMT' },
response => [ 304, [ 'ETag' => '"0xDEADBEEF"', 'Last-Modified' => 'Sat, 18 Mar 2000 15:45:00 GMT' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,l17'
},
# M20 via L15,M16
{
resource => 'M20',
request => { REQUEST_METHOD => 'DELETE', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2036 15:49:00 GMT' },
response => [ 202, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,m16,m20,m20b'
},
{
resource => 'M20b',
request => { REQUEST_METHOD => 'DELETE', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2036 15:49:00 GMT' },
response => [ 500, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,m16,m20'
},
# O20
{
resource => 'O20c',
request => { REQUEST_METHOD => 'DELETE', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2036 15:49:00 GMT' },
response => [ 204, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,m16,m20,m20b,o20'
},
# O18
{
resource => 'O18c',
request => { REQUEST_METHOD => 'DELETE', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2036 15:49:00 GMT' },
response => [ 200, [ 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], [ 'HELLO WORLD' ] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,m16,m20,m20b,o20,o18,o18b'
},
# N11
{
resource => 'N11h',
request => { REQUEST_METHOD => 'POST', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2036 15:49:00 GMT' },
response => [ 303, [ 'Location' => '/foo/bar', 'Content-Encoding' => 'gzip', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,m16,n16,n11'
},
# O14
{
resource => 'O14',
request => { REQUEST_METHOD => 'PUT', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2036 15:49:00 GMT' },
response => [ 409, [ 'Content-Type' => 'text/plain' ], ['Conflict'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,m16,n16,o16,o14'
},
{
resource => 'O14b',
request => { REQUEST_METHOD => 'PUT', CONTENT_TYPE => 'text/plain', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2036 15:49:00 GMT' },
response => [ 500, [ 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,m16,n16,o16,o14'
},
# P11
{
resource => 'P11e',
request => { REQUEST_METHOD => 'PUT', CONTENT_TYPE => 'text/plain', HTTP_IF_NONE_MATCH => '0xDEADPORK', HTTP_IF_MODIFIED_SINCE => '18 Mar 2036 15:49:00 GMT' },
response => [ 201, [ 'Location' => '/foo/bar', 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,i13,k13,l13,l14,l15,m16,n16,o16,o14,p11'
},
# O18e
{
resource => 'O18e',
request => { REQUEST_METHOD => 'GET', CONTENT_TYPE => 'text/plain' },
response => [ 200, [ 'Content-Length' => 11, 'Content-Type' => 'text/plain' ], [ 'HELLO WORLD' ] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,l13,m16,n16,o16,o18,o18b'
},
{
resource => 'O18e',
request => { REQUEST_METHOD => 'HEAD', CONTENT_TYPE => 'text/plain' },
response => [ 200, [ 'Content-Type' => 'text/plain' ], [] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,l13,m16,n16,o16,o18,o18b'
},
{
resource => 'O18f',
request => { REQUEST_METHOD => 'GET', CONTENT_TYPE => 'text/plain' },
response => [ 500, [ 'Content-Type' => 'text/plain' ], ['Internal Server Error'] ],
trace => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,d4,e5,f6,g7,g8,h10,i12,l13,m16,n16,o16,o18'
},
);
foreach my $test ( @tests ) {
my $resource = Plack::Util::load_class( $test->{'resource'} );
my $request = inflate_headers( Plack::Request->new( $test->{'request'} ) );
my $r = $resource->new(
request => $request,
response => Plack::Response->new
);
my $response;
is(exception {
$response = $fsm->run( $r );
}, undef, '... ran resource (' . $test->{'resource'}. ') successfully');
isa_ok($response, 'Plack::Response');
my $trace = $response->header( $fsm->tracing_header );
is( $trace, $test->{'trace'}, '... got the trace we expected' );
$response->headers->remove_header( $fsm->tracing_header );
my $finalized = $response->finalize;
if ( ref $test->{'response'} eq 'ARRAY' ) {
my $got_headers = { @{ $finalized->[1] } };
my $expected_headers = { @{ $test->{'response'}[1] } };
if ( !Plack::Util::status_with_no_entity_body($test->{'response'}[0] ) ) {
$expected_headers->{'Content-Length'} = Plack::Util::content_length( $test->{'response'}[2] );
}
is( $finalized->[0], $test->{'response'}[0], '... got the status for resource (' . $test->{'resource'} . ') we expected' );
is_deeply( $got_headers, $expected_headers, '... got the headers for resource (' . $test->{'resource'} . ') we expected' );
is_deeply( $finalized->[2], $test->{'response'}[2], '... got the body for resource (' . $test->{'resource'} . ') we expected' );
}
else {
is( $finalized->[0], 500, '... got the error status for resource (' . $test->{'resource'}. ') we expected' );
like( $finalized->[2]->[0], $test->{'response'}, '... got the error response for resource (' . $test->{'resource'}. ') we expected' );
}
}
done_testing;
|