(t *testing.T)
| 306 | } |
| 307 | |
| 308 | func TestHandleGetBytesPartViaSharing(t *testing.T) { |
| 309 | st := newShareTester(t) |
| 310 | defer st.done() |
| 311 | |
| 312 | content1 := "monkey" // part1 |
| 313 | contentRef1 := blob.RefFromString(content1) |
| 314 | content2 := "banana" // part2 |
| 315 | contentRef2 := blob.RefFromString(content2) |
| 316 | |
| 317 | link2 := fmt.Sprintf(`{"camliVersion": 1, |
| 318 | "camliType": "bytes", |
| 319 | "parts": [ |
| 320 | {"blobRef": "%v", "size": %d}, |
| 321 | {"blobRef": "%v", "size": %d} |
| 322 | ]}`, contentRef1, len(content1), contentRef2, len(content2)) |
| 323 | linkRef2 := blob.RefFromString(link2) |
| 324 | |
| 325 | link1 := fmt.Sprintf(`{"camliVersion": 1, |
| 326 | "camliType": "file", |
| 327 | "parts": [ |
| 328 | {"blobRef": "%v", "size": %d}, |
| 329 | {"bytesRef": "%v", "size": %d} |
| 330 | ]}`, blob.RefFromString("irrelevant content"), len("irrelevant content"), linkRef2, len(link2)) |
| 331 | linkRef1 := blob.RefFromString(link1) |
| 332 | |
| 333 | share := schema.NewShareRef(schema.ShareHaveRef, false). |
| 334 | SetShareTarget(linkRef1). |
| 335 | SetSigner(blob.RefFromString("irrelevant")). |
| 336 | SetRawStringField("camliSig", "alsounused") |
| 337 | shareRef := func() blob.Ref { return share.Blob().BlobRef() } |
| 338 | |
| 339 | t.Logf("Checking share blob doesn't yet exist...") |
| 340 | st.testGet(shareRef().String(), shareFetchFailed) |
| 341 | if !st.slept() { |
| 342 | t.Error("expected sleep after miss") |
| 343 | } |
| 344 | st.put(share.Blob()) |
| 345 | t.Logf("Checking share blob now exists...") |
| 346 | st.testGet(shareRef().String(), noError) |
| 347 | |
| 348 | t.Logf("Checking we can't get the content directly via the share...") |
| 349 | st.testGet(fmt.Sprintf("%s?via=%s", contentRef2, shareRef()), shareTargetInvalid) |
| 350 | |
| 351 | t.Logf("Checking we can't get the link (file) blob directly...") |
| 352 | st.putRaw(linkRef1, link1) |
| 353 | st.testGet(linkRef1.String(), shareBlobInvalid) |
| 354 | |
| 355 | t.Logf("Checking we can get the link (file) blob via the share...") |
| 356 | st.testGet(fmt.Sprintf("%s?via=%s", linkRef1, shareRef()), noError) |
| 357 | |
| 358 | t.Logf("Checking we can't get the deeper link (bytes) blob via the non-transitive share...") |
| 359 | st.putRaw(linkRef2, link2) |
| 360 | st.testGet(fmt.Sprintf("%s?via=%s,%s", linkRef2, shareRef(), linkRef1), shareNotTransitive) |
| 361 | |
| 362 | // TODO: new test? |
| 363 | share.SetShareIsTransitive(true) |
| 364 | st.put(share.Blob()) |
| 365 | st.testGet(fmt.Sprintf("%s?via=%s,%s,%s", linkRef2, shareRef(), linkRef1, linkRef2), viaChainInvalidLink) |
nothing calls this directly
no test coverage detected