mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-25 10:14:36 +00:00

Fix the index out of bound panic when a request is made to the local fileserver mux with a valid secret-token, but missing share name. Example error: http: panic serving 127.0.0.1:40974: runtime error: slice bounds out of range [2:1] Additionally, we document the edge case behavior of utilities that this fileserver mux depends on. Signed-off-by: Craig Hesling <craig@hesling.com>
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package shared
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestCleanAndSplit(t *testing.T) {
|
|
tests := []struct {
|
|
path string
|
|
want []string
|
|
}{
|
|
{"", []string{""}},
|
|
{"/", []string{""}},
|
|
{"//", []string{""}},
|
|
{"a", []string{"a"}},
|
|
{"/a", []string{"a"}},
|
|
{"a/", []string{"a"}},
|
|
{"/a/", []string{"a"}},
|
|
{"a/b", []string{"a", "b"}},
|
|
{"/a/b", []string{"a", "b"}},
|
|
{"a/b/", []string{"a", "b"}},
|
|
{"/a/b/", []string{"a", "b"}},
|
|
{"/a/../b", []string{"b"}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.path, func(t *testing.T) {
|
|
if got := CleanAndSplit(tt.path); !reflect.DeepEqual(tt.want, got) {
|
|
t.Errorf("CleanAndSplit(%q) = %v; want %v", tt.path, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestJoin(t *testing.T) {
|
|
tests := []struct {
|
|
parts []string
|
|
want string
|
|
}{
|
|
{[]string{}, "/"},
|
|
{[]string{""}, "/"},
|
|
{[]string{"a"}, "/a"},
|
|
{[]string{"/a"}, "/a"},
|
|
{[]string{"/a/"}, "/a"},
|
|
{[]string{"/a/", "/b/"}, "/a/b"},
|
|
{[]string{"/a/../b", "c"}, "/b/c"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(Join(tt.parts...), func(t *testing.T) {
|
|
if got := Join(tt.parts...); !reflect.DeepEqual(tt.want, got) {
|
|
t.Errorf("Join(%v) = %q; want %q", tt.parts, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|