MCPcopy Create free account
hub / github.com/perkeep/perkeep / TestHandleGetFilePartViaSharing

Function TestHandleGetFilePartViaSharing

pkg/server/share_test.go:245–306  ·  view source on GitHub ↗

TODO(mpl): try to refactor TestHandleGet*, but there are enough subtle differences to barely make it worth it

(t *testing.T)

Source from the content-addressed store, hash-verified

243// TODO(mpl): try to refactor TestHandleGet*, but there are enough subtle differences to barely make it worth it
244
245func TestHandleGetFilePartViaSharing(t *testing.T) {
246 st := newShareTester(t)
247 defer st.done()
248
249 content1 := "monkey" // part1
250 contentRef1 := blob.RefFromString(content1)
251 content2 := "banana" // part2
252 contentRef2 := blob.RefFromString(content2)
253
254 link := fmt.Sprintf(`{"camliVersion": 1,
255"camliType": "file",
256"parts": [
257 {"blobRef": "%v", "size": %d},
258 {"blobRef": "%v", "size": %d}
259]}`, contentRef1, len(content1), contentRef2, len(content2))
260 linkRef := blob.RefFromString(link)
261
262 share := schema.NewShareRef(schema.ShareHaveRef, false).
263 SetShareTarget(linkRef).
264 SetSigner(blob.RefFromString("irrelevant")).
265 SetRawStringField("camliSig", "alsounused")
266 shareRef := func() blob.Ref { return share.Blob().BlobRef() }
267
268 t.Logf("Checking share blob doesn't yet exist...")
269 st.testGet(shareRef().String(), shareFetchFailed)
270 if !st.slept() {
271 t.Error("expected sleep after miss")
272 }
273 st.put(share.Blob())
274 t.Logf("Checking share blob now exists...")
275 st.testGet(shareRef().String(), noError)
276
277 t.Logf("Checking we can't get the content directly via the share...")
278 st.testGet(fmt.Sprintf("%s?via=%s", contentRef2, shareRef()), shareTargetInvalid)
279
280 t.Logf("Checking we can't get the link (file) blob directly...")
281 st.putRaw(linkRef, link)
282 st.testGet(linkRef.String(), shareBlobInvalid)
283
284 t.Logf("Checking we can get the link (file) blob via the share...")
285 st.testGet(fmt.Sprintf("%s?via=%s", linkRef, shareRef()), noError)
286
287 t.Logf("Checking we can't get the content via the non-transitive share...")
288 st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef2, shareRef(), linkRef), shareNotTransitive)
289
290 // TODO: new test?
291 share.SetShareIsTransitive(true)
292 st.put(share.Blob())
293 st.testGet(fmt.Sprintf("%s?via=%s,%s", linkRef, shareRef(), linkRef), viaChainInvalidLink)
294
295 st.putRaw(contentRef2, content2)
296 st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef2, shareRef(), linkRef), noError)
297
298 // new test?
299 share.SetShareExpiration(time.Now().Add(-time.Duration(10) * time.Minute))
300 st.put(share.Blob())
301 st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef2, shareRef(), linkRef), shareExpired)
302

Callers

nothing calls this directly

Calls 15

RefFromStringFunction · 0.92
NewShareRefFunction · 0.92
newShareTesterFunction · 0.85
doneMethod · 0.80
SetRawStringFieldMethod · 0.80
SetSignerMethod · 0.80
SetShareTargetMethod · 0.80
LogfMethod · 0.80
testGetMethod · 0.80
sleptMethod · 0.80
putMethod · 0.80
putRawMethod · 0.80

Tested by

no test coverage detected