Files
supabase/apps/studio/components/interfaces/Database/Roles/Roles.utils.test.ts
39b359a70e chore: keep db partner roles out of picker (#54019)
## Problem

Newly added trusted partner roles appear as user selectable /
manageable. Resolves DEPR-735.

## Solution

Trusted partner roles should not be selectable in temporary access. And
should not appear as modifiable in the database roles tab.

| Before | After |
| --- | --- |
| <img width="553" height="398" alt="CleanShot 2026-11-27 at 12 24 43"
src="https://github.com/user-attachments/assets/14affc16-2f00-496f-a124-d918acd93bf0"
/> | <img width="553" height="363" alt="CleanShot 2026-11-27 at 12 25
00"
src="https://github.com/user-attachments/assets/de06002f-d063-453e-a9da-00eee8e0616d"
/> |
| _This partner role `this_is_a_test` shouldn’t be here._ | _Partner
role `this_is_a_test` is no longer in the list of options._ |
| <img width="940" height="305" alt="CleanShot 2026-11-30 at 10 34 52"
src="https://github.com/user-attachments/assets/bdface9f-b3f4-4620-b567-cba8d829205e"
/> | <img width="935" height="299" alt="CleanShot 2026-11-30 at 10 37
40"
src="https://github.com/user-attachments/assets/da1abaa3-5a98-4837-9e8f-35be84b6be4c"
/> |
| _Previous definition._ | _Broadened definition to better encompass
roles we generally manage
([context](https://github.com/supabase/supabase/pull/54019#discussion_r4716757425))._
|

## How to test

1. Open the [Studio staging
preview](https://studio-staging-git-chore-depr-735-supabase.vercel.app)
and select a staging test project. If **Temporary access** is off in
**Feature previews**, enable it there. Then go to **Database → Settings
→ Temporary access** and make sure it is enabled for the test project.
2. Go to **Database → Roles**. Open Chrome DevTools, select **Network**,
and reload. Filter for `key=database-roles`. Right-click the matching
request and select **Override content**.
3. Append this test role to the roles array. Save the override and
reload.

```json
{
  "id": 99999,
  "name": "this_is_a_test",
  "isSuperuser": false,
  "canCreateDb": false,
  "canCreateRole": false,
  "inheritRole": true,
  "canLogin": true,
  "isReplicationRole": false,
  "canBypassRls": false,
  "activeConnections": 0,
  "connectionLimit": 90,
  "validUntil": null,
  "comment": "{\"_supabase\":{\"oauth_app_id\":\"app\"}}",
  "config": {}
}
```

4. In **Database → Roles**, make sure that `this_is_a_test` appears
under **Supabase managed roles** without edit or delete controls.
5. Go to **Database → Settings → Temporary access**, select **Add
rule**, and open the role picker. The test role should be absent.
6. Set the test role's `comment` to `null` in the override and reload.
Open **Add rule** again and make sure that the role is now selectable.
Close the form without saving and remove the override.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
2026-11-30 15:35:30 +01:00

49 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { isSupabaseManagedRole, isSupabaseRole, isTrustedPartnerRole } from './Roles.utils'
describe('isSupabaseRole', () => {
it('matches exact Supabase role names', () => {
expect(isSupabaseRole('supabase_admin')).toBe(true)
expect(isSupabaseRole('authenticated')).toBe(true)
})
it('matches roles with a Supabase-managed prefix', () => {
expect(isSupabaseRole('support_ro_1a2b3c')).toBe(true)
})
it('does not match user-created roles', () => {
expect(isSupabaseRole('my_role')).toBe(false)
expect(isSupabaseRole('support_ro')).toBe(false)
expect(isSupabaseRole('my_support_ro_role')).toBe(false)
})
})
describe('isTrustedPartnerRole', () => {
it('matches the comment the platform sets on Trusted Partner roles', () => {
expect(isTrustedPartnerRole('{"_supabase":{"oauth_app_id":"app"}}')).toBe(true)
})
it('does not match other comments', () => {
expect(isTrustedPartnerRole(null)).toBe(false)
expect(isTrustedPartnerRole('')).toBe(false)
expect(isTrustedPartnerRole('Role for reporting')).toBe(false)
expect(isTrustedPartnerRole('{"_supabase":')).toBe(false)
expect(isTrustedPartnerRole('{"_supabase":{}}')).toBe(false)
expect(isTrustedPartnerRole('null')).toBe(false)
})
})
describe('isSupabaseManagedRole', () => {
it('matches Supabase roles by name and Trusted Partner roles by comment', () => {
expect(isSupabaseManagedRole({ name: 'authenticated', comment: null })).toBe(true)
expect(
isSupabaseManagedRole({
name: 'acme_user',
comment: '{"_supabase":{"oauth_app_id":"app"}}',
})
).toBe(true)
expect(isSupabaseManagedRole({ name: 'acme_user', comment: null })).toBe(false)
})
})