@@ -81,7 +81,7 @@ afterAll(async () => {
8181// starts from a blank cluster:
8282beforeEach ( ( ) => cluster . reset ( ) ) ;
8383
84- test ( "read access covers existing/RLS and future tables from both creators without writes" , async ( ) => {
84+ test . each ( [ true , false , undefined ] ) ( "read access covers existing/RLS and future tables without writes (BypassRls: %s) " , async ( bypassRls ) => {
8585 const client = await cluster . connectTo ( DB_DEFAULT_DB ) ;
8686 try {
8787 await client . query ( `
@@ -92,6 +92,8 @@ test("read access covers existing/RLS and future tables from both creators witho
9292 CREATE TABLE public.items (id int);
9393 INSERT INTO public.items VALUES (1);
9494 ALTER TABLE public.items ENABLE ROW LEVEL SECURITY;
95+ CREATE TABLE public.ordinary (id int);
96+ INSERT INTO public.ordinary VALUES (1);
9597 RESET ROLE;
9698 ` ) ;
9799 const event = {
@@ -106,7 +108,8 @@ test("read access covers existing/RLS and future tables from both creators witho
106108 Username : DB_MASTER_USERNAME , PasswordArn : masterPasswordArn , SSLMode : "disable" ,
107109 } ,
108110 Role : "reader" , Schema : "public" ,
109- CreatorRoles : [ "app" , DB_MASTER_USERNAME ] , BypassRls : true ,
111+ CreatorRoles : [ "app" , DB_MASTER_USERNAME ] ,
112+ ...( bypassRls === undefined ? { } : { BypassRls : bypassRls } ) ,
110113 } ,
111114 } as CloudFormationCustomResourceEvent ;
112115 await expect ( handler ( {
@@ -127,14 +130,19 @@ test("read access covers existing/RLS and future tables from both creators witho
127130 RESET ROLE;
128131 SET ROLE reader;
129132 ` ) ;
130- for ( const table of [ "items" , "from_master" , "from_app" ] ) {
133+ expect ( ( await client . query (
134+ "SELECT rolbypassrls FROM pg_roles WHERE rolname = current_user"
135+ ) ) . rows [ 0 ] . rolbypassrls ) . toBe ( bypassRls === true ) ;
136+ expect ( ( await client . query ( "SELECT * FROM public.items" ) ) . rowCount ) . toBe ( bypassRls ? 1 : 0 ) ;
137+ for ( const table of [ "ordinary" , "from_master" , "from_app" ] ) {
131138 expect ( ( await client . query ( `SELECT * FROM public.${ table } ` ) ) . rowCount ) . toBe ( 1 ) ;
132139 }
133140 await expect ( client . query ( "INSERT INTO public.items VALUES (4)" ) ) . rejects . toThrow ( / p e r m i s s i o n d e n i e d / ) ;
134141 await expect ( client . query ( "UPDATE public.items SET id = 4" ) ) . rejects . toThrow ( / p e r m i s s i o n d e n i e d / ) ;
135142 await expect ( client . query ( "DELETE FROM public.items" ) ) . rejects . toThrow ( / p e r m i s s i o n d e n i e d / ) ;
136143 await handler ( { ...event , RequestType : "Delete" , PhysicalResourceId : "ReadAccess" } ) ;
137- expect ( ( await client . query ( "SELECT * FROM public.items" ) ) . rowCount ) . toBe ( 1 ) ;
144+ expect ( ( await client . query ( "SELECT * FROM public.items" ) ) . rowCount ) . toBe ( bypassRls ? 1 : 0 ) ;
145+ expect ( ( await client . query ( "SELECT * FROM public.ordinary" ) ) . rowCount ) . toBe ( 1 ) ;
138146 } finally {
139147 await client . end ( ) ;
140148 }
0 commit comments