Skip to content
quarry Artifact [0901385195]
Login

Artifact [0901385195]

Artifact 09013851957641ef69747f91b83a359b56a166570d53a8a163fcc5d912877296:


package web

import (
	"os"
	"path/filepath"
	"strings"
	"testing"
)

// A LOOKING aid for the two surfaces a password reset adds: the row's
// new control on the People tab beside the one that shuts an account,
// and the banner handing the operator a link. Off unless
// QUARRY_SHOT_RESET is set.
func TestWriteResetShot(t *testing.T) {
	out := os.Getenv("QUARRY_SHOT_RESET")
	if out == "" {
		t.Skip("QUARRY_SHOT_RESET unset")
	}
	if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
		[]byte(sheet), 0o644); err != nil {
		t.Fatal(err)
	}
	data := pageData{Title: "People", SheetURL: "quarry.css", User: "root",
		InviteLink:  "https://zeitforge.app/invite/" + strings.Repeat("cd", 32),
		InviteReset: true,
		Accounts: []betaAccount{
			{Name: "jva", Live: 1, LastLogin: "2026-09-16T00:37:32Z", Created: "2026-08-01T00:00:00Z"},
			{Name: "lou", Email: "[email protected]", LastLogin: "2026-09-15T08:00:00Z", Created: "2026-07-01T00:00:00Z"},
			{Name: "newbie", Email: "[email protected]", Pending: true, Created: "2026-09-14T00:00:00Z"},
			{Name: "eve", Disabled: "2026-09-10T00:00:00Z", Created: "2026-06-01T00:00:00Z"},
		},
	}
	var buf strings.Builder
	if err := fleetPeoplePage.Execute(&buf, data); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(out, []byte(buf.String()), 0o644); err != nil {
		t.Fatal(err)
	}
	t.Logf("ok: wrote %s", out)
}

// And the page the link opens, in its reset words.
func TestWriteResetLinkShot(t *testing.T) {
	out := os.Getenv("QUARRY_SHOT_RESETLINK")
	if out == "" {
		t.Skip("QUARRY_SHOT_RESETLINK unset")
	}
	if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
		[]byte(sheet), 0o644); err != nil {
		t.Fatal(err)
	}
	var buf strings.Builder
	if err := invitePage.Execute(&buf, pageData{Title: "New password", SheetURL: "quarry.css",
		InviteToken: strings.Repeat("cd", 32), InviteName: "jva", InviteReset: true}); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(out, []byte(buf.String()), 0o644); err != nil {
		t.Fatal(err)
	}
}