v0.324.0: the database password comes back with the data (R-1106, R-127b, R-926); restic 0.19.1 (R-1107); R-1108, R-1065, R-1017; dashboard hardening (R-983, R-976)
gates / gates (push) Successful in 44s

This commit is contained in:
2026-10-16 22:46:00 +02:00
parent 00a0d91976
commit f75b3aa778
212 changed files with 2414 additions and 398 deletions
+89
View File
@@ -296,3 +296,92 @@ func TestSambaPasswordRefusedWhenDisabled(t *testing.T) {
t.Errorf("no compose call may happen while disabled, got %d", *upCalls)
}
}
// R-1108: a share added while sharing is on but the household password is NOT yet set must be
// exported once the password is set, even though the samba container is ALREADY running. Before the
// fix SetSMBPassword rewrote smb.conf + compose but called compose up only when the container was
// down, and the next reconcile saw "unchanged + running" and did nothing — the share never appeared.
// The consequence asserted: the new config is on disk AND a compose up ran after it was written.
func TestSambaPassword_ShareAddedBeforePasswordIsApplied(t *testing.T) {
m, sett, root, upCalls := newSambaManager(t)
if err := sett.SetSMBEnabled(true); err != nil {
t.Fatal(err)
}
// First password attempt: the container is brought up, then smbpasswd fails — the box is left
// with sharing on, UserSet=false and a RUNNING container holding a share-less config.
m.sambaPasswdFn = func(string) error { return os.ErrDeadlineExceeded }
if err := m.SetSMBPassword("elso"); err == nil {
t.Fatal("setup: the first password apply was meant to fail")
}
if *upCalls != 1 {
t.Fatalf("setup: expected the container brought up once, got %d", *upCalls)
}
if sett.GetSMBSettings().UserSet {
t.Fatal("setup: UserSet must stay false after a failed smbpasswd")
}
m.sambaRunFn = func() bool { return true }
// A share is added now; its reconcile is skipped because no password is set yet.
shareDir := seedShare(t, sett, root, "dokumentumok")
if err := sett.AddSMBShare(settings.SMBShare{Name: "dokumentumok", Path: shareDir}); err != nil {
t.Fatal(err)
}
if err := m.ReconcileSamba(); err != nil {
t.Fatal(err)
}
if *upCalls != 1 {
t.Fatalf("setup: reconcile without a password must not deploy, got %d up calls", *upCalls)
}
// The password is set: the share must be written AND applied to the running container.
var upAfterWrite bool
m.sambaUpFn = func(dir string) error {
*upCalls++
conf, err := os.ReadFile(filepath.Join(dir, "smb.conf"))
upAfterWrite = err == nil && strings.Contains(string(conf), "[dokumentumok]")
return nil
}
m.sambaPasswdFn = func(string) error { return nil }
if err := m.SetSMBPassword("masodik"); err != nil {
t.Fatalf("SetSMBPassword: %v", err)
}
conf, err := os.ReadFile(filepath.Join(m.sambaDir(), "smb.conf"))
if err != nil || !strings.Contains(string(conf), "[dokumentumok]") {
t.Fatalf("share missing from smb.conf after the password set: err=%v\n%s", err, conf)
}
if *upCalls != 2 || !upAfterWrite {
t.Errorf("the running container must be re-applied with the new share: up calls=%d (want 2), up saw the share=%v", *upCalls, upAfterWrite)
}
// And the follow-up reconcile is a clean no-op (nothing pending was left behind).
before := *upCalls
if err := m.ReconcileSamba(); err != nil {
t.Fatal(err)
}
if *upCalls != before {
t.Errorf("reconcile after the password set must be a no-op: up calls %d → %d", before, *upCalls)
}
}
// R-1108 companion: setting (or changing) the password on a running container whose config did NOT
// change performs no compose call — the fix must not turn every password change into a recreate.
func TestSambaPassword_RunningUnchangedNoComposeCall(t *testing.T) {
m, sett, root, upCalls := newSambaManager(t)
shareDir := seedShare(t, sett, root, "dokumentumok")
enableSMB(t, sett)
if err := sett.AddSMBShare(settings.SMBShare{Name: "dokumentumok", Path: shareDir}); err != nil {
t.Fatal(err)
}
if err := m.ReconcileSamba(); err != nil {
t.Fatal(err)
}
m.sambaRunFn = func() bool { return true }
m.sambaPasswdFn = func(string) error { return nil }
before := *upCalls
if err := m.SetSMBPassword("uj"); err != nil {
t.Fatalf("SetSMBPassword: %v", err)
}
if *upCalls != before {
t.Errorf("an unchanged config on a running container needs no compose call: %d → %d", before, *upCalls)
}
}