MCPcopy
hub / github.com/caddyserver/caddy / TestPathMatcherWindows

Function TestPathMatcherWindows

modules/caddyhttp/matchers_test.go:457–520  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

455}
456
457func TestPathMatcherWindows(t *testing.T) {
458 // only Windows has this bug where it will ignore
459 // trailing dots and spaces in a filename
460 if runtime.GOOS != "windows" {
461 return
462 }
463
464 repl := caddy.NewReplacer()
465
466 for _, tc := range []struct {
467 name string
468 path string
469 requestTarget string
470 match MatchPath
471 }{
472 {
473 name: "trailing dots and spaces",
474 path: "/index.php . . ..",
475 match: MatchPath{"*.php"},
476 },
477 {
478 name: "encoded backslash path separator",
479 requestTarget: `/private%5csecret.txt`,
480 match: MatchPath{"/private/*"},
481 },
482 {
483 name: "encoded backslash path separator with escaped wildcard",
484 requestTarget: `/private%5csecret.txt`,
485 match: MatchPath{"/private/%*"},
486 },
487 {
488 name: "uppercase encoded backslash path separator with escaped wildcard",
489 requestTarget: `/private%5Csecret.txt`,
490 match: MatchPath{"/private/%*"},
491 },
492 {
493 name: "encoded backslash in escaped pattern",
494 requestTarget: `/private%5csecret.txt`,
495 match: MatchPath{"/private%5c%*"},
496 },
497 } {
498 t.Run(tc.name, func(t *testing.T) {
499 u := &url.URL{Path: tc.path}
500 if tc.requestTarget != "" {
501 var err error
502 u, err = url.ParseRequestURI(tc.requestTarget)
503 if err != nil {
504 t.Fatalf("Parsing request target: %v", err)
505 }
506 }
507 req := &http.Request{URL: u}
508 ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
509 req = req.WithContext(ctx)
510
511 matched, err := tc.match.MatchWithError(req)
512 if err != nil {
513 t.Errorf("Expected no error, but got: %v", err)
514 }

Callers

nothing calls this directly

Calls 2

WithValueMethod · 0.80
MatchWithErrorMethod · 0.65

Tested by

no test coverage detected