TestAdminMeta tests the _admin_meta query, the non-deprecated source of the configured roles for the dashboard. It must be super-admin gated and return the configured role lists.
(t *testing.T)
| 15 | // configured roles for the dashboard. It must be super-admin gated and return |
| 16 | // the configured role lists. |
| 17 | func TestAdminMeta(t *testing.T) { |
| 18 | cfg := getTestConfig() |
| 19 | ts := initTestSetup(t, cfg) |
| 20 | req, ctx := createContext(ts) |
| 21 | |
| 22 | t.Run("should fail without admin cookie", func(t *testing.T) { |
| 23 | res, err := ts.GraphQLProvider.AdminMeta(ctx) |
| 24 | assert.Error(t, err) |
| 25 | assert.Nil(t, res) |
| 26 | }) |
| 27 | |
| 28 | t.Run("should return configured roles with a valid admin cookie", func(t *testing.T) { |
| 29 | _, err := ts.GraphQLProvider.AdminLogin(ctx, &model.AdminLoginRequest{ |
| 30 | AdminSecret: cfg.AdminSecret, |
| 31 | }) |
| 32 | require.NoError(t, err) |
| 33 | |
| 34 | h, err := crypto.EncryptPassword(cfg.AdminSecret) |
| 35 | require.NoError(t, err) |
| 36 | req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h)) |
| 37 | |
| 38 | res, err := ts.GraphQLProvider.AdminMeta(ctx) |
| 39 | require.NoError(t, err) |
| 40 | require.NotNil(t, res) |
| 41 | // Mirrors the configured roles in getTestConfig. |
| 42 | assert.Equal(t, cfg.Roles, res.Roles) |
| 43 | assert.Equal(t, cfg.DefaultRoles, res.DefaultRoles) |
| 44 | assert.Contains(t, res.Roles, "admin") |
| 45 | // Non-null list contract: never nil, even when nothing is configured. |
| 46 | assert.NotNil(t, res.ProtectedRoles) |
| 47 | }) |
| 48 | } |
nothing calls this directly
no test coverage detected