Skip to content
quarry Artifact [6028e69c6f]
Login

Artifact [6028e69c6f]

Artifact 6028e69c6fb87140b35bde746a1a787355b1892a535336c2f688fd5c1ea7b31d:


package oltp

import "testing"

// A repository private by its column but with no category rows of its
// own (made private before AddRepo wrote them, like orchard) grants a
// signed-in account without a role nothing, and reads as Private, not
// as the fleet's public preset.
func TestAPrivateRepoWithoutRowsDoesNotFallBackToTheFleet(t *testing.T) {
	db := testDB(t)
	if err := db.AddRepo("orchard", t.TempDir(), "", Public); err != nil {
		t.Fatal(err)
	}
	// The pre-fix state: the column says private, no category rows.
	if _, err := db.w.Exec(`UPDATE repo SET visibility = ? WHERE name = ?`, Private, "orchard"); err != nil {
		t.Fatal(err)
	}
	if _, err := db.w.Exec(`DELETE FROM repo_category_caps WHERE repo = ?`, "orchard"); err != nil {
		t.Fatal(err)
	}
	if err := db.AddAccount("stranger", "a long enough password", false); err != nil {
		t.Fatal(err)
	}
	if got := db.EffectiveCaps("stranger", "orchard"); got.HasAny("gjoh2r") {
		t.Errorf("FAIL: a signed-in account with no role reads a private repo: %q", got)
	}
	if got := db.VisibilityName("orchard"); got != "Private" {
		t.Errorf("FAIL: visibility reads %q, want Private", got)
	}
	// A public repository with no rows still gets the fleet default.
	if err := db.AddRepo("open", t.TempDir(), "", Public); err != nil {
		t.Fatal(err)
	}
	if got := db.EffectiveCaps("stranger", "open"); !got.HasAny("o") {
		t.Errorf("FAIL: a public repo lost the fleet default: %q", got)
	}
	t.Log("ok")
}