Files
ziti/tests/default_admin_test.go
Paul Lorenz 566c09c7b2 Keep the default admin an admin. Fixes #4561
- rejects, in the identity store, any create or update whose result would be a default admin without admin rights
- counts an identity as admin by either flag in the apply-time admin precondition, matching how a session's permissions are resolved, so a default admin whose flag was cleared before the guard existed still has and receives admin protection
- tests the rejection on create and update, the legacy-data case at the manager level, and the rejected patch through the API
2026-10-07 14:56:34 -04:00

32 lines
1.2 KiB
Go

//go:build apitests
package tests
import (
"testing"
"github.com/openziti/edge-api/rest_model"
"github.com/openziti/foundation/v2/errorz"
)
// Test_DefaultAdminStaysAdmin: the default admin's isAdmin flag cannot be cleared.
func Test_DefaultAdminStaysAdmin(t *testing.T) {
ctx := NewTestContext(t)
defer ctx.Teardown()
ctx.StartServer()
ctx.RequireAdminManagementApiLogin()
current := ctx.AdminManagementSession.requireQuery("current-identity")
defaultAdminId := ctx.RequireGetNonNilPathValue(current, "data", "id").Data().(string)
ctx.Req.True(ctx.RequireGetNonNilPathValue(current, "data", "isDefaultAdmin").Data().(bool), "the admin session belongs to the default admin")
resp, err := ctx.AdminManagementSession.newAuthenticatedRequest().
SetBody(&rest_model.IdentityPatch{IsAdmin: ToPtr(false)}).
Patch("/identities/" + defaultAdminId)
ctx.Req.NoError(err)
ctx.requireFieldError(resp.StatusCode(), resp.Body(), errorz.CouldNotValidateCode, "isAdmin")
detail := ctx.AdminManagementSession.requireQuery("identities/" + defaultAdminId)
ctx.Req.True(ctx.RequireGetNonNilPathValue(detail, "data", "isAdmin").Data().(bool), "the default admin is still an admin")
}