diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-11-16 19:28:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-16 19:28:52 -0500 |
commit | 0135904f7d3e1c0e763adaefe267c736616e3d26 (patch) | |
tree | c27be7588f98eaea62e0bd0c0087f2b348da9738 /vendor/golang.org/x/net/webdav/webdav_test.go | |
parent | 0b296dd8c2aefefe89787be5cc627d44cf431150 (diff) | |
download | chat-0135904f7d3e1c0e763adaefe267c736616e3d26.tar.gz chat-0135904f7d3e1c0e763adaefe267c736616e3d26.tar.bz2 chat-0135904f7d3e1c0e763adaefe267c736616e3d26.zip |
Upgrading server dependancies (#4566)
Diffstat (limited to 'vendor/golang.org/x/net/webdav/webdav_test.go')
-rw-r--r-- | vendor/golang.org/x/net/webdav/webdav_test.go | 113 |
1 files changed, 86 insertions, 27 deletions
diff --git a/vendor/golang.org/x/net/webdav/webdav_test.go b/vendor/golang.org/x/net/webdav/webdav_test.go index b068aab32..25e0d5421 100644 --- a/vendor/golang.org/x/net/webdav/webdav_test.go +++ b/vendor/golang.org/x/net/webdav/webdav_test.go @@ -18,6 +18,8 @@ import ( "sort" "strings" "testing" + + "golang.org/x/net/context" ) // TODO: add tests to check XML responses with the expected prefix path @@ -48,7 +50,7 @@ func TestPrefix(t *testing.T) { req.Header.Add(headers[0], headers[1]) headers = headers[2:] } - res, err := http.DefaultClient.Do(req) + res, err := http.DefaultTransport.RoundTrip(req) if err != nil { return nil, err } @@ -65,6 +67,7 @@ func TestPrefix(t *testing.T) { "/a/b/", "/a/b/c/", } + ctx := context.Background() for _, prefix := range prefixes { fs := NewMemFS() h := &Handler{ @@ -183,7 +186,7 @@ func TestPrefix(t *testing.T) { continue } - got, err := find(nil, fs, "/") + got, err := find(ctx, nil, fs, "/") if err != nil { t.Errorf("prefix=%-9q find: %v", prefix, err) continue @@ -202,57 +205,110 @@ func TestPrefix(t *testing.T) { } } +func TestEscapeXML(t *testing.T) { + // These test cases aren't exhaustive, and there is more than one way to + // escape e.g. a quot (as """ or """) or an apos. We presume that + // the encoding/xml package tests xml.EscapeText more thoroughly. This test + // here is just a sanity check for this package's escapeXML function, and + // its attempt to provide a fast path (and avoid a bytes.Buffer allocation) + // when escaping filenames is obviously a no-op. + testCases := map[string]string{ + "": "", + " ": " ", + "&": "&", + "*": "*", + "+": "+", + ",": ",", + "-": "-", + ".": ".", + "/": "/", + "0": "0", + "9": "9", + ":": ":", + "<": "<", + ">": ">", + "A": "A", + "_": "_", + "a": "a", + "~": "~", + "\u0201": "\u0201", + "&": "&amp;", + "foo&<b/ar>baz": "foo&<b/ar>baz", + } + + for in, want := range testCases { + if got := escapeXML(in); got != want { + t.Errorf("in=%q: got %q, want %q", in, got, want) + } + } +} + func TestFilenameEscape(t *testing.T) { - re := regexp.MustCompile(`<D:href>([^<]*)</D:href>`) - do := func(method, urlStr string) (string, error) { + hrefRe := regexp.MustCompile(`<D:href>([^<]*)</D:href>`) + displayNameRe := regexp.MustCompile(`<D:displayname>([^<]*)</D:displayname>`) + do := func(method, urlStr string) (string, string, error) { req, err := http.NewRequest(method, urlStr, nil) if err != nil { - return "", err + return "", "", err } res, err := http.DefaultClient.Do(req) if err != nil { - return "", err + return "", "", err } defer res.Body.Close() b, err := ioutil.ReadAll(res.Body) if err != nil { - return "", err + return "", "", err + } + hrefMatch := hrefRe.FindStringSubmatch(string(b)) + if len(hrefMatch) != 2 { + return "", "", errors.New("D:href not found") } - m := re.FindStringSubmatch(string(b)) - if len(m) != 2 { - return "", errors.New("D:href not found") + displayNameMatch := displayNameRe.FindStringSubmatch(string(b)) + if len(displayNameMatch) != 2 { + return "", "", errors.New("D:displayname not found") } - return m[1], nil + return hrefMatch[1], displayNameMatch[1], nil } testCases := []struct { - name, want string + name, wantHref, wantDisplayName string }{{ - name: `/foo%bar`, - want: `/foo%25bar`, + name: `/foo%bar`, + wantHref: `/foo%25bar`, + wantDisplayName: `foo%bar`, }, { - name: `/こんにちわ世界`, - want: `/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F%E4%B8%96%E7%95%8C`, + name: `/こんにちわ世界`, + wantHref: `/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F%E4%B8%96%E7%95%8C`, + wantDisplayName: `こんにちわ世界`, }, { - name: `/Program Files/`, - want: `/Program%20Files`, + name: `/Program Files/`, + wantHref: `/Program%20Files`, + wantDisplayName: `Program Files`, }, { - name: `/go+lang`, - want: `/go+lang`, + name: `/go+lang`, + wantHref: `/go+lang`, + wantDisplayName: `go+lang`, }, { - name: `/go&lang`, - want: `/go&lang`, + name: `/go&lang`, + wantHref: `/go&lang`, + wantDisplayName: `go&lang`, + }, { + name: `/go<lang`, + wantHref: `/go%3Clang`, + wantDisplayName: `go<lang`, }} + ctx := context.Background() fs := NewMemFS() for _, tc := range testCases { if strings.HasSuffix(tc.name, "/") { - if err := fs.Mkdir(tc.name, 0755); err != nil { + if err := fs.Mkdir(ctx, tc.name, 0755); err != nil { t.Fatalf("name=%q: Mkdir: %v", tc.name, err) } } else { - f, err := fs.OpenFile(tc.name, os.O_CREATE, 0644) + f, err := fs.OpenFile(ctx, tc.name, os.O_CREATE, 0644) if err != nil { t.Fatalf("name=%q: OpenFile: %v", tc.name, err) } @@ -273,13 +329,16 @@ func TestFilenameEscape(t *testing.T) { for _, tc := range testCases { u.Path = tc.name - got, err := do("PROPFIND", u.String()) + gotHref, gotDisplayName, err := do("PROPFIND", u.String()) if err != nil { t.Errorf("name=%q: PROPFIND: %v", tc.name, err) continue } - if got != tc.want { - t.Errorf("name=%q: got %q, want %q", tc.name, got, tc.want) + if gotHref != tc.wantHref { + t.Errorf("name=%q: got href %q, want %q", tc.name, gotHref, tc.wantHref) + } + if gotDisplayName != tc.wantDisplayName { + t.Errorf("name=%q: got dispayname %q, want %q", tc.name, gotDisplayName, tc.wantDisplayName) } } } |