@@ -81,7 +81,7 @@ test('revoke & grant column privileges', async () => {
81
81
] ,
82
82
} )
83
83
let privs = res . json < PostgresColumnPrivileges [ ] > ( )
84
- expect ( privs . length === 1 )
84
+ expect ( privs . length ) . toBe ( 1 )
85
85
expect ( privs [ 0 ] ) . toMatchInlineSnapshot (
86
86
{ column_id : expect . stringMatching ( / ^ \d + \. \d + $ / ) } ,
87
87
`
@@ -156,7 +156,7 @@ test('revoke & grant column privileges', async () => {
156
156
] ,
157
157
} )
158
158
privs = res . json < PostgresColumnPrivileges [ ] > ( )
159
- expect ( privs . length === 1 )
159
+ expect ( privs . length ) . toBe ( 1 )
160
160
expect ( privs [ 0 ] ) . toMatchInlineSnapshot (
161
161
{ column_id : expect . stringMatching ( / ^ \d + \. \d + $ / ) } ,
162
162
`
@@ -206,3 +206,158 @@ test('revoke & grant column privileges', async () => {
206
206
throw new Error ( res . payload )
207
207
}
208
208
} )
209
+
210
+ test ( 'revoke & grant column privileges w/ quoted column name' , async ( ) => {
211
+ let res = await app . inject ( {
212
+ method : 'POST' ,
213
+ path : '/query' ,
214
+ payload : {
215
+ query : `create role r; create table "t 1"("c 1" int8);` ,
216
+ } ,
217
+ } )
218
+ if ( res . json ( ) . error ) {
219
+ throw new Error ( res . payload )
220
+ }
221
+
222
+ res = await app . inject ( { method : 'GET' , path : '/column-privileges' } )
223
+ const { column_id } = res
224
+ . json < PostgresColumnPrivileges [ ] > ( )
225
+ . find ( ( { relation_name, column_name } ) => relation_name === 't 1' && column_name === 'c 1' ) !
226
+
227
+ res = await app . inject ( {
228
+ method : 'POST' ,
229
+ path : '/column-privileges' ,
230
+ payload : [
231
+ {
232
+ column_id,
233
+ grantee : 'r' ,
234
+ privilege_type : 'ALL' ,
235
+ } ,
236
+ ] ,
237
+ } )
238
+ let privs = res . json < PostgresColumnPrivileges [ ] > ( )
239
+ expect ( privs . length ) . toBe ( 1 )
240
+ expect ( privs [ 0 ] ) . toMatchInlineSnapshot (
241
+ { column_id : expect . stringMatching ( / ^ \d + \. \d + $ / ) } ,
242
+ `
243
+ {
244
+ "column_id": StringMatching /\\^\\\\d\\+\\\\\\.\\\\d\\+\\$/,
245
+ "column_name": "c 1",
246
+ "privileges": [
247
+ {
248
+ "grantee": "r",
249
+ "grantor": "postgres",
250
+ "is_grantable": false,
251
+ "privilege_type": "UPDATE",
252
+ },
253
+ {
254
+ "grantee": "r",
255
+ "grantor": "postgres",
256
+ "is_grantable": false,
257
+ "privilege_type": "SELECT",
258
+ },
259
+ {
260
+ "grantee": "r",
261
+ "grantor": "postgres",
262
+ "is_grantable": false,
263
+ "privilege_type": "REFERENCES",
264
+ },
265
+ {
266
+ "grantee": "r",
267
+ "grantor": "postgres",
268
+ "is_grantable": false,
269
+ "privilege_type": "INSERT",
270
+ },
271
+ {
272
+ "grantee": "postgres",
273
+ "grantor": "postgres",
274
+ "is_grantable": false,
275
+ "privilege_type": "UPDATE",
276
+ },
277
+ {
278
+ "grantee": "postgres",
279
+ "grantor": "postgres",
280
+ "is_grantable": false,
281
+ "privilege_type": "SELECT",
282
+ },
283
+ {
284
+ "grantee": "postgres",
285
+ "grantor": "postgres",
286
+ "is_grantable": false,
287
+ "privilege_type": "REFERENCES",
288
+ },
289
+ {
290
+ "grantee": "postgres",
291
+ "grantor": "postgres",
292
+ "is_grantable": false,
293
+ "privilege_type": "INSERT",
294
+ },
295
+ ],
296
+ "relation_name": "t 1",
297
+ "relation_schema": "public",
298
+ }
299
+ `
300
+ )
301
+
302
+ res = await app . inject ( {
303
+ method : 'DELETE' ,
304
+ path : '/column-privileges' ,
305
+ payload : [
306
+ {
307
+ column_id,
308
+ grantee : 'r' ,
309
+ privilege_type : 'ALL' ,
310
+ } ,
311
+ ] ,
312
+ } )
313
+ privs = res . json < PostgresColumnPrivileges [ ] > ( )
314
+ expect ( privs . length ) . toBe ( 1 )
315
+ expect ( privs [ 0 ] ) . toMatchInlineSnapshot (
316
+ { column_id : expect . stringMatching ( / ^ \d + \. \d + $ / ) } ,
317
+ `
318
+ {
319
+ "column_id": StringMatching /\\^\\\\d\\+\\\\\\.\\\\d\\+\\$/,
320
+ "column_name": "c 1",
321
+ "privileges": [
322
+ {
323
+ "grantee": "postgres",
324
+ "grantor": "postgres",
325
+ "is_grantable": false,
326
+ "privilege_type": "UPDATE",
327
+ },
328
+ {
329
+ "grantee": "postgres",
330
+ "grantor": "postgres",
331
+ "is_grantable": false,
332
+ "privilege_type": "SELECT",
333
+ },
334
+ {
335
+ "grantee": "postgres",
336
+ "grantor": "postgres",
337
+ "is_grantable": false,
338
+ "privilege_type": "REFERENCES",
339
+ },
340
+ {
341
+ "grantee": "postgres",
342
+ "grantor": "postgres",
343
+ "is_grantable": false,
344
+ "privilege_type": "INSERT",
345
+ },
346
+ ],
347
+ "relation_name": "t 1",
348
+ "relation_schema": "public",
349
+ }
350
+ `
351
+ )
352
+
353
+ res = await app . inject ( {
354
+ method : 'POST' ,
355
+ path : '/query' ,
356
+ payload : {
357
+ query : `drop role r; drop table "t 1";` ,
358
+ } ,
359
+ } )
360
+ if ( res . json ( ) . error ) {
361
+ throw new Error ( res . payload )
362
+ }
363
+ } )
0 commit comments