Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate max number of node connections #196908

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move the max value to common/constant and fix typo
  • Loading branch information
SoniaSanzV committed Oct 21, 2024
commit 9937a151be1cde1673518fd6ea1f7a0a9144d79d
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import { act } from 'react-dom/test-utils';
import { setupEnvironment, RemoteClustersActions } from '../helpers';
import { setup } from './remote_clusters_add.helpers';
import { NON_ALPHA_NUMERIC_CHARS, ACCENTED_CHARS } from './special_characters';
import { MAX_NODE_CONNECTIONS } from '../../../common/constants';

const notInArray = (array: string[]) => (value: string) => array.indexOf(value) < 0;

@@ -277,13 +278,12 @@ describe('Create Remote cluster', () => {
});

describe('node connections', () => {
const maxNodeConnections = 2147483647;
test('should require a valid number of node connections', async () => {
await actions.saveButton.click();

actions.nodeConnectionsInput.setValue(String(maxNodeConnections + 1));
actions.nodeConnectionsInput.setValue(String(MAX_NODE_CONNECTIONS + 1));
expect(actions.getErrorMessages()).toContain(
`This number must be equal or less than ${maxNodeConnections}.`
`This number must be equal or less than ${MAX_NODE_CONNECTIONS}.`
);
});
});
3 changes: 3 additions & 0 deletions x-pack/plugins/remote_clusters/common/constants.ts
Original file line number Diff line number Diff line change
@@ -42,3 +42,6 @@ export const getSecurityModel = (type: string) => {

return type;
};

// Hardcoded limit of maximum node connections allowed
export const MAX_NODE_CONNECTIONS = 2 ** 31 - 1; // 2147483647
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ export const SniffConnection: FunctionComponent<Props> = ({
const { seeds: seedsError, nodeConnections: nodeError } = fieldsErrors;
// Show errors if there is a general form error or local errors.
const areFormErrorsVisible = Boolean(areErrorsVisible && seedsError);
const showLocalSheedErrors = areFormErrorsVisible || localSeedErrors.length !== 0;
const showLocalSeedErrors = areFormErrorsVisible || localSeedErrors.length !== 0;
const errorsInLocalSeeds =
areFormErrorsVisible && seedsError ? localSeedErrors.concat(seedsError) : localSeedErrors;
const formattedSeeds: EuiComboBoxOptionOption[] = seeds.map((seed: string) => ({ label: seed }));
@@ -109,7 +109,7 @@ export const SniffConnection: FunctionComponent<Props> = ({
}}
/>
}
isInvalid={showLocalSheedErrors}
isInvalid={showLocalSeedErrors}
error={errorsInLocalSeeds}
fullWidth
>
@@ -127,7 +127,7 @@ export const SniffConnection: FunctionComponent<Props> = ({
onFieldsChange({ seeds: options.map(({ label }) => label) })
}
onSearchChange={onSeedsInputChange}
isInvalid={showLocalSheedErrors}
isInvalid={showLocalSeedErrors}
fullWidth
data-test-subj="remoteClusterFormSeedsInput"
/>
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@
* 2.0.
*/

import { MAX_NODE_CONNECTIONS, validateNodeConnections } from './validate_node_connections';
import { MAX_NODE_CONNECTIONS } from '../../../../../../common/constants';
import { validateNodeConnections } from './validate_node_connections';

describe('validateNodeConnections', () => {
test('rejects numbers larger than MaxValue', () => {
Original file line number Diff line number Diff line change
@@ -7,8 +7,7 @@

import React from 'react';
import { FormattedMessage } from '@kbn/i18n-react';

export const MAX_NODE_CONNECTIONS = 2147483647;
import { MAX_NODE_CONNECTIONS } from '../../../../../../common/constants';

export function validateNodeConnections(connections?: number | null): null | JSX.Element {
if (connections && connections > MAX_NODE_CONNECTIONS) {