2013-09-21 08:54:07 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2013 The Perkeep Authors.
|
2013-09-21 08:54:07 +00:00
|
|
|
|
|
|
|
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 server
|
|
|
|
|
|
|
|
import (
|
2018-01-16 23:03:16 +00:00
|
|
|
"context"
|
2013-09-24 08:38:38 +00:00
|
|
|
"fmt"
|
2013-09-21 08:54:07 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/blob"
|
|
|
|
"perkeep.org/pkg/blobserver"
|
|
|
|
"perkeep.org/pkg/index"
|
|
|
|
"perkeep.org/pkg/jsonsign"
|
|
|
|
"perkeep.org/pkg/schema"
|
|
|
|
"perkeep.org/pkg/test"
|
2013-09-21 08:54:07 +00:00
|
|
|
)
|
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
type shareTester struct {
|
|
|
|
t *testing.T
|
|
|
|
sto *test.Fetcher
|
2017-03-24 00:45:34 +00:00
|
|
|
signer *schema.Signer
|
2015-12-28 21:53:29 +00:00
|
|
|
handler *shareHandler
|
|
|
|
sleeps int
|
|
|
|
rec *httptest.ResponseRecorder
|
|
|
|
restoreLog func()
|
|
|
|
}
|
2013-09-24 08:38:38 +00:00
|
|
|
|
2018-01-16 23:03:16 +00:00
|
|
|
var ctxbg = context.Background()
|
|
|
|
|
2017-03-24 00:45:34 +00:00
|
|
|
// newSigner returns the armored public key of the newly created signer as well,
|
|
|
|
// so we can upload it to the index.
|
|
|
|
func newSigner(t *testing.T) (*schema.Signer, string) {
|
|
|
|
ent, err := jsonsign.NewEntity()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
armorPub, err := jsonsign.ArmoredPublicKey(ent)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-01-09 23:07:38 +00:00
|
|
|
pubRef := blob.RefFromString(armorPub)
|
2017-03-24 00:45:34 +00:00
|
|
|
sig, err := schema.NewSigner(pubRef, strings.NewReader(armorPub), ent)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewSigner: %v", err)
|
|
|
|
}
|
|
|
|
return sig, armorPub
|
|
|
|
}
|
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
func newShareTester(t *testing.T) *shareTester {
|
2017-03-24 00:45:34 +00:00
|
|
|
return newShareTesterIdx(t, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newShareTesterIdx(t *testing.T, withIndex bool) *shareTester {
|
2015-12-28 21:53:29 +00:00
|
|
|
sto := new(test.Fetcher)
|
2017-03-24 00:45:34 +00:00
|
|
|
var idx *index.Index
|
|
|
|
var sig *schema.Signer
|
|
|
|
var armorPub string
|
|
|
|
if withIndex {
|
|
|
|
idx = index.NewMemoryIndex()
|
|
|
|
idx.InitBlobSource(sto)
|
|
|
|
if _, err := idx.KeepInMemory(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
sig, armorPub = newSigner(t)
|
|
|
|
}
|
2015-12-28 21:53:29 +00:00
|
|
|
st := &shareTester{
|
|
|
|
t: t,
|
|
|
|
sto: sto,
|
2017-03-24 00:45:34 +00:00
|
|
|
signer: sig,
|
|
|
|
handler: &shareHandler{fetcher: sto, idx: idx},
|
2015-12-28 21:53:29 +00:00
|
|
|
restoreLog: test.TLog(t),
|
2013-09-24 08:38:38 +00:00
|
|
|
}
|
2017-03-24 00:45:34 +00:00
|
|
|
if withIndex {
|
2018-01-09 23:07:38 +00:00
|
|
|
st.putRaw(blob.RefFromString(armorPub), armorPub)
|
2017-03-24 00:45:34 +00:00
|
|
|
}
|
2015-12-28 21:53:29 +00:00
|
|
|
timeSleep = func(d time.Duration) {
|
|
|
|
st.sleeps++
|
|
|
|
}
|
|
|
|
return st
|
|
|
|
}
|
|
|
|
|
|
|
|
func (st *shareTester) done() {
|
|
|
|
timeSleep = time.Sleep
|
|
|
|
st.restoreLog()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (st *shareTester) slept() bool {
|
|
|
|
v := st.sleeps > 0
|
|
|
|
st.sleeps = 0
|
|
|
|
return v
|
|
|
|
}
|
2013-09-24 08:38:38 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
func (st *shareTester) putRaw(ref blob.Ref, data string) {
|
2018-01-16 23:03:16 +00:00
|
|
|
if _, err := blobserver.Receive(ctxbg, st.sto, ref, strings.NewReader(data)); err != nil {
|
2017-03-24 00:45:34 +00:00
|
|
|
st.t.Fatalf("error storing %q: %v", ref, err)
|
|
|
|
}
|
|
|
|
if st.handler.idx != nil {
|
2018-01-16 23:03:16 +00:00
|
|
|
if _, err := st.handler.idx.ReceiveBlob(ctxbg, ref, strings.NewReader(data)); err != nil {
|
2017-03-24 00:45:34 +00:00
|
|
|
st.t.Fatalf("error indexing %q, with schema \n%q\n: %v", ref, data, err)
|
|
|
|
}
|
2013-09-24 08:38:38 +00:00
|
|
|
}
|
2015-12-28 21:53:29 +00:00
|
|
|
}
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
func (st *shareTester) put(blob *schema.Blob) {
|
|
|
|
st.putRaw(blob.BlobRef(), blob.JSON())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (st *shareTester) get(path string) *shareError {
|
|
|
|
st.rec = httptest.NewRecorder()
|
|
|
|
req, err := http.NewRequest("GET", "http://unused/"+path, nil)
|
|
|
|
if err != nil {
|
|
|
|
st.t.Fatalf("NewRequest(path=%q): %v", path, err)
|
|
|
|
}
|
|
|
|
if err := st.handler.serveHTTP(st.rec, req); err != nil {
|
|
|
|
return err.(*shareError)
|
2013-09-21 08:54:07 +00:00
|
|
|
}
|
2015-12-28 21:53:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
func (st *shareTester) testGet(path string, wantErr errorCode) {
|
|
|
|
gotErr := st.get(path)
|
|
|
|
if wantErr != noError {
|
|
|
|
if gotErr == nil || gotErr.code != wantErr {
|
|
|
|
st.t.Errorf("Fetching %s, error = %v; want %v", path, gotErr, wantErr)
|
2014-09-01 06:46:37 +00:00
|
|
|
}
|
2015-12-28 21:53:29 +00:00
|
|
|
} else {
|
|
|
|
if gotErr != nil {
|
|
|
|
st.t.Errorf("Fetching %s, error = %v; want success", path, gotErr)
|
2014-09-01 06:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-28 21:53:29 +00:00
|
|
|
}
|
2014-09-01 06:46:37 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
func TestHandleGetViaSharing(t *testing.T) {
|
|
|
|
st := newShareTester(t)
|
|
|
|
defer st.done()
|
|
|
|
|
|
|
|
content := "monkey" // the secret
|
2018-01-09 23:07:38 +00:00
|
|
|
contentRef := blob.RefFromString(content)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
link := fmt.Sprintf(`{"camliVersion": 1,
|
|
|
|
"camliType": "file",
|
|
|
|
"parts": [
|
|
|
|
{"blobRef": "%v", "size": %d}
|
|
|
|
]}`, contentRef, len(content))
|
2018-01-09 23:07:38 +00:00
|
|
|
linkRef := blob.RefFromString(link)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2014-09-04 21:56:01 +00:00
|
|
|
share := schema.NewShareRef(schema.ShareHaveRef, false).
|
|
|
|
SetShareTarget(linkRef).
|
2018-01-09 23:07:38 +00:00
|
|
|
SetSigner(blob.RefFromString("irrelevant")).
|
2013-09-21 08:54:07 +00:00
|
|
|
SetRawStringField("camliSig", "alsounused")
|
2015-12-28 21:53:29 +00:00
|
|
|
shareRef := func() blob.Ref { return share.Blob().BlobRef() }
|
|
|
|
|
|
|
|
t.Logf("Checking share blob doesn't yet exist...")
|
|
|
|
st.testGet(shareRef().String(), shareFetchFailed)
|
|
|
|
if !st.slept() {
|
|
|
|
t.Error("expected sleep after miss")
|
|
|
|
}
|
|
|
|
st.put(share.Blob())
|
|
|
|
t.Logf("Checking share blob now exists...")
|
|
|
|
st.testGet(shareRef().String(), noError)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
t.Logf("Checking we can't get the content directly via the share...")
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s", contentRef, shareRef()), shareTargetInvalid)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
t.Logf("Checking we can't get the link (file) blob directly...")
|
|
|
|
st.putRaw(linkRef, link)
|
|
|
|
st.testGet(linkRef.String(), shareBlobInvalid)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2016-05-11 21:58:15 +00:00
|
|
|
t.Logf("Checking we can get the link (file) blob via the share...")
|
2015-12-28 21:53:29 +00:00
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s", linkRef, shareRef()), noError)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2016-05-11 21:58:15 +00:00
|
|
|
t.Logf("Checking we can't get the content via the non-transitive share...")
|
2015-12-28 21:53:29 +00:00
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), shareNotTransitive)
|
|
|
|
|
|
|
|
// TODO: new test?
|
2013-09-21 08:54:07 +00:00
|
|
|
share.SetShareIsTransitive(true)
|
2015-12-28 21:53:29 +00:00
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", linkRef, shareRef(), linkRef), viaChainInvalidLink)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
st.putRaw(contentRef, content)
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), noError)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
// new test?
|
2013-09-21 08:54:07 +00:00
|
|
|
share.SetShareExpiration(time.Now().Add(-time.Duration(10) * time.Minute))
|
2015-12-28 21:53:29 +00:00
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), shareExpired)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
|
|
|
share.SetShareExpiration(time.Now().Add(time.Duration(10) * time.Minute))
|
2015-12-28 21:53:29 +00:00
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), noError)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Issue 228: only follow transitive blobref links in known trusted schema fields.
|
|
|
|
func TestSharingTransitiveSafety(t *testing.T) {
|
|
|
|
st := newShareTester(t)
|
|
|
|
defer st.done()
|
|
|
|
|
|
|
|
content := "the secret"
|
2018-01-09 23:07:38 +00:00
|
|
|
contentRef := blob.RefFromString(content)
|
2015-12-28 21:53:29 +00:00
|
|
|
|
|
|
|
// User-injected blob, somehow.
|
|
|
|
evilClaim := fmt.Sprintf("Some payload containing the ref: %v", contentRef)
|
2018-01-09 23:07:38 +00:00
|
|
|
evilClaimRef := blob.RefFromString(evilClaim)
|
2013-09-21 08:54:07 +00:00
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
share := schema.NewShareRef(schema.ShareHaveRef, false).
|
|
|
|
SetShareTarget(evilClaimRef).
|
|
|
|
SetShareIsTransitive(true).
|
2018-01-09 23:07:38 +00:00
|
|
|
SetSigner(blob.RefFromString("irrelevant")).
|
2015-12-28 21:53:29 +00:00
|
|
|
SetRawStringField("camliSig", "alsounused")
|
|
|
|
shareRef := func() blob.Ref { return share.Blob().BlobRef() }
|
|
|
|
|
|
|
|
st.put(share.Blob())
|
|
|
|
st.putRaw(contentRef, content)
|
|
|
|
st.putRaw(evilClaimRef, evilClaim)
|
|
|
|
|
|
|
|
st.testGet(shareRef().String(), noError)
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s", evilClaimRef, shareRef()), noError)
|
|
|
|
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), evilClaimRef), viaChainInvalidLink)
|
|
|
|
if !st.slept() {
|
|
|
|
t.Error("expected sleep after miss")
|
|
|
|
}
|
2013-09-21 08:54:07 +00:00
|
|
|
}
|
2015-12-28 21:53:29 +00:00
|
|
|
|
2016-05-11 21:58:15 +00:00
|
|
|
// TODO(mpl): try to refactor TestHandleGet*, but there are enough subtle differences to barely make it worth it
|
|
|
|
|
|
|
|
func TestHandleGetFilePartViaSharing(t *testing.T) {
|
|
|
|
st := newShareTester(t)
|
|
|
|
defer st.done()
|
|
|
|
|
|
|
|
content1 := "monkey" // part1
|
2018-01-09 23:07:38 +00:00
|
|
|
contentRef1 := blob.RefFromString(content1)
|
2016-05-11 21:58:15 +00:00
|
|
|
content2 := "banana" // part2
|
2018-01-09 23:07:38 +00:00
|
|
|
contentRef2 := blob.RefFromString(content2)
|
2016-05-11 21:58:15 +00:00
|
|
|
|
|
|
|
link := fmt.Sprintf(`{"camliVersion": 1,
|
|
|
|
"camliType": "file",
|
|
|
|
"parts": [
|
|
|
|
{"blobRef": "%v", "size": %d},
|
|
|
|
{"blobRef": "%v", "size": %d}
|
|
|
|
]}`, contentRef1, len(content1), contentRef2, len(content2))
|
2018-01-09 23:07:38 +00:00
|
|
|
linkRef := blob.RefFromString(link)
|
2016-05-11 21:58:15 +00:00
|
|
|
|
|
|
|
share := schema.NewShareRef(schema.ShareHaveRef, false).
|
|
|
|
SetShareTarget(linkRef).
|
2018-01-09 23:07:38 +00:00
|
|
|
SetSigner(blob.RefFromString("irrelevant")).
|
2016-05-11 21:58:15 +00:00
|
|
|
SetRawStringField("camliSig", "alsounused")
|
|
|
|
shareRef := func() blob.Ref { return share.Blob().BlobRef() }
|
|
|
|
|
|
|
|
t.Logf("Checking share blob doesn't yet exist...")
|
|
|
|
st.testGet(shareRef().String(), shareFetchFailed)
|
|
|
|
if !st.slept() {
|
|
|
|
t.Error("expected sleep after miss")
|
|
|
|
}
|
|
|
|
st.put(share.Blob())
|
|
|
|
t.Logf("Checking share blob now exists...")
|
|
|
|
st.testGet(shareRef().String(), noError)
|
|
|
|
|
|
|
|
t.Logf("Checking we can't get the content directly via the share...")
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s", contentRef2, shareRef()), shareTargetInvalid)
|
|
|
|
|
|
|
|
t.Logf("Checking we can't get the link (file) blob directly...")
|
|
|
|
st.putRaw(linkRef, link)
|
|
|
|
st.testGet(linkRef.String(), shareBlobInvalid)
|
|
|
|
|
|
|
|
t.Logf("Checking we can get the link (file) blob via the share...")
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s", linkRef, shareRef()), noError)
|
|
|
|
|
|
|
|
t.Logf("Checking we can't get the content via the non-transitive share...")
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef2, shareRef(), linkRef), shareNotTransitive)
|
|
|
|
|
|
|
|
// TODO: new test?
|
|
|
|
share.SetShareIsTransitive(true)
|
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", linkRef, shareRef(), linkRef), viaChainInvalidLink)
|
|
|
|
|
|
|
|
st.putRaw(contentRef2, content2)
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef2, shareRef(), linkRef), noError)
|
|
|
|
|
|
|
|
// new test?
|
|
|
|
share.SetShareExpiration(time.Now().Add(-time.Duration(10) * time.Minute))
|
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef2, shareRef(), linkRef), shareExpired)
|
|
|
|
|
|
|
|
share.SetShareExpiration(time.Now().Add(time.Duration(10) * time.Minute))
|
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef2, shareRef(), linkRef), noError)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHandleGetBytesPartViaSharing(t *testing.T) {
|
|
|
|
st := newShareTester(t)
|
|
|
|
defer st.done()
|
|
|
|
|
|
|
|
content1 := "monkey" // part1
|
2018-01-09 23:07:38 +00:00
|
|
|
contentRef1 := blob.RefFromString(content1)
|
2016-05-11 21:58:15 +00:00
|
|
|
content2 := "banana" // part2
|
2018-01-09 23:07:38 +00:00
|
|
|
contentRef2 := blob.RefFromString(content2)
|
2016-05-11 21:58:15 +00:00
|
|
|
|
|
|
|
link2 := fmt.Sprintf(`{"camliVersion": 1,
|
|
|
|
"camliType": "bytes",
|
|
|
|
"parts": [
|
|
|
|
{"blobRef": "%v", "size": %d},
|
|
|
|
{"blobRef": "%v", "size": %d}
|
|
|
|
]}`, contentRef1, len(content1), contentRef2, len(content2))
|
2018-01-09 23:07:38 +00:00
|
|
|
linkRef2 := blob.RefFromString(link2)
|
2016-05-11 21:58:15 +00:00
|
|
|
|
|
|
|
link1 := fmt.Sprintf(`{"camliVersion": 1,
|
|
|
|
"camliType": "file",
|
|
|
|
"parts": [
|
|
|
|
{"blobRef": "%v", "size": %d},
|
|
|
|
{"bytesRef": "%v", "size": %d}
|
2018-01-09 23:07:38 +00:00
|
|
|
]}`, blob.RefFromString("irrelevant content"), len("irrelevant content"), linkRef2, len(link2))
|
|
|
|
linkRef1 := blob.RefFromString(link1)
|
2016-05-11 21:58:15 +00:00
|
|
|
|
|
|
|
share := schema.NewShareRef(schema.ShareHaveRef, false).
|
|
|
|
SetShareTarget(linkRef1).
|
2018-01-09 23:07:38 +00:00
|
|
|
SetSigner(blob.RefFromString("irrelevant")).
|
2016-05-11 21:58:15 +00:00
|
|
|
SetRawStringField("camliSig", "alsounused")
|
|
|
|
shareRef := func() blob.Ref { return share.Blob().BlobRef() }
|
|
|
|
|
|
|
|
t.Logf("Checking share blob doesn't yet exist...")
|
|
|
|
st.testGet(shareRef().String(), shareFetchFailed)
|
|
|
|
if !st.slept() {
|
|
|
|
t.Error("expected sleep after miss")
|
|
|
|
}
|
|
|
|
st.put(share.Blob())
|
|
|
|
t.Logf("Checking share blob now exists...")
|
|
|
|
st.testGet(shareRef().String(), noError)
|
|
|
|
|
|
|
|
t.Logf("Checking we can't get the content directly via the share...")
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s", contentRef2, shareRef()), shareTargetInvalid)
|
|
|
|
|
|
|
|
t.Logf("Checking we can't get the link (file) blob directly...")
|
|
|
|
st.putRaw(linkRef1, link1)
|
|
|
|
st.testGet(linkRef1.String(), shareBlobInvalid)
|
|
|
|
|
|
|
|
t.Logf("Checking we can get the link (file) blob via the share...")
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s", linkRef1, shareRef()), noError)
|
|
|
|
|
|
|
|
t.Logf("Checking we can't get the deeper link (bytes) blob via the non-transitive share...")
|
|
|
|
st.putRaw(linkRef2, link2)
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", linkRef2, shareRef(), linkRef1), shareNotTransitive)
|
|
|
|
|
|
|
|
// TODO: new test?
|
|
|
|
share.SetShareIsTransitive(true)
|
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s,%s", linkRef2, shareRef(), linkRef1, linkRef2), viaChainInvalidLink)
|
|
|
|
|
|
|
|
st.putRaw(contentRef2, content2)
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s,%s", contentRef2, shareRef(), linkRef1, linkRef2), noError)
|
|
|
|
|
|
|
|
// new test?
|
|
|
|
share.SetShareExpiration(time.Now().Add(-time.Duration(10) * time.Minute))
|
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s,%s", contentRef2, shareRef(), linkRef1, linkRef2), shareExpired)
|
|
|
|
|
|
|
|
share.SetShareExpiration(time.Now().Add(time.Duration(10) * time.Minute))
|
|
|
|
st.put(share.Blob())
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s,%s", contentRef2, shareRef(), linkRef1, linkRef2), noError)
|
|
|
|
}
|
|
|
|
|
2015-12-28 21:53:29 +00:00
|
|
|
// TODO(aa): test the "assemble" mode too.
|
2017-03-24 00:45:34 +00:00
|
|
|
|
|
|
|
// TestHandleShareDeletion makes sure that deleting (with a delete claim) a
|
|
|
|
// share claim invalidates the sharing.
|
|
|
|
func TestHandleShareDeletion(t *testing.T) {
|
|
|
|
st := newShareTesterIdx(t, true)
|
|
|
|
defer st.done()
|
|
|
|
|
|
|
|
content := "monkey" // the secret
|
2018-01-09 23:07:38 +00:00
|
|
|
contentRef := blob.RefFromString(content)
|
2017-03-24 00:45:34 +00:00
|
|
|
|
|
|
|
link := fmt.Sprintf(`{"camliVersion": 1,
|
|
|
|
"camliType": "file",
|
|
|
|
"parts": [
|
|
|
|
{"blobRef": "%v", "size": %d}
|
|
|
|
]}`, contentRef, len(content))
|
2018-01-09 23:07:38 +00:00
|
|
|
linkRef := blob.RefFromString(link)
|
2017-03-24 00:45:34 +00:00
|
|
|
st.putRaw(contentRef, content)
|
|
|
|
st.putRaw(linkRef, link)
|
|
|
|
|
|
|
|
share := schema.NewShareRef(schema.ShareHaveRef, false).
|
|
|
|
SetShareTarget(linkRef).
|
|
|
|
SetShareIsTransitive(true)
|
2018-01-16 23:03:16 +00:00
|
|
|
signed, err := share.SignAt(ctxbg, st.signer, time.Now())
|
2017-03-24 00:45:34 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-01-09 23:07:38 +00:00
|
|
|
shareRef := blob.RefFromString(signed)
|
2017-03-24 00:45:34 +00:00
|
|
|
st.putRaw(shareRef, signed)
|
|
|
|
|
|
|
|
// Test we can get content.
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef, linkRef), noError)
|
|
|
|
|
|
|
|
// Delete share
|
|
|
|
deletion := schema.NewDeleteClaim(shareRef)
|
2018-01-16 23:03:16 +00:00
|
|
|
signedDel, err := deletion.SignAt(ctxbg, st.signer, time.Now())
|
2017-03-24 00:45:34 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-01-09 23:07:38 +00:00
|
|
|
deleteRef := blob.RefFromString(signedDel)
|
2017-03-24 00:45:34 +00:00
|
|
|
st.putRaw(deleteRef, signedDel)
|
|
|
|
|
|
|
|
// Test we can't get the content anymore
|
|
|
|
st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef, linkRef), shareDeleted)
|
|
|
|
|
|
|
|
// Test we can't even get the share itself anymore, just in case.
|
|
|
|
st.testGet(fmt.Sprintf("%s", shareRef), shareDeleted)
|
|
|
|
}
|