MCPcopy
hub / github.com/perkeep/perkeep / TestHandleGetViaSharing

Function TestHandleGetViaSharing

pkg/server/share_test.go:151–209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

149}
150
151func TestHandleGetViaSharing(t *testing.T) {
152 st := newShareTester(t)
153 defer st.done()
154
155 content := "monkey" // the secret
156 contentRef := blob.RefFromString(content)
157
158 link := fmt.Sprintf(`{"camliVersion": 1,
159"camliType": "file",
160"parts": [
161 {"blobRef": "%v", "size": %d}
162]}`, contentRef, len(content))
163 linkRef := blob.RefFromString(link)
164
165 share := schema.NewShareRef(schema.ShareHaveRef, false).
166 SetShareTarget(linkRef).
167 SetSigner(blob.RefFromString("irrelevant")).
168 SetRawStringField("camliSig", "alsounused")
169 shareRef := func() blob.Ref { return share.Blob().BlobRef() }
170
171 t.Logf("Checking share blob doesn't yet exist...")
172 st.testGet(shareRef().String(), shareFetchFailed)
173 if !st.slept() {
174 t.Error("expected sleep after miss")
175 }
176 st.put(share.Blob())
177 t.Logf("Checking share blob now exists...")
178 st.testGet(shareRef().String(), noError)
179
180 t.Logf("Checking we can't get the content directly via the share...")
181 st.testGet(fmt.Sprintf("%s?via=%s", contentRef, shareRef()), shareTargetInvalid)
182
183 t.Logf("Checking we can't get the link (file) blob directly...")
184 st.putRaw(linkRef, link)
185 st.testGet(linkRef.String(), shareBlobInvalid)
186
187 t.Logf("Checking we can get the link (file) blob via the share...")
188 st.testGet(fmt.Sprintf("%s?via=%s", linkRef, shareRef()), noError)
189
190 t.Logf("Checking we can't get the content via the non-transitive share...")
191 st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), shareNotTransitive)
192
193 // TODO: new test?
194 share.SetShareIsTransitive(true)
195 st.put(share.Blob())
196 st.testGet(fmt.Sprintf("%s?via=%s,%s", linkRef, shareRef(), linkRef), viaChainInvalidLink)
197
198 st.putRaw(contentRef, content)
199 st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), noError)
200
201 // new test?
202 share.SetShareExpiration(time.Now().Add(-time.Duration(10) * time.Minute))
203 st.put(share.Blob())
204 st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), shareExpired)
205
206 share.SetShareExpiration(time.Now().Add(time.Duration(10) * time.Minute))
207 st.put(share.Blob())
208 st.testGet(fmt.Sprintf("%s?via=%s,%s", contentRef, shareRef(), linkRef), noError)

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