MCPcopy
hub / github.com/dgraph-io/dgraph / attemptDoneOnlyStream

Function attemptDoneOnlyStream

dgraph/cmd/dgraphimport/import_security_test.go:190–229  ·  view source on GitHub ↗

attemptDoneOnlyStream opens StreamExtSnapshot, names the target group, then immediately sends Done with no data packets — the advisory PoC. Stream errors are tolerated and logged: after the fix the server rejects the stream, which is the desired outcome. The assertion that matters is made by the cal

(t *testing.T, ctx context.Context, dc api.DgraphClient, groupId uint32)

Source from the content-addressed store, hash-verified

188// the fix the server rejects the stream, which is the desired outcome. The assertion that
189// matters is made by the caller, on whether the store survived.
190func attemptDoneOnlyStream(t *testing.T, ctx context.Context, dc api.DgraphClient, groupId uint32) {
191 ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
192 defer cancel()
193
194 out, err := dc.StreamExtSnapshot(ctx)
195 if err != nil {
196 t.Logf("StreamExtSnapshot rejected at open (expected after fix): %v", err)
197 return
198 }
199
200 // First message names the target group, exactly as the legitimate client does.
201 if err := out.Send(&api.StreamExtSnapshotRequest{GroupId: groupId}); err != nil {
202 t.Logf("send group id failed (expected after fix): %v", err)
203 return
204 }
205 if _, err := out.Recv(); err != nil {
206 t.Logf("recv group ack failed (expected after fix): %v", err)
207 return
208 }
209
210 // Done-only: no data packets. This alone triggered Prepare()/dropAll() before the fix.
211 if err := out.Send(&api.StreamExtSnapshotRequest{Pkt: &api.StreamPacket{Done: true}}); err != nil {
212 t.Logf("send done failed (expected after fix): %v", err)
213 return
214 }
215 _ = out.CloseSend()
216
217 // Drain until the server signals completion or closes the stream.
218 for {
219 resp, err := out.Recv()
220 if err != nil {
221 t.Logf("stream closed: %v", err)
222 return
223 }
224 if resp.Finish {
225 t.Logf("server reported Finish=true")
226 return
227 }
228 }
229}

Calls 3

StreamExtSnapshotMethod · 0.65
SendMethod · 0.65
RecvMethod · 0.65

Tested by

no test coverage detected