diff --git a/graphql/env/__tests__/__snapshots__/merge.test.ts.snap b/graphql/env/__tests__/__snapshots__/merge.test.ts.snap index 98dcc9552..b6969aaf5 100644 --- a/graphql/env/__tests__/__snapshots__/merge.test.ts.snap +++ b/graphql/env/__tests__/__snapshots__/merge.test.ts.snap @@ -44,7 +44,6 @@ exports[`getEnvOptions merges pgpm defaults, graphql defaults, config, env, and "administrator": "administrator", "anonymous": "anonymous", "authenticated": "authenticated", - "authenticatedClient": "authenticated_client", "default": "anonymous", }, "rootDb": "postgres", diff --git a/pgpm/core/__tests__/roles/roles-sql-generators.test.ts b/pgpm/core/__tests__/roles/roles-sql-generators.test.ts index fa0dd9834..e3b3ebcb2 100644 --- a/pgpm/core/__tests__/roles/roles-sql-generators.test.ts +++ b/pgpm/core/__tests__/roles/roles-sql-generators.test.ts @@ -1,8 +1,8 @@ import { generateCreateBaseRolesSQL, generateCreateClientRoleSQL, - generateCreateUserSQL, generateCreateTestUsersSQL, + generateCreateUserSQL, generateRemoveUserSQL } from '../../src/roles'; @@ -75,12 +75,12 @@ describe('Role SQL Generators - Input Validation', () => { }).toThrow('generateCreateClientRoleSQL: roles is missing required properties'); }); - it('should throw an error when roles.authenticatedClient is missing', () => { - expect(() => { - generateCreateClientRoleSQL({ - authenticated: 'authenticated' - }); - }).toThrow('generateCreateClientRoleSQL: roles is missing required properties'); + it('should default the client role name when roles.authenticatedClient is missing', () => { + const sql = generateCreateClientRoleSQL({ + authenticated: 'authenticated' + }); + expect(sql).toContain('authenticated_client'); + expect(sql).toContain('CREATE ROLE'); }); it('should generate valid SQL when all roles are provided', () => { diff --git a/pgpm/core/src/roles/index.ts b/pgpm/core/src/roles/index.ts index cc14932f8..9c6656039 100644 --- a/pgpm/core/src/roles/index.ts +++ b/pgpm/core/src/roles/index.ts @@ -127,16 +127,16 @@ export function generateCreateClientRoleSQL( 'Ensure getConnEnvOptions().roles is defined.' ); } - if (!roles.authenticated || !roles.authenticatedClient) { + if (!roles.authenticated) { throw new Error( 'generateCreateClientRoleSQL: roles is missing required properties. ' + - `Got: authenticated=${roles.authenticated}, authenticatedClient=${roles.authenticatedClient}. ` + + `Got: authenticated=${roles.authenticated}. ` + 'Ensure all role names are defined in your configuration.' ); } const r = { authenticated: roles.authenticated, - authenticatedClient: roles.authenticatedClient + authenticatedClient: roles.authenticatedClient ?? 'authenticated_client' }; return ` diff --git a/pgpm/env/__tests__/__snapshots__/merge.test.ts.snap b/pgpm/env/__tests__/__snapshots__/merge.test.ts.snap index b60b50f48..8ba29ba73 100644 --- a/pgpm/env/__tests__/__snapshots__/merge.test.ts.snap +++ b/pgpm/env/__tests__/__snapshots__/merge.test.ts.snap @@ -29,7 +29,6 @@ exports[`getEnvOptions merges defaults, config, env, and overrides 1`] = ` "administrator": "administrator", "anonymous": "anonymous", "authenticated": "authenticated", - "authenticatedClient": "authenticated_client", "default": "anonymous", }, "rootDb": "postgres", diff --git a/pgpm/types/src/pgpm.ts b/pgpm/types/src/pgpm.ts index ab9a08024..c80cc38eb 100644 --- a/pgpm/types/src/pgpm.ts +++ b/pgpm/types/src/pgpm.ts @@ -1,5 +1,6 @@ import { execSync } from 'child_process'; import { PgConfig } from 'pg-env'; + import { PgpmDriverConfig } from './driver'; import { JobsConfig } from './jobs'; @@ -303,7 +304,6 @@ export const pgpmDefaults: PgpmOptions = { anonymous: 'anonymous', authenticated: 'authenticated', administrator: 'administrator', - authenticatedClient: 'authenticated_client', default: 'anonymous' }, useLocksForRoles: false @@ -313,13 +313,13 @@ export const pgpmDefaults: PgpmOptions = { port: 5432, user: 'postgres', password: 'password', - database: 'postgres', + database: 'postgres' }, server: { host: 'localhost', port: 3000, trustProxy: false, - strictAuth: false, + strictAuth: false }, cdn: { provider: 'minio',