File tree Expand file tree Collapse file tree 3 files changed +38
-6
lines changed
streams_app/public/components/data_management/stream_detail_routing
streams/server/lib/streams
test/api_integration_deployment_agnostic/apis/streams Expand file tree Collapse file tree 3 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ import { State } from './state_management/state';
3434import { checkAccess , checkAccessBulk } from './stream_crud' ;
3535import { StreamsStatusConflictError } from './errors/streams_status_conflict_error' ;
3636import type { FeatureClient } from './feature/feature_client' ;
37-
3837interface AcknowledgeResponse < TResult extends Result > {
3938 acknowledged : true ;
4039 result : TResult ;
@@ -324,13 +323,11 @@ export class StreamsClient {
324323 throw new StatusError ( `Child stream ${ name } already exists` , 409 ) ;
325324 }
326325
327- // TODO - These constants need to be shared between both plugins so I don't have to duplicate them
328- // TODO: need to know prefix to do min check properly
329- logger . info ( `parent: ${ parent } , \n name: ${ name } ` ) ;
330- const MIN_NAME_LENGTH = 6 ; // 'logs.' is already included which is 5 characters, so user must enter at least one more.
326+ const prefix = parent + '.' ;
327+ // TODO - constants need to be shared between both plugins so we don't have to duplicate them
331328 const MAX_NAME_LENGTH = 200 ;
332329
333- if ( name . length < MIN_NAME_LENGTH ) {
330+ if ( name . length <= prefix . length ) {
334331 throw new StatusError ( 'Stream name must not be empty.' , 400 ) ;
335332 }
336333
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ const MIN_NAME_LENGTH = 1;
3030const MAX_NAME_LENGTH = 200 ;
3131const PREFIX_MAX_VISIBLE_CHARACTERS = 25 ;
3232
33+ // TODO: write a unit test for this function
3334const getHelpText = ( prefix : string , value : string , readOnly : boolean ) : string | undefined => {
3435 if ( value . length <= prefix . length && ! readOnly ) {
3536 return i18n . translate ( 'xpack.streams.streamDetailRouting.emptyNameErrorHelpText' , {
Original file line number Diff line number Diff line change @@ -246,6 +246,40 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
246246 expect ( response ) . to . have . property ( 'message' , 'Child stream logs.nginx already exists' ) ;
247247 } ) ;
248248
249+ it ( 'fails to fork logs with empty stream name' , async ( ) => {
250+ const body = {
251+ stream : {
252+ name : 'logs.' , // empty child stream name
253+ } ,
254+ where : {
255+ field : 'log.logger' ,
256+ eq : 'nginx' ,
257+ } ,
258+ status,
259+ } ;
260+ const response = await forkStream ( apiClient , 'logs' , body , 400 ) ;
261+ expect ( response ) . to . have . property ( 'message' , 'Stream name must not be empty.' ) ;
262+ } ) ;
263+
264+ it ( 'fails to fork logs with stream name that is over the 200 character limit' , async ( ) => {
265+ const body = {
266+ stream : {
267+ // child stream is 201 chars
268+ name : 'logs.xwdaqmsegtkamcrofcfcomnlkkkrkqtlkbqizvjvtrbwereqygqaaxmodzccqipzpwymyowrtvljtxevczoohrbpgijilsdptszgssmrkpwhvkukkgiqhvmcuzygmolyyadbxwngbkqjkretmzhgntkjkhrmltgyurufizwlelvmaqtngwhwqhxpfsuxiivxspvtwfcem' ,
269+ } ,
270+ where : {
271+ field : 'log.logger' ,
272+ eq : 'nginx' ,
273+ } ,
274+ status,
275+ } ;
276+ const response = await forkStream ( apiClient , 'logs' , body , 400 ) ;
277+ expect ( response ) . to . have . property (
278+ 'message' ,
279+ 'Stream name cannot be longer than 200 characters.'
280+ ) ;
281+ } ) ;
282+
249283 it ( 'Index an Nginx access log message, should goto logs.nginx' , async ( ) => {
250284 const doc = {
251285 '@timestamp' : '2024-01-01T00:00:10.000Z' ,
You can’t perform that action at this time.
0 commit comments