Make AuthGuard integration decouple from knowing the URL at startup
Every language's AuthGuard client/service used "no URL at construction" to mean "auth disabled forever" - a live SetBaseUrl/setBaseUrl push from ProjectConfigurator could only ever retarget an *already-enabled* client, never turn one on for the first time. That made AUTHGUARD_URL a de-facto required env var everywhere, even though ProjectConfigurator can push it live after startup. - Go: shared/backend/auth's New/NewWithStore now default to a "pending" Service (still enabled, fails closed until a URL arrives) instead of disabled when authGuardURL is empty; add an explicit Disabled() option for the genuine standalone/local-dev opt-out. - Python/Node/Java: add setBaseUrl/set_base_url to each AuthClient so a client built with an empty base URL can be retargeted in place once a URL is pushed, the same as the Go client already supported. - Python/Node: add a coreconfig module (Info/Store), the framework-agnostic equivalent of shared/backend/coreconfig (Go), for services in those languages to receive ProjectConfigurator's core-services push at all. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c09957189f
commit
dcfdb3d7af
18 files changed
+747
-46
No files matched your search
@@ -1,6 +1,69 @@
|
||||
package auth
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// fakeProxyStore is a minimal in-memory ProxyStore for constructing a
|
||||
// Service in tests without a real database.
|
||||
type fakeProxyStore struct {
|
||||
loginRequired bool
|
||||
setupClaimed bool
|
||||
}
|
||||
|
||||
func (s *fakeProxyStore) LoginRequired(context.Context) (bool, error) { return s.loginRequired, nil }
|
||||
func (s *fakeProxyStore) SetLoginRequired(_ context.Context, v bool) error {
|
||||
s.loginRequired = v
|
||||
return nil
|
||||
}
|
||||
func (s *fakeProxyStore) IsSetupClaimed(context.Context) (bool, error) { return s.setupClaimed, nil }
|
||||
func (s *fakeProxyStore) TryClaimSetup(context.Context) (bool, error) {
|
||||
if s.setupClaimed {
|
||||
return false, nil
|
||||
}
|
||||
s.setupClaimed = true
|
||||
return true, nil
|
||||
}
|
||||
func (s *fakeProxyStore) UnclaimSetup(context.Context) error {
|
||||
s.setupClaimed = false
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestPendingModeStillGatesRequests locks in the fix that made an empty
|
||||
// authGuardURL at construction mean "pending" (auth still enabled, calls
|
||||
// fail closed until a real URL arrives via SetAuthGuardBaseURL) instead of
|
||||
// "disabled" (nothing gated, a fixed superadmin identity) - the bug that
|
||||
// made AUTHGUARD_URL a de-facto requirement even though ProjectConfigurator
|
||||
// can push it live after startup.
|
||||
func TestPendingModeStillGatesRequests(t *testing.T) {
|
||||
service := NewWithStore(&fakeProxyStore{}, "session", false, "", "testproject")
|
||||
if !service.enabled() {
|
||||
t.Fatal("Service with no authGuardURL and no Disabled() option should still be enabled (pending), not disabled")
|
||||
}
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
req.AddCookie(&http.Cookie{Name: "auth_session", Value: "sometoken"})
|
||||
if _, err := service.CurrentUser(req); err == nil {
|
||||
t.Fatal("pending Service (no AuthGuard URL yet) should fail closed on a real session cookie, not silently resolve a user")
|
||||
}
|
||||
}
|
||||
|
||||
// TestDisabledOptionSkipsGating confirms the explicit opt-out still works
|
||||
// exactly like the old "empty authGuardURL" behavior.
|
||||
func TestDisabledOptionSkipsGating(t *testing.T) {
|
||||
service := NewWithStore(&fakeProxyStore{}, "session", false, "", "testproject", Disabled())
|
||||
if service.enabled() {
|
||||
t.Fatal("Service built with Disabled() should report enabled() == false")
|
||||
}
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
user, err := service.CurrentUser(req)
|
||||
if err != nil || user == nil || user.Username != "local" {
|
||||
t.Fatalf("Disabled() Service should resolve the fixed local superadmin profile, got user=%+v err=%v", user, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeProxyCredentials(t *testing.T) {
|
||||
email, username, password, err := normalizeProxyCredentials(" User@Example.com ", "user", "correct horse battery staple")
|
||||
|
||||
Reference in new issue
Block a user