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 e7463d31f..7fa1f4805 100644 Binary files a/pkg/test/testdata/server-config.json and b/pkg/test/testdata/server-config.json differ