MCPcopy Create free account
hub / github.com/caddyserver/caddy / TestRemoteAdminAccessControlPathSegmentMatching

Function TestRemoteAdminAccessControlPathSegmentMatching

admin_test.go:659–750  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

657}
658
659func TestRemoteAdminAccessControlPathSegmentMatching(t *testing.T) {
660 const authorizedKey testAdminPublicKey = "authorized"
661 peerCert := &x509.Certificate{PublicKey: authorizedKey}
662
663 tests := []struct {
664 name string
665 allowedPath string
666 requestPath string
667 wantErr bool
668 }{
669 {
670 name: "exact path",
671 allowedPath: "/pki/ca/prod",
672 requestPath: "/pki/ca/prod",
673 wantErr: false,
674 },
675 {
676 name: "subpath",
677 allowedPath: "/pki/ca/prod",
678 requestPath: "/pki/ca/prod/certificates",
679 wantErr: false,
680 },
681 {
682 name: "trailing slash subpath",
683 allowedPath: "/pki/ca/prod/",
684 requestPath: "/pki/ca/prod/certificates",
685 wantErr: false,
686 },
687 {
688 name: "sibling with shared prefix",
689 allowedPath: "/pki/ca/prod",
690 requestPath: "/pki/ca/prod-backup",
691 wantErr: true,
692 },
693 {
694 name: "same segment plus digit",
695 allowedPath: "/pki/ca/prod",
696 requestPath: "/pki/ca/prod1",
697 wantErr: true,
698 },
699 {
700 name: "root path",
701 allowedPath: "/",
702 requestPath: "/pki/ca/prod",
703 wantErr: false,
704 },
705 }
706
707 for i, test := range tests {
708 t.Run(test.name, func(t *testing.T) {
709 remote := RemoteAdmin{
710 AccessControl: []*AdminAccess{
711 {
712 Permissions: []AdminPermissions{
713 {
714 Methods: []string{http.MethodGet},
715 Paths: []string{test.allowedPath},
716 },

Callers

nothing calls this directly

Calls 1

enforceAccessControlsMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…