Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion graphql/env/__tests__/__snapshots__/merge.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions pgpm/core/__tests__/roles/roles-sql-generators.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
generateCreateBaseRolesSQL,
generateCreateClientRoleSQL,
generateCreateUserSQL,
generateCreateTestUsersSQL,
generateCreateUserSQL,
generateRemoveUserSQL
} from '../../src/roles';

Expand Down Expand Up @@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions pgpm/core/src/roles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
Expand Down
1 change: 0 additions & 1 deletion pgpm/env/__tests__/__snapshots__/merge.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions pgpm/types/src/pgpm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { execSync } from 'child_process';
import { PgConfig } from 'pg-env';

import { PgpmDriverConfig } from './driver';
import { JobsConfig } from './jobs';

Expand Down Expand Up @@ -303,7 +304,6 @@ export const pgpmDefaults: PgpmOptions = {
anonymous: 'anonymous',
authenticated: 'authenticated',
administrator: 'administrator',
authenticatedClient: 'authenticated_client',
default: 'anonymous'
},
useLocksForRoles: false
Expand All @@ -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',
Expand Down
Loading