Sync shared snapshot from 78067cc
Docker / Docker Build & Push (push) Successful in 2m5s

This commit is contained in:
Gabriel20xx committed 2026-09-17 00:00:32 +02:00
1 parent 08a6d7bd1d
commit b3d27ff37e
5 files changed
+165 -114

No files matched your search

+30 -4
View File
@@ -14,7 +14,7 @@ type fakeProxyStore struct {
setupClaimed bool
}
func (s *fakeProxyStore) LoginRequired(context.Context) (bool, error) { return s.loginRequired, nil }
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
@@ -39,7 +39,7 @@ func (s *fakeProxyStore) UnclaimSetup(context.Context) error {
// 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")
service := NewWithStore(&fakeProxyStore{loginRequired: true}, "session", false, "", "testproject")
if !service.enabled() {
t.Fatal("Service with no authGuardURL and no Disabled() option should still be enabled (pending), not disabled")
}
@@ -60,8 +60,34 @@ func TestDisabledOptionSkipsGating(t *testing.T) {
}
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)
if err != nil || user == nil || user.Username != "Admin" || !IsAdmin(user) {
t.Fatalf("Disabled() Service should resolve the fixed Admin superadmin profile, got user=%+v err=%v", user, err)
}
}
func TestLoginDisabledUsesAdminIdentityWithoutCredentials(t *testing.T) {
store := &fakeProxyStore{loginRequired: false}
service := NewWithStore(store, "session", false, "", "testproject")
req := httptest.NewRequest(http.MethodGet, "/", nil)
user, err := service.CurrentUser(req)
if err != nil || user == nil || user.Username != "Admin" || !IsAdmin(user) {
t.Fatalf("login-disabled Service should resolve the Admin identity, got user=%+v err=%v", user, err)
}
called := false
handler := service.RequireAdminIfLoginRequired(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
called = true
contextUser := UserFromContext(r.Context())
if contextUser == nil || contextUser.Username != "Admin" || !IsAdmin(contextUser) {
t.Errorf("middleware context user = %+v, want Admin superadmin", contextUser)
}
w.WriteHeader(http.StatusNoContent)
}))
response := httptest.NewRecorder()
handler.ServeHTTP(response, req)
if response.Code != http.StatusNoContent || !called {
t.Fatalf("login-disabled admin middleware status = %d/called=%v, want %d/true", response.Code, called, http.StatusNoContent)
}
}