From 0eeea2ee0a603be2ed37b26aadf35765fc5d80b7 Mon Sep 17 00:00:00 2001 From: mpl Date: Mon, 4 Aug 2014 21:43:08 +0200 Subject: [PATCH] test/integration: add sharing test http://camlistore.org/issue/462 Change-Id: If7642eef597bf1d81a88738c1b831f582d7ace30 --- pkg/test/integration/share_test.go | 67 +++++++++++++++++++++++++++ pkg/test/testdata/server-config.json | Bin 1986 -> 2116 bytes 2 files changed, 67 insertions(+) create mode 100644 pkg/test/integration/share_test.go diff --git a/pkg/test/integration/share_test.go b/pkg/test/integration/share_test.go new file mode 100644 index 000000000..097cd72fd --- /dev/null +++ b/pkg/test/integration/share_test.go @@ -0,0 +1,67 @@ +/* +Copyright 2014 The Camlistore Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integration + +import ( + "fmt" + "io/ioutil" + "os" + "path/filepath" + "strings" + "testing" + + "camlistore.org/pkg/test" +) + +func TestFileSharing(t *testing.T) { + share(t, "share_test.go") +} + +func TestDirSharing(t *testing.T) { + share(t, filepath.FromSlash("../integration")) +} + +func share(t *testing.T, file string) { + w := test.GetWorld(t) + out := test.MustRunCmd(t, w.Cmd("camput", "file", file)) + fileRef := strings.Split(out, "\n")[0] + + out = test.MustRunCmd(t, w.Cmd("camput", "share", "-transitive", fileRef)) + shareRef := strings.Split(out, "\n")[0] + + testDir, err := ioutil.TempDir("", "camli-share-test-") + if err != nil { + t.Fatalf("ioutil.TempDir(): %v", err) + } + defer os.RemoveAll(testDir) + + // test that we can get it through the share + test.MustRunCmd(t, w.Cmd("camget", "-o", testDir, "-shared", fmt.Sprintf("%v/share/%v", w.ServerBaseURL(), shareRef))) + if _, err := os.Stat(filepath.Join(testDir, filepath.Base(file))); err != nil { + t.Fatalf("camget -shared failed to get %v: %v", file, err) + } + + // test that we're not allowed to get it directly + fileURL := fmt.Sprintf("%v/share/%v", w.ServerBaseURL(), fileRef) + _, err = test.RunCmd(w.Cmd("camget", "-shared", fileURL)) + if err == nil { + t.Fatal("Was expecting error for 'camget -shared " + fileURL + "'") + } + if !strings.Contains(err.Error(), "client: got status code 401") { + t.Fatalf("'camget -shared %v': got error %v, was expecting 401", fileURL, err) + } +} diff --git a/pkg/test/testdata/server-config.json b/pkg/test/testdata/server-config.json index e7463d31f288e3e01c2556cbc4df4e4120d7d327..7fa1f480568e5a01e256886afdac42a889953e80 100644 GIT binary patch delta 54 zcmX@ae?(xzZuZIV*tl4WGZKqZC+}vKWdSo3m~iaEO1yZuZHx9P9ub&;$1X