Console: l'identifiant du noeud est ajoute automatiquement a GARAGE_RPC_HOST (GetNodeInfo)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
cedricandClaude Sonnet 5.5 committed 2026-11-21 13:03:32 +01:00
1 parent 17b98b6cf3
commit ca1330434e
4 files changed
+122 -7

No files matched your search

+44 -1
View File
@@ -125,7 +125,9 @@ func TestMutationNeedsCSRFHeader(t *testing.T) {
func TestCLIWhitelist(t *testing.T) {
g, _ := fakeGarage(t)
h := newTestConfig(t, g).routes()
c := newTestConfig(t, g)
c.rpcHost = "ff00@garage.test:3901" // déjà complet : la résolution a son propre test
h := c.routes()
ck := login(t, h)
call := func(body string) *httptest.ResponseRecorder {
req := httptest.NewRequest("POST", "/api/cli", strings.NewReader(body))
@@ -144,3 +146,44 @@ func TestCLIWhitelist(t *testing.T) {
}
}
}
func TestResolveRPCHost(t *testing.T) {
calls := 0
rt := roundTripFunc(func(r *http.Request) (*http.Response, error) {
calls++
rec := httptest.NewRecorder()
if r.URL.Path != "/v2/GetNodeInfo" || r.URL.Query().Get("node") != "self" || r.Header.Get("Authorization") != "Bearer tok" {
rec.WriteHeader(400)
return rec.Result(), nil
}
_, _ = rec.WriteString(`{"success":{"abc123":{"nodeId":"abc123"}},"error":{}}`)
return rec.Result(), nil
})
c := newTestConfig(t, rt)
c.rpcHost = "garage:3901"
for i := 0; i < 2; i++ { // le second appel doit venir du cache
got, err := c.resolveRPCHost(t.Context())
if err != nil || got != "abc123@garage:3901" {
t.Fatalf("résolu : %q, %v", got, err)
}
}
if calls != 1 {
t.Fatalf("%d appels à GetNodeInfo, attendu 1 (cache)", calls)
}
// Déjà au bon format : aucun appel.
c2 := newTestConfig(t, rt)
c2.rpcHost = "ff00@10.0.0.2:3901"
before := calls
if got, _ := c2.resolveRPCHost(t.Context()); got != "ff00@10.0.0.2:3901" || calls != before {
t.Fatalf("hôte complet modifié ou appel inutile : %q", got)
}
// Vide : hôte de l'API d'administration, port 3901.
c3 := newTestConfig(t, rt)
c3.rpcHost = ""
if got, _ := c3.resolveRPCHost(t.Context()); got != "abc123@garage.test:3901" {
t.Fatalf("hôte par défaut : %q", got)
}
}