element(s) — the form IS the CSS grid; "+
"a nested div breaks the column layout", n)
}
if o, c := strings.Count(form, "
"); o != c {
t.Errorf("unbalanced div tags inside the artifacts form: %d open, %d close", o, c)
}
// 4. Whole-page div balance — an unclosed div here corrupts every section BELOW it (the login
// password card and the assets card both render after this form).
if o, c := strings.Count(body, "
"); o != c {
t.Errorf("configuration.html has unbalanced divs: %d open, %d close — sections after the "+
"artifact form will render inside the wrong container", o, c)
}
// 5. The sections that follow must still be present and not swallowed.
for _, want := range []string{"Login password", "Change password", "Assets", "Refresh Assets from Image"} {
if !strings.Contains(body, want) {
t.Errorf("section %q missing — likely swallowed by an unclosed element above it", want)
}
}
}
var artifactsFormRe = regexp.MustCompile(`(?s)`)
func artifactsForm(t *testing.T, body string) string {
t.Helper()
m := artifactsFormRe.FindStringSubmatch(body)
if m == nil {
t.Fatal("could not locate the artifacts form")
}
return m[1]
}
// An empty stored value must render an empty field (blank = not vouched), not the string ""
// or a zero — the operator reads this field to decide whether anything is vouched at all.
func TestConfigurationArtifactsForm_EmptyWrapperSHA(t *testing.T) {
s, _ := newTestServer(t)
var buf bytes.Buffer
err := s.templates.ExecuteTemplate(&buf, "configuration.html", map[string]interface{}{
"CSRFToken": "tok", "CSRFField": s.csrfField(httptest.NewRequest("GET", "/", nil)),
"AssetCount": 0, "AssetLastSync": "", "GlobalFloor": "",
"Artifacts": store.ArtifactManifest{},
})
if err != nil {
t.Fatalf("render: %v", err)
}
form := artifactsForm(t, buf.String())
if !strings.Contains(form, `name="wrapper_sha256" value=""`) {
t.Errorf("an unvouched wrapper must render an empty value; got:\n%s", form)
}
}