@@ -40,6 +40,7 @@ jest.mock('@aws-sdk/client-redshift-data', () => {
4040} ) ;
4141
4242import { handler as managePrivileges } from '../../lib/private/database-query-provider/privileges' ;
43+ import { makePhysicalId } from '../../lib/private/database-query-provider/util' ;
4344
4445beforeEach ( ( ) => {
4546 jest . clearAllMocks ( ) ;
@@ -61,6 +62,31 @@ describe('create', () => {
6162 Sql : `GRANT INSERT, SELECT ON ${ tableName } TO ${ username } ` ,
6263 } ) ) ;
6364 } ) ;
65+
66+ test ( 'serializes properties in statement when tableName in physical resource ID' , async ( ) => {
67+ const properties = {
68+ ...resourceProperties ,
69+ tablePrivileges : [ {
70+ tableId,
71+ tableName : `${ makePhysicalId ( tableName , resourceProperties , requestId ) } ` ,
72+ actions,
73+ } ] ,
74+ } ;
75+
76+ const event = {
77+ ...baseEvent ,
78+ ResourceProperties : properties ,
79+ StackId : 'xxxxx:' + requestId ,
80+ } ;
81+
82+ await expect ( managePrivileges ( properties , event ) ) . resolves . toEqual ( {
83+ PhysicalResourceId : 'clusterName:databaseName:username:requestId' ,
84+ } ) ;
85+
86+ expect ( mockExecuteStatement ) . toHaveBeenCalledWith ( expect . objectContaining ( {
87+ Sql : `GRANT INSERT, SELECT ON ${ tableName } TO ${ username } ` ,
88+ } ) ) ;
89+ } ) ;
6490} ) ;
6591
6692describe ( 'delete' , ( ) => {
@@ -79,6 +105,29 @@ describe('delete', () => {
79105 Sql : `REVOKE INSERT, SELECT ON ${ tableName } FROM ${ username } ` ,
80106 } ) ) ;
81107 } ) ;
108+
109+ test ( 'serializes properties in statement when tableName in physical resource ID' , async ( ) => {
110+ const properties = {
111+ ...resourceProperties ,
112+ tablePrivileges : [ {
113+ tableId,
114+ tableName : `${ makePhysicalId ( tableName , resourceProperties , requestId ) } ` ,
115+ actions,
116+ } ] ,
117+ } ;
118+
119+ const event = {
120+ ...baseEvent ,
121+ ResourceProperties : properties ,
122+ StackId : 'xxxxx:' + requestId ,
123+ } ;
124+
125+ await managePrivileges ( properties , event ) ;
126+
127+ expect ( mockExecuteStatement ) . toHaveBeenCalledWith ( expect . objectContaining ( {
128+ Sql : `REVOKE INSERT, SELECT ON ${ tableName } FROM ${ username } ` ,
129+ } ) ) ;
130+ } ) ;
82131} ) ;
83132
84133describe ( 'update' , ( ) => {
0 commit comments