Learn AuthGuard/CarrierNode URLs from ProjectConfigurator's push
Lint / Lint (push) Successful in 39s
Tests / Go backend (push) Successful in 42s
Tests / Dashboard checks (push) Successful in 46s
Docker / Docker Build & Push (push) Successful in 3m37s

Adds the receiving end of ProjectConfigurator's core-services push
(PUT /api/core-services/internal, X-Internal-Auth-gated) via the shared
coreconfig package, so this service's AUTHGUARD_URL/CARRIERNODE_URL env
vars become just the bootstrap/fallback value instead of the permanent
source of truth. authclient.Client gains a concurrency-safe SetBaseURL
so a later push retargets it in place with no restart.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-10 11:56:17 +02:00
1 parent 20e9461d46
commit 7c4a903f59
7 files changed
+323 -11

No files matched your search

@@ -0,0 +1,83 @@
package coreconfig
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestStoreSetIgnoresBlankFields(t *testing.T) {
store := NewStore(Info{AuthGuardURL: "http://auth.example.com", CarrierNodeURL: "http://carrier.example.com"})
store.Set(Info{CarrierNodeURL: "http://carrier2.example.com"})
got := store.Get()
if got.AuthGuardURL != "http://auth.example.com" {
t.Fatalf("AuthGuardURL = %q, want unchanged", got.AuthGuardURL)
}
if got.CarrierNodeURL != "http://carrier2.example.com" {
t.Fatalf("CarrierNodeURL = %q, want updated", got.CarrierNodeURL)
}
}
func TestStoreOnUpdateFiresWithNewInfo(t *testing.T) {
store := NewStore(Info{})
var got Info
calls := 0
store.OnUpdate(func(info Info) {
calls++
got = info
})
store.Set(Info{AuthGuardURL: "http://auth.example.com"})
if calls != 1 {
t.Fatalf("OnUpdate called %d times, want 1", calls)
}
if got.AuthGuardURL != "http://auth.example.com" {
t.Fatalf("OnUpdate saw AuthGuardURL = %q, want http://auth.example.com", got.AuthGuardURL)
}
}
func TestHandlerRejectsMissingOrWrongSecret(t *testing.T) {
store := NewStore(Info{})
handler := Handler("s3cret", store)
body, _ := json.Marshal(Info{AuthGuardURL: "http://auth.example.com"})
cases := []string{"", "wrong"}
for _, header := range cases {
req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body))
if header != "" {
req.Header.Set("X-Internal-Auth", header)
}
rec := httptest.NewRecorder()
handler(rec, req)
if rec.Code != http.StatusUnauthorized {
t.Fatalf("status = %d, want 401 for X-Internal-Auth=%q", rec.Code, header)
}
}
if got := store.Get(); got.AuthGuardURL != "" {
t.Fatalf("store was updated despite auth failure: %+v", got)
}
}
func TestHandlerAppliesPushedInfo(t *testing.T) {
store := NewStore(Info{})
handler := Handler("s3cret", store)
body, _ := json.Marshal(Info{AuthGuardURL: "http://auth.example.com", CarrierNodeURL: "http://carrier.example.com"})
req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body))
req.Header.Set("X-Internal-Auth", "s3cret")
rec := httptest.NewRecorder()
handler(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
}
got := store.Get()
if got.AuthGuardURL != "http://auth.example.com" || got.CarrierNodeURL != "http://carrier.example.com" {
t.Fatalf("store = %+v, want pushed values applied", got)
}
}