Refactor the multi-host salt install page.
[arvados.git] / services / keep-web / cadaver_test.go
index 22ddd84df09e1883fa0aa1d83d540211c0efc39d..742140f7f347d34f1c815f1712a3b39a84a8bf13 100644 (file)
@@ -2,22 +2,21 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-package main
+package keepweb
 
 import (
        "bytes"
        "fmt"
        "io"
        "io/ioutil"
-       "net/url"
        "os"
        "os/exec"
        "path/filepath"
        "strings"
        "time"
 
-       "git.curoverse.com/arvados.git/sdk/go/arvados"
-       "git.curoverse.com/arvados.git/sdk/go/arvadostest"
+       "git.arvados.org/arvados.git/sdk/go/arvados"
+       "git.arvados.org/arvados.git/sdk/go/arvadostest"
        check "gopkg.in/check.v1"
 )
 
@@ -72,7 +71,7 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun
        var newCollection arvados.Collection
        arv := arvados.NewClientFromEnv()
        arv.AuthToken = arvadostest.ActiveToken
-       err = arv.RequestAndDecode(&newCollection, "POST", "/arvados/v1/collections", bytes.NewBufferString(url.Values{"collection": {"{}"}}.Encode()), nil)
+       err = arv.RequestAndDecode(&newCollection, "POST", "arvados/v1/collections", nil, map[string]interface{}{"collection": map[string]interface{}{}})
        c.Assert(err, check.IsNil)
 
        readPath, writePath, pdhPath := pathFunc(newCollection)
@@ -133,6 +132,16 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun
                        match: `(?ms).*succeeded.*`,
                        data:  testdata,
                },
+               {
+                       path:  writePath,
+                       cmd:   "move testfile \"test &#!%20 file\"\n",
+                       match: `(?ms).*Moving .* succeeded.*`,
+               },
+               {
+                       path:  writePath,
+                       cmd:   "move \"test &#!%20 file\" testfile\n",
+                       match: `(?ms).*Moving .* succeeded.*`,
+               },
                {
                        path:  writePath,
                        cmd:   "move testfile newdir0/\n",
@@ -143,6 +152,16 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun
                        cmd:   "move testfile newdir0/\n",
                        match: `(?ms).*Moving .* failed.*`,
                },
+               {
+                       path:  writePath,
+                       cmd:   "lock newdir0/testfile\n",
+                       match: `(?ms).*Locking .* succeeded.*`,
+               },
+               {
+                       path:  writePath,
+                       cmd:   "unlock newdir0/testfile\nasdf\n",
+                       match: `(?ms).*Unlocking .* succeeded.*`,
+               },
                {
                        path:  writePath,
                        cmd:   "ls\n",
@@ -158,6 +177,16 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun
                        cmd:   "mkcol newdir1\n",
                        match: `(?ms).*Creating .* succeeded.*`,
                },
+               {
+                       path:  writePath,
+                       cmd:   "move newdir1/ newdir1x/\n",
+                       match: `(?ms).*Moving .* succeeded.*`,
+               },
+               {
+                       path:  writePath,
+                       cmd:   "move newdir1x newdir1\n",
+                       match: `(?ms).*Moving .* succeeded.*`,
+               },
                {
                        path:  writePath,
                        cmd:   "move newdir0/testfile newdir1/\n",
@@ -241,8 +270,13 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun
                        cmd:   "delete foo\n",
                        match: `(?ms).*Deleting .* failed:.*405 Method Not Allowed.*`,
                },
+               {
+                       path:  pdhPath,
+                       cmd:   "lock foo\n",
+                       match: `(?ms).*Locking .* failed:.*405 Method Not Allowed.*`,
+               },
        } {
-               c.Logf("%s %+v", "http://"+s.testServer.Addr, trial)
+               c.Logf("%s %+v", s.testServer.URL, trial)
                if skip != nil && skip(trial.path) {
                        c.Log("(skip)")
                        continue
@@ -265,6 +299,22 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun
        }
 }
 
+func (s *IntegrationSuite) TestCadaverByID(c *check.C) {
+       for _, path := range []string{"/by_id", "/by_id/"} {
+               stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls")
+               c.Check(stdout, check.Matches, `(?ms).*collection is empty.*`)
+       }
+       for _, path := range []string{
+               "/by_id/" + arvadostest.FooCollectionPDH,
+               "/by_id/" + arvadostest.FooCollectionPDH + "/",
+               "/by_id/" + arvadostest.FooCollection,
+               "/by_id/" + arvadostest.FooCollection + "/",
+       } {
+               stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls")
+               c.Check(stdout, check.Matches, `(?ms).*\s+foo\s+3 .*`)
+       }
+}
+
 func (s *IntegrationSuite) TestCadaverUsersDir(c *check.C) {
        for _, path := range []string{"/"} {
                stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls")
@@ -291,14 +341,14 @@ func (s *IntegrationSuite) runCadaver(c *check.C, password, path, stdin string)
        c.Assert(err, check.IsNil)
        defer os.RemoveAll(tempdir)
 
-       cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+path)
+       cmd := exec.Command("cadaver", s.testServer.URL+path)
        if password != "" {
                // cadaver won't try username/password authentication
                // unless the server responds 401 to an
                // unauthenticated request, which it only does in
                // AttachmentOnlyHost, TrustAllContent, and
                // per-collection vhost cases.
-               s.testServer.Config.AttachmentOnlyHost = s.testServer.Addr
+               s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = s.testServer.URL[7:]
 
                cmd.Env = append(os.Environ(), "HOME="+tempdir)
                f, err := os.OpenFile(filepath.Join(tempdir, ".netrc"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)