Skip to content
quarry Artifact [2f64a14e0d]
Login

Artifact [2f64a14e0d]

Artifact 2f64a14e0de00e2c433e50d1a8ccc95583d20592ca948c0b42c9ed6e35840f36:


package xfer

import (
	"bytes"
	"io"
	"net/http"
	"testing"
)

// The horizon draft's request pragmas reach the child as they were sent
// (RFC 0024 rung 1). The front decodes a request to read its login and
// push cards, and passes everything else on untouched: the child is the
// one that serves a horizon, and a child too old to know these pragmas
// ignores them by the sync protocol's rule.
func TestHorizonPragmasReachTheChildUntouched(t *testing.T) {
	f := gated()
	defer f.Close()
	srv, _ := fakeChild(t, f, "alpha")
	var got []byte
	srv.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		got, _ = io.ReadAll(r.Body)
		w.Header().Set("Content-Type", "application/x-fossil")
		w.Write([]byte("pragma horizon-served structural\n"))
	})
	sent := encodeContainer([]byte("pull SRV PRJ\n" +
		"pragma client-version 22900 20260101 120000\n" +
		"pragma horizon-structural 4f2a9c1e8b7d6a5f4e3d2c1b0a99887766554433\n" +
		"pragma horizon-rule descendants\n" +
		"pragma horizon-cursor 17\n"))
	w, _, _ := postRaw(t, f, sent)
	if w.Code != http.StatusOK {
		t.Fatalf("the pull answered %d", w.Code)
	}
	if !bytes.Equal(got, sent) {
		t.Errorf("FAIL: the child received %d bytes, not the %d sent unchanged", len(got), len(sent))
	}
	if !bytes.Contains(w.Body.Bytes(), []byte("pragma horizon-served structural")) {
		t.Errorf("FAIL: the child's horizon-served did not reach the client: %q", w.Body.String())
	}
}