package main
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"strings"
"testing"
"time"
"craftdesign.group/quarry/internal/lease"
"craftdesign.group/quarry/internal/oltp"
"craftdesign.group/quarry/internal/ops"
"craftdesign.group/quarry/internal/zitcli"
)
// RFC 0023 across the doors: a disable answers 451 on the API and the
// pages to everybody but the repository's own admins, a hold to
// everybody, and restoring answers as before.
func TestATakedownAnswers451OnEverySurface(t *testing.T) {
g := newSiteRig(t)
api := "/api/v1/r/pub/counts"
page := "/r/pub/timeline"
status := func(user, path string) int {
pass := doorPassword
if user == "" {
pass = ""
}
code, _ := g.doAs(user, http.MethodGet, path, pass, "", nil)
return code
}
if c := status("", api); c != http.StatusOK {
t.Fatalf("before: anonymous API %d", c)
}
if code, body := g.doAs("dmestas", http.MethodPost, "/api/v1/repos/disable", doorPassword, "",
map[string]string{"repo": "pub", "category": "copyright", "notice": "N-1"}); code != http.StatusOK {
t.Fatalf("FAIL: disable: %d %s", code, body)
}
for _, c := range []struct {
user, path string
want int
}{
{"", api, http.StatusUnavailableForLegalReasons},
{"", page, http.StatusUnavailableForLegalReasons},
{"carol", api, http.StatusOK}, // a site admin, as a person, reaches it to judge the notice
{"alice", api, http.StatusOK}, // the repository's own admin
{"alice", page, http.StatusOK},
} {
if got := status(c.user, c.path); got != c.want {
t.Errorf("FAIL: disabled: %q %s answered %d, want %d", c.user, c.path, got, c.want)
}
}
if _, body := g.doAs("", http.MethodGet, page, "", "", nil); !strings.Contains(body, `data-hook="held"`) {
t.Error("FAIL: the 451 page is not the held page")
}
// A private repository answers a stranger as one that is not there,
// taken down or not.
if err := g.db.SetTakedown(oltp.Takedown{Repo: "secret", Strength: oltp.Disabled, Category: "copyright", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
if c := status("", "/api/v1/r/secret/counts"); c == http.StatusUnavailableForLegalReasons {
t.Error("FAIL: a private repository told a stranger it was taken down")
}
if code, body := g.doAs("dmestas", http.MethodPost, "/api/v1/repos/hold", doorPassword, "",
map[string]string{"repo": "pub", "category": "child-abuse"}); code != http.StatusOK {
t.Fatalf("FAIL: hold: %d %s", code, body)
}
if got := status("alice", api); got != http.StatusUnavailableForLegalReasons {
t.Errorf("FAIL: on hold, the owner's API answered %d", got)
}
if got := status("carol", api); got != http.StatusOK {
t.Errorf("FAIL: on hold, a site admin as a person answered %d", got)
}
siteV, _ := g.mint(t, oltp.ScopeAPI, oltp.ScopeWeb, oltp.ScopeSite)
if code, _ := g.do(http.MethodGet, api, siteV, "", nil); code != http.StatusUnavailableForLegalReasons {
t.Errorf("FAIL: on hold, a site token answered %d", code)
}
if _, body := g.doAs("alice", http.MethodGet, api, doorPassword, "", nil); strings.Contains(body, "child-abuse") {
t.Errorf("FAIL: a hold said why: %s", body)
}
if code, _ := g.doAs("dmestas", http.MethodPost, "/api/v1/repos/restore", doorPassword, "",
map[string]string{"repo": "pub"}); code == http.StatusOK {
t.Error("FAIL: restore lifted a hold")
}
if code, body := g.doAs("dmestas", http.MethodPost, "/api/v1/repos/lift", doorPassword, "",
map[string]string{"repo": "pub", "reason": "report filed"}); code != http.StatusOK {
t.Fatalf("FAIL: lift: %d %s", code, body)
}
if c := status("", api); c != http.StatusOK {
t.Errorf("FAIL: after the lift: anonymous API %d", c)
}
acts, _ := g.db.TakedownLog("pub", 10)
if len(acts) != 3 {
t.Errorf("FAIL: %d logged acts, want disable, hold, lift", len(acts))
}
}
// A site token may disable and restore, which a host complaint needs in
// minutes; it may neither place nor lift a hold, and it reaches no
// private repository it holds no grant on.
func TestASiteTokenTakesDownWithinItsLine(t *testing.T) {
g := newSiteRig(t)
_, tok := g.mint(t, oltp.ScopeAPI, oltp.ScopeWeb, oltp.ScopeSite)
v, _, err := g.db.MintToken("zeitgeist", oltp.TokenSpec{Name: "site2", Scopes: []string{oltp.ScopeAPI, oltp.ScopeWeb, oltp.ScopeSite}})
if err != nil {
t.Fatal(err)
}
_ = tok
post := func(path string, body map[string]string) int {
code, _ := g.do(http.MethodPost, path, v, "", body)
return code
}
if c := post("/api/v1/repos/disable", map[string]string{"repo": "pub", "category": "host"}); c != http.StatusOK {
t.Fatalf("FAIL: the site token's disable: %d", c)
}
if c := post("/api/v1/repos/hold", map[string]string{"repo": "pub", "category": "child-abuse"}); c == http.StatusOK {
t.Error("FAIL: the site token placed a hold")
}
if c := post("/api/v1/repos/restore", map[string]string{"repo": "pub"}); c != http.StatusOK {
t.Errorf("FAIL: the site token's restore: %d", c)
}
if c := post("/api/v1/repos/disable", map[string]string{"repo": "secret", "category": "host"}); c != http.StatusNotFound {
t.Errorf("FAIL: the site token's disable of secret answered %d, want 404", c)
}
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.LegalHold, Category: "preservation", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
if c := post("/api/v1/repos/lift", map[string]string{"repo": "pub"}); c == http.StatusOK {
t.Error("FAIL: the site token lifted a hold")
}
}
// The fleet row offers the takedown acts and, while one is in force,
// neither stopping nor deleting; the form carries a disable across.
func TestTheFleetRowTakesDown(t *testing.T) {
g := newSiteRig(t)
_, body := g.doAs("dmestas", http.MethodGet, "/fleet", doorPassword, "", nil)
if !strings.Contains(body, `href="/fleet?takedown=pub&strength=disabled"`) || !strings.Contains(body, `data-hook="fleet-hold-link"`) {
t.Fatal("FAIL: no takedown links on the fleet rows")
}
if _, body := g.doAs("dmestas", http.MethodGet, "/fleet?takedown=pub&strength=disabled", doorPassword, "", nil); !strings.Contains(body, `data-hook="fleet-takedown"`) {
t.Fatal("FAIL: no takedown form")
}
if code, body := g.fleetForm("dmestas", "/fleet/repo/takedown", url.Values{"repo": {"pub"}, "strength": {"disabled"},
"category": {"copyright"}, "notice": {"N-9"}}); code != http.StatusSeeOther {
t.Fatalf("FAIL: the form's disable: %d %s", code, body)
}
if td, ok, _ := g.db.TakedownOf("pub"); !ok || td.Notice != "N-9" || td.Actor != "dmestas" {
t.Fatalf("FAIL: takedown %+v %v", td, ok)
}
_, body = g.doAs("dmestas", http.MethodGet, "/fleet", doorPassword, "", nil)
row := body[strings.Index(body, `data-strength="disabled"`):]
row = row[:strings.Index(row, "</li>")]
if !strings.Contains(row, `data-hook="fleet-restore"`) {
t.Error("FAIL: a disabled row offers no restore")
}
if strings.Contains(row, `data-hook="fleet-stop"`) || strings.Contains(row, `data-hook="fleet-delete-link"`) {
t.Error("FAIL: a disabled row still offers stopping or deleting")
}
}
// Stopping and deleting both refuse a repository under a takedown, from
// the registrar itself, before anything stops serving.
func TestTheRegistrarKeepsATakenDownRepository(t *testing.T) {
rg := newTestRegistrar(t, 25)
if err := rg.odb.AddRepo("held", t.TempDir(), "", oltp.Public); err != nil {
t.Fatal(err)
}
if err := rg.odb.SetTakedown(oltp.Takedown{Repo: "held", Strength: oltp.Disabled, Category: "copyright", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
if err := rg.Remove("held"); err == nil || !strings.Contains(err.Error(), "disabled") {
t.Errorf("FAIL: stop serving: %v", err)
}
if err := rg.Delete("held", "held"); err == nil || !strings.Contains(err.Error(), "disabled") {
t.Errorf("FAIL: delete: %v", err)
}
if _, ok, _ := rg.odb.RepoByName("held"); !ok {
t.Error("FAIL: the registration went")
}
}
// The sync front's answer: an anonymous pull of a disabled repository
// is refused with the sentence, its admin is served, and a hold refuses
// the admin too.
func TestTheSyncHoldGate(t *testing.T) {
g := newSiteRig(t)
req := httptest.NewRequest(http.MethodPost, "/r/pub", nil)
if why := g.rg.SyncHoldGate(req, "pub", ""); why != "" {
t.Fatalf("FAIL: refused before any takedown: %s", why)
}
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.Disabled, Category: "copyright", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
if why := g.rg.SyncHoldGate(req, "pub", ""); !strings.Contains(why, "legal reasons") {
t.Errorf("FAIL: an anonymous pull of a disabled repository: %q", why)
}
if why := g.rg.SyncHoldGate(req, "pub", "alice"); why != "" {
t.Errorf("FAIL: the admin's pull was refused: %q", why)
}
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.LegalHold, Category: "preservation", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
if why := g.rg.SyncHoldGate(req, "pub", "alice"); why == "" {
t.Error("FAIL: a hold served the admin")
}
}
// A takedown pauses the mirror pull, so a hold keeps the store as it is.
func TestATakedownPausesTheMirrorPull(t *testing.T) {
g := newSiteRig(t)
if err := g.db.SetMirror("pub", "https://example.invalid/pub", time.Hour); err != nil {
t.Fatal(err)
}
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.LegalHold, Category: "preservation", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
g.fleetForm("dmestas", "/fleet/mirror/run", url.Values{"repo": {"pub"}})
for _, r := range *g.pulled {
if r == "pub" {
t.Error("FAIL: a repository on legal hold was pulled from its upstream")
}
}
}
// Behind the real wiring: a disabled repository leaves the fleet-wide
// reads of whoever the takedown shuts out, and a single-repository
// route's feed, archive and API say 451 to them. Its admin still reads.
func TestADisabledRepositoryLeavesTheFleetWideReads(t *testing.T) {
g := newSiteRig(t)
body := func(user, path string) (int, string) {
pass := doorPassword
if user == "" {
pass = ""
}
return g.doAs(user, http.MethodGet, path, pass, "", nil)
}
listed := func(user, path string) bool {
code, b := body(user, path)
return code == http.StatusOK && strings.Contains(b, `pub`)
}
reads := []string{"/api/v1/repos", "/"}
for _, p := range reads {
if !listed("", p) {
t.Fatalf("FAIL: before the takedown %s does not name the repository, so the test proves nothing", p)
}
}
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.Disabled, Category: "copyright", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
for _, p := range reads[:1] {
if listed("", p) {
t.Errorf("FAIL: anonymous %s still names a disabled repository", p)
}
}
if code, b := body("", "/"); code == http.StatusOK && strings.Contains(b, "/r/pub") {
t.Error("FAIL: the front page still links a disabled repository to an anonymous visitor")
}
if code, _ := body("", "/api/v1/search?q=a&repo=pub"); code == http.StatusOK {
t.Errorf("FAIL: searching inside a disabled repository answered %d to a stranger", code)
}
if !listed("alice", "/api/v1/repos") || !listed("carol", "/api/v1/repos") {
t.Error("FAIL: its own admin or a site admin lost the repository from the list")
}
for _, p := range []string{"/r/pub/timeline.atom", "/r/pub/archive/trunk", "/api/v1/r/pub/counts"} {
if code, _ := body("", p); code != http.StatusUnavailableForLegalReasons {
t.Errorf("FAIL: anonymous %s answered %d, want 451", p, code)
}
}
if !t.Failed() {
t.Log("ok")
}
}
// A parent's takedown covers its companion store on every gate, bound
// before or after, and the binding cannot be dropped to shed it.
func TestAParentsTakedownCoversItsCompanionStore(t *testing.T) {
g := newSiteRig(t)
if err := g.db.AddRepo("pubforum", t.TempDir(), "", oltp.Public); err != nil {
t.Fatal(err)
}
if err := g.db.BindCompanion("pub", "forum", "pubforum"); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
anon := context.Background()
if why := g.rg.HeldRefusal(anon, "pubforum"); why != "" {
t.Fatalf("FAIL: refused before any takedown: %s", why)
}
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.Disabled, Category: "copyright", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
if why := g.rg.HeldRefusal(anon, "pubforum"); !strings.Contains(why, "legal reasons") {
t.Errorf("FAIL: the companion store of a disabled repository served an anonymous caller: %q", why)
}
if why := g.rg.HeldRefusal(ops.WithUser(anon, "alice"), "pubforum"); why != "" {
t.Errorf("FAIL: the parent's admin was refused its own forum store: %q", why)
}
req := httptest.NewRequest(http.MethodPost, "/r/pubforum", nil)
if why := g.rg.SyncHoldGate(req, "pubforum", ""); why == "" {
t.Error("FAIL: the sync front served the companion store of a disabled repository")
}
if err := g.db.UnbindCompanion("pub", "forum"); !errors.Is(err, oltp.ErrHeld) {
t.Errorf("FAIL: unbinding under a takedown was allowed: %v", err)
}
if err := g.db.EndTakedown("pub", oltp.Disabled, "dmestas", "", "restored"); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
if why := g.rg.HeldRefusal(anon, "pubforum"); why != "" {
t.Errorf("FAIL: the store stayed held after the lift: %q", why)
}
if err := g.db.UnbindCompanion("pub", "forum"); err != nil {
t.Errorf("FAIL: unbinding after the lift: %v", err)
}
if !t.Failed() {
t.Log("ok")
}
}
// Until a load has succeeded the gates ask the tables themselves, and when
// that fails they refuse: serving is what cannot be taken back. A site
// admin as a person is let through, since they are the one who can act.
func TestTheHoldGateFailsClosedBeforeTheFirstLoad(t *testing.T) {
g := newSiteRig(t)
g.rg.heldStored = 0
g.rg.heldLookup = func(string) (oltp.Takedown, string, bool, error) {
return oltp.Takedown{}, "", false, errors.New("database is closed")
}
anon := context.Background()
if why := g.rg.HeldRefusal(anon, "pub"); !strings.Contains(why, "legal reasons") {
t.Errorf("FAIL: a stranger was served while the tables could not be read: %q", why)
}
if why := g.rg.HeldRefusal(ops.WithUser(anon, "alice"), "pub"); why == "" {
t.Error("FAIL: a repository's admin was served while the tables could not be read")
}
if why := g.rg.HeldRefusal(ops.WithUser(anon, "carol"), "pub"); why != "" {
t.Errorf("FAIL: a site admin person was refused: %q", why)
}
// After a good load, a later reload that fails keeps the last good map.
g.rg.heldLookup = nil
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.Disabled, Category: "copyright", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
g.rg.privLoad = func() (map[string]bool, error) { return nil, errors.New("reload failed") }
g.rg.refreshPrivate()
if why := g.rg.HeldRefusal(anon, "pub"); !strings.Contains(why, "legal reasons") {
t.Errorf("FAIL: a failed reload dropped the takedown it held: %q", why)
}
if !t.Failed() {
t.Log("ok")
}
}
// RFC 0023: a legal hold is visible to a site admin PERSON, and "a site
// token may neither set nor lift it". So the fleet and ops listings omit
// a held repository, and what they count, for a token (an agent's
// included); a person signed in as a site admin sees it. A disabled
// repository stays in the token's listings, which is where it restores
// one. Operations on the forge as a whole stay with the token.
func TestHeldRepositoryIsAbsentFromASiteTokensFleetListings(t *testing.T) {
g := newSiteRig(t)
tok, _ := g.mint(t, oltp.ScopeAPI, oltp.ScopeWeb, oltp.ScopeSite)
names := func(user, pass, path, key string) (map[string]bool, string) {
code, body := g.doAs(user, http.MethodGet, path, pass, "", nil)
if code != http.StatusOK {
t.Fatalf("FAIL: %s as %s: %d %s", path, user, code, body)
}
var out map[string]json.RawMessage
if err := json.Unmarshal([]byte(body), &out); err != nil {
t.Fatal(err)
}
var rows []struct {
Name string `json:"name"`
}
_ = json.Unmarshal(out[key], &rows)
got := map[string]bool{}
for _, r := range rows {
got[r.Name] = true
}
var count int
_ = json.Unmarshal(out["count"], &count)
return got, strconv.Itoa(count) + "/" + strconv.Itoa(len(rows))
}
check := func(label string, wantTok, wantPerson bool) {
t.Helper()
for _, c := range []struct {
path, key string
}{{"/api/v1/fleet", "repos"}, {"/api/v1/ops", "stores"}} {
if got, _ := names("zeitgeist", tok, c.path, c.key); got["pub"] != wantTok {
t.Errorf("FAIL: %s: a site token's %s lists pub = %v, want %v", label, c.path, got["pub"], wantTok)
}
if got, _ := names("carol", doorPassword, c.path, c.key); got["pub"] != wantPerson {
t.Errorf("FAIL: %s: a site admin person's %s lists pub = %v, want %v", label, c.path, got["pub"], wantPerson)
}
}
}
check("up", true, true)
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.Disabled, Category: "host", Actor: "carol"}); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
check("disabled", true, true)
if err := g.db.SetTakedown(oltp.Takedown{Repo: "pub", Strength: oltp.LegalHold, Category: "preservation", Actor: "carol"}); err != nil {
t.Fatal(err)
}
g.rg.refreshPrivate()
check("held", false, true)
// The count the token reads is the listing it is shown.
_, tokCount := names("zeitgeist", tok, "/api/v1/fleet", "repos")
_, personCount := names("carol", doorPassword, "/api/v1/fleet", "repos")
if tokCount == personCount {
t.Errorf("FAIL: a token's fleet count %s equals a person's %s with a hold in force", tokCount, personCount)
}
if a, b, _ := strings.Cut(tokCount, "/"); a != b {
t.Errorf("FAIL: the token's count %s disagrees with its rows", tokCount)
}
// Naming the repository to a sync does not reach it either.
if code, _ := g.doAs("zeitgeist", http.MethodPost, "/api/v1/fleet/sync", tok, "", map[string]string{"repo": "pub"}); code != http.StatusNotFound {
t.Errorf("FAIL: a token's sync of a held repository answered %d, want 404", code)
}
// What is not about one repository still answers the token: the ops
// page's health and disk figures.
if code, body := g.doAs("zeitgeist", http.MethodGet, "/api/v1/ops", tok, "", nil); code != http.StatusOK || !strings.Contains(body, `"store"`) {
t.Errorf("FAIL: the forge-wide ops read stopped answering a token: %d", code)
}
if !t.Failed() {
t.Log("ok")
}
}
// RFC 0023: "Webhooks and CI | paused | paused". A repository under
// either strength starts no run: not on a fold (its check-ins, tags and
// landing merges), not on a re-run, not from a schedule, not from the
// deferred queue. Nothing is deleted, so the lifted repository resumes
// on the next fold.
func TestHeldRepositoryStartsNoCI(t *testing.T) {
for _, strength := range []string{oltp.Disabled, oltp.LegalHold} {
n := newJobNodes(t, lease.DefaultTTL, "node-a")
rg := n.registrar(t, 0)
cli := zitcli.New(n.dir)
if err := n.db.AddRepo("test", n.dir, "", oltp.Public); err != nil {
t.Fatal(err)
}
if err := n.db.SetTakedown(oltp.Takedown{Repo: "test", Strength: strength, Category: "preservation", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
rg.refreshPrivate()
if !rg.ciHeld("test") {
t.Fatalf("FAIL: %s: ciHeld does not see the takedown", strength)
}
rg.afterFold("test", cli, n.ix)
if _, ok := n.db.CIWatermark("test"); ok {
t.Errorf("FAIL: %s: a fold of a held repository reached the CI trigger", strength)
}
if err := rg.TriggerCI("test", "", "dmestas"); !errors.Is(err, ops.ErrForbidden) {
t.Errorf("FAIL: %s: a re-run answered %v, want a refusal", strength, err)
}
if err := rg.TriggerPairCI("test", "b", "x", "y"); !errors.Is(err, ops.ErrForbidden) {
t.Errorf("FAIL: %s: a merge re-run answered %v, want a refusal", strength, err)
}
if err := n.db.EndTakedown("test", strength, "dmestas", "person", ""); err != nil {
t.Fatal(err)
}
rg.refreshPrivate()
rg.afterFold("test", cli, n.ix)
if _, ok := n.db.CIWatermark("test"); !ok {
t.Errorf("FAIL: %s: the lifted repository did not resume CI", strength)
}
}
if !t.Failed() {
t.Log("ok")
}
}
// RFC 0023: under a legal hold "Writes | refused for everybody, so the
// evidence does not change"; a disabled repository's admins still write,
// so the forge's writes for them go on. Every forge-initiated writer is
// held back on a hold, silently, and runs again at the lift: the fold's
// sweeps, the auto-accept sweep, and (for either strength) the mirror pull.
func TestHeldRepositoryTakesNoForgeWrites(t *testing.T) {
n := newJobNodes(t, lease.DefaultTTL, "node-a")
rg := n.registrar(t, 0)
cli := zitcli.New(n.dir)
if err := n.db.AddRepo("test", n.dir, "", oltp.Public); err != nil {
t.Fatal(err)
}
if err := n.db.SetMirror("test", "https://example.invalid/test", time.Hour); err != nil {
t.Fatal(err)
}
pulls := 0
pull := func() int {
pulls = 0
mirrorRound(n.mirrorDeps(&pulls), n.db, n.gates[0], time.Now())
return pulls
}
armedRows := armed{{Repo: "test", Landing: "L1", Account: "dan"}}
legal := func(repo string) bool { return rg.legallyHeld(repo) }
armedCount := func() int {
got, _ := (heldSweeper{AutoSweeper: armedRows, jobs: n.gates[0], legal: legal}).AutoAccepts()
return len(got)
}
if err := n.db.SetTakedown(oltp.Takedown{Repo: "test", Strength: oltp.Disabled, Category: "copyright", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
rg.refreshPrivate()
if rg.legallyHeld("test") {
t.Error("FAIL: a disabled repository reads as on legal hold")
}
if pull() != 0 {
t.Error("FAIL: a disabled repository was pulled from its upstream")
}
if armedCount() != 1 {
t.Error("FAIL: a disabled repository's armed landing was held back, though its admins may write")
}
if err := n.db.EndTakedown("test", oltp.Disabled, "dmestas", "person", ""); err != nil {
t.Fatal(err)
}
if err := n.db.SetTakedown(oltp.Takedown{Repo: "test", Strength: oltp.LegalHold, Category: "preservation", Actor: "dmestas"}); err != nil {
t.Fatal(err)
}
rg.refreshPrivate()
if !rg.legallyHeld("test") {
t.Fatal("FAIL: a legal hold is not seen")
}
rg.afterFold("test", cli, n.ix)
if _, seen := n.db.CloseWatch("test"); seen {
t.Error("FAIL: a fold of a held repository ran the write sweeps")
}
if pull() != 0 {
t.Error("FAIL: a held repository was pulled from its upstream")
}
if armedCount() != 0 {
t.Error("FAIL: a held repository's armed landing was tried")
}
if len(armedRows) != 1 {
t.Error("FAIL: the arm was not left in place")
}
if err := n.db.EndTakedown("test", oltp.LegalHold, "dmestas", "person", ""); err != nil {
t.Fatal(err)
}
rg.refreshPrivate()
rg.afterFold("test", cli, n.ix)
if _, seen := n.db.CloseWatch("test"); !seen {
t.Error("FAIL: the lifted repository's sweeps did not resume")
}
if pull() != 1 {
t.Error("FAIL: the lifted repository's mirror did not resume")
}
if armedCount() != 1 {
t.Error("FAIL: the lifted repository's armed landing is not tried again")
}
if !t.Failed() {
t.Log("ok")
}
}