@@ -218,4 +218,50 @@ describe('[#26572] the v18 /meta read doors, over HTTP on a booted showcase', ()
218218 expect ( memberApps , 'a member never sees setup' ) . not . toContain ( 'setup' ) ;
219219 } ) ;
220220 } ) ;
221+
222+ // The same class on the view switcher's `object` and on the list's
223+ // `package` scope: a bracketed key (`?object[]=`, `?package[]=`) reached the
224+ // door under the key as spelled, so the filter never read it, and a caller
225+ // who asked for one object's views (or one package's items) got every view
226+ // (or every package's items). Each is refused: 400 VALIDATION_ERROR naming
227+ // the key, no list.
228+ describe ( 'GET /meta/view with a bracketed `object` key, and a list with a bracketed `package` key, are refused' , ( ) => {
229+ const itemsOf = ( body : any ) : any [ ] => ( Array . isArray ( body ) ? body : body ?. items ) ?? [ ] ;
230+ const OBJ = 'showcase_task' ;
231+
232+ for ( const [ path , key ] of [
233+ [ '/meta/view' , 'object[]' ] , [ '/meta/view' , 'object[0]' ] ,
234+ [ '/meta/object' , 'package[]' ] , [ '/meta/object' , 'package[0]' ] ,
235+ ] as const ) {
236+ it ( `${ path } ?${ key } =…: 400 VALIDATION_ERROR naming the key, for the admin and for a member` , async ( ) => {
237+ const value = key . startsWith ( 'object' ) ? OBJ : PKG ;
238+ const names = key . startsWith ( 'object' ) ? 'object' : 'package' ;
239+ for ( const [ who , token ] of [ [ 'admin' , admin ] , [ 'member' , liaison ] ] as const ) {
240+ const res = await stack . apiAs ( token , 'GET' , `${ path } ?${ key } =${ encodeURIComponent ( value ) } ` ) ;
241+ const body : any = await res . json ( ) ;
242+ expect ( { who, status : res . status , code : codeOf ( body ) } , JSON . stringify ( body ) . slice ( 0 , 400 ) )
243+ . toEqual ( { who, status : 400 , code : 'VALIDATION_ERROR' } ) ;
244+ expect ( messageOf ( body ) ) . toMatch ( new RegExp ( `^Query parameter '${ key . replace ( / [ [ \] ] / g, '\\$&' ) } ' names no ${ names } ` ) ) ;
245+ expect ( itemsOf ( body ) ) . toEqual ( [ ] ) ;
246+ }
247+ } ) ;
248+ }
249+
250+ it ( 'CONTROLS — ?object=NAME is that object\'s views and ?package=ID that package\'s items, each narrower than no filter' , async ( ) => {
251+ const all = itemsOf ( await ( await stack . apiAs ( admin , 'GET' , '/meta/view' ) ) . json ( ) ) ;
252+ const switched = await stack . apiAs ( admin , 'GET' , `/meta/view?object=${ OBJ } ` ) ;
253+ expect ( switched . status ) . toBe ( 200 ) ;
254+ const views = itemsOf ( await switched . json ( ) ) ;
255+ expect ( views . length , 'the showcase ships views of showcase_task' ) . toBeGreaterThan ( 0 ) ;
256+ expect ( views . every ( ( v : any ) => v ?. object === OBJ ) , JSON . stringify ( views . map ( ( v : any ) => v ?. object ) ) ) . toBe ( true ) ;
257+ expect ( views . length ) . toBeLessThan ( all . length ) ;
258+
259+ const everyPackage = itemsOf ( await ( await stack . apiAs ( admin , 'GET' , '/meta/object' ) ) . json ( ) ) ;
260+ const scoped = await stack . apiAs ( admin , 'GET' , `/meta/object?package=${ encodeURIComponent ( PKG ) } ` ) ;
261+ expect ( scoped . status ) . toBe ( 200 ) ;
262+ const objects = itemsOf ( await scoped . json ( ) ) ;
263+ expect ( objects . length , 'the showcase package declares objects' ) . toBeGreaterThan ( 0 ) ;
264+ expect ( objects . length ) . toBeLessThan ( everyPackage . length ) ;
265+ } ) ;
266+ } ) ;
221267} ) ;
0 commit comments