File tree Expand file tree Collapse file tree
x-pack/platform/plugins/shared/global_search/server/routes Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export const registerInternalFindRoute = (router: GlobalSearchRouter) => {
2929 } ) ,
3030 options : schema . maybe (
3131 schema . object ( {
32- preference : schema . maybe ( schema . string ( ) ) ,
32+ preference : schema . maybe ( schema . string ( { maxLength : 64 } ) ) ,
3333 } )
3434 ) ,
3535 } ) ,
Original file line number Diff line number Diff line change @@ -122,6 +122,35 @@ describe('POST /internal/global_search/find', () => {
122122 ) ;
123123 } ) ;
124124
125+ it ( 'allows requests with max length options.preference string' , async ( ) => {
126+ const longPreference = 'a' . repeat ( 64 ) ; // maxLength is 64
127+
128+ const response = await supertest ( httpSetup . server . listener )
129+ . post ( '/internal/global_search/find' )
130+ . send ( { params : { term : 'search' } , options : { preference : longPreference } } )
131+ . expect ( 200 ) ;
132+
133+ expect ( response . body ) . toEqual ( { } ) ;
134+ } ) ;
135+
136+ it ( 'disallows requests with large options.preference string' , async ( ) => {
137+ const longPreference = 'a' . repeat ( 65 ) ; // maxLength is 64
138+
139+ const response = await supertest ( httpSetup . server . listener )
140+ . post ( '/internal/global_search/find' )
141+ . send ( { params : { term : 'search' } , options : { preference : longPreference } } )
142+ . expect ( 400 ) ;
143+
144+ expect ( response . body ) . toEqual (
145+ expect . objectContaining ( {
146+ error : 'Bad Request' ,
147+ message :
148+ '[request body.options.preference]: value has length [65] but it must have a maximum length of [64].' ,
149+ statusCode : 400 ,
150+ } )
151+ ) ;
152+ } ) ;
153+
125154 it ( 'returns the default error when the observable throws any other error' , async ( ) => {
126155 globalSearchHandlerContext . find . mockReturnValue ( throwError ( 'any-error' ) ) ;
127156
You can’t perform that action at this time.
0 commit comments