Files
llmgw/internal/web/slurmkeys_test.go
T
Ilker ManapandClaude Opus 5.5 d8ce573bdb
CI / test (push) Failing after 7m1s
Slurm's shared files and users: one path everywhere, accounts as Linux users
slurm.shared mounts the site's NFS export, has an llmgw node export the path
over NFS to the Slurm machines alone (2049 in the firewall), or looks for a
file system the site mounts. slurm.users "llmgw" makes each active account a
Linux user on every Slurm machine: login from its e-mail, a UID from 200000
kept in slurm_users and never reused, its home on the shared path, its SSH
keys from the portal's Profile (or ctl slurm users keys) read by sshd from
/etc/llmgw/ssh-keys. server init --slurm chooses /shared from the first
machine and llmgw's users; --slurm-shared and --slurm-users change that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:34:34 +01:00

75 lines
2.6 KiB
Go

package web
import (
"log/slog"
"net/http"
"net/http/httptest"
"net/url"
"path/filepath"
"strings"
"testing"
"time"
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
)
func TestTheProfileKeepsAPersonsSSHKeysForSlurm(t *testing.T) {
ctx := t.Context()
st, err := store.OpenSQLite(ctx, filepath.Join(t.TempDir(), "s.db"))
if err != nil {
t.Fatal(err)
}
defer st.Close()
ayse := store.User{ID: "usr-a", Email: "ayse@llmt.test", Name: "Ayşe", State: store.UserActive, CreatedAt: time.Now()}
if err := st.CreateUser(ctx, ayse); err != nil {
t.Fatal(err)
}
set := config.SlurmSettings{Enabled: true, Controller: "llmt-1", Users: config.UsersLlmgw,
Shared: config.SharedStorage{Path: "/shared", Server: "llmt-1"}}
p := NewAccountPages(fakeAccounts{user: ayse}, st, nil, "v0", slog.New(slog.DiscardHandler))
p.SetSlurm(st, func() config.SlurmSettings { return set })
mux := http.NewServeMux()
p.Register(mux)
do := func(form url.Values) (int, string) {
req := httptest.NewRequest(http.MethodGet, "/profile", nil)
if form != nil {
form.Set("csrf", "tok")
req = httptest.NewRequest(http.MethodPost, "/profile/ssh-keys", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
req.AddCookie(&http.Cookie{Name: SessionCookie, Value: "good"})
req.AddCookie(&http.Cookie{Name: csrfCookie, Value: "tok"})
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
return rec.Code, rec.Body.String()
}
_, page := do(nil)
for _, want := range []string{`action="/profile/ssh-keys"`, "ssh ayse@llmt-1", "UID 200000", "/shared/home/ayse"} {
if !strings.Contains(page, want) {
t.Errorf("the page lacks %q", want)
}
}
key := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILq3vMdLAKlaDdxwrSgCtP/j/qrF4nzxNBNGuJmK5vxh ayse@laptop"
_, saved := do(url.Values{"keys": {key + "\n"}})
u, _ := st.SlurmUserByID(ctx, ayse.ID)
if len(u.SSHKeys) != 1 || u.SSHKeys[0] != key || !strings.Contains(saved, "within a minute") {
t.Fatalf("kept %v", u.SSHKeys)
}
_, bad := do(url.Values{"keys": {"not a key"}})
if !strings.Contains(bad, "Not kept") || !strings.Contains(bad, "not a key</textarea>") {
t.Error("a bad key was not refused, or the box lost what was typed")
}
if u, _ := st.SlurmUserByID(ctx, ayse.ID); len(u.SSHKeys) != 1 {
t.Error("a refused form changed the keys")
}
// Off: neither the part nor the form.
set.Users = ""
if _, page := do(nil); strings.Contains(page, "ssh-keys") {
t.Error("offered with slurm.users off")
}
if code, _ := do(url.Values{"keys": {key}}); code != http.StatusNotFound {
t.Errorf("posted with slurm.users off: %d", code)
}
}