Skip to content

Commit 04c20d7

Browse files
committed
update backend validation to use prefix and add integration tests
1 parent 97f6b43 commit 04c20d7

File tree

3 files changed

+38
-6
lines changed
  • x-pack/platform

3 files changed

+38
-6
lines changed

x-pack/platform/plugins/shared/streams/server/lib/streams/client.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { State } from './state_management/state';
3434
import { checkAccess, checkAccessBulk } from './stream_crud';
3535
import { StreamsStatusConflictError } from './errors/streams_status_conflict_error';
3636
import type { FeatureClient } from './feature/feature_client';
37-
3837
interface 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

x-pack/platform/plugins/shared/streams_app/public/components/data_management/stream_detail_routing/stream_name_form_row.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const MIN_NAME_LENGTH = 1;
3030
const MAX_NAME_LENGTH = 200;
3131
const PREFIX_MAX_VISIBLE_CHARACTERS = 25;
3232

33+
// TODO: write a unit test for this function
3334
const getHelpText = (prefix: string, value: string, readOnly: boolean): string | undefined => {
3435
if (value.length <= prefix.length && !readOnly) {
3536
return i18n.translate('xpack.streams.streamDetailRouting.emptyNameErrorHelpText', {

x-pack/platform/test/api_integration_deployment_agnostic/apis/streams/basic.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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',

0 commit comments

Comments
 (0)