Skip to content

Commit

Permalink
[Remote clusters] Add support for proxy mode (#59221)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Mar 16, 2020
1 parent dccfa59 commit 77a859d
Show file tree
Hide file tree
Showing 34 changed files with 2,765 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ describe('Create Remote cluster', () => {
expect(find('remoteClusterFormSkipUnavailableFormToggle').props()['aria-checked']).toBe(true);
});

test('should have a toggle to enable "proxy" mode for a remote cluster', () => {
expect(exists('remoteClusterFormConnectionModeToggle')).toBe(true);

// By default it should be set to "false"
expect(find('remoteClusterFormConnectionModeToggle').props()['aria-checked']).toBe(false);

form.toggleEuiSwitch('remoteClusterFormConnectionModeToggle');

expect(find('remoteClusterFormConnectionModeToggle').props()['aria-checked']).toBe(true);
});

test('should display errors and disable the save button when clicking "save" without filling the form', () => {
expect(exists('remoteClusterFormGlobalError')).toBe(false);
expect(find('remoteClusterFormSaveButton').props().disabled).toBe(false);
Expand Down Expand Up @@ -144,5 +155,44 @@ describe('Create Remote cluster', () => {
expect(form.getErrorsMessages()).toContain('A port is required.');
});
});

describe('proxy address', () => {
let actions;
let form;

beforeEach(async () => {
({ form, actions } = setup());

// Enable "proxy" mode
form.toggleEuiSwitch('remoteClusterFormConnectionModeToggle');
});

test('should only allow alpha-numeric characters and "-" (dash) in the proxy address "host" part', () => {
actions.clickSaveForm(); // display form errors

const notInArray = array => value => array.indexOf(value) < 0;

const expectInvalidChar = char => {
form.setInputValue('remoteClusterFormProxyAddressInput', `192.16${char}:3000`);
expect(form.getErrorsMessages()).toContain(
'Address must use host:port format. Example: 127.0.0.1:9400, localhost:9400. Hosts can only consist of letters, numbers, and dashes.'
);
};

[...NON_ALPHA_NUMERIC_CHARS, ...ACCENTED_CHARS]
.filter(notInArray(['-', '_', ':']))
.forEach(expectInvalidChar);
});

test('should require a numeric "port" to be set', () => {
actions.clickSaveForm();

form.setInputValue('remoteClusterFormProxyAddressInput', '192.168.1.1');
expect(form.getErrorsMessages()).toContain('A port is required.');

form.setInputValue('remoteClusterFormProxyAddressInput', '192.168.1.1:abc');
expect(form.getErrorsMessages()).toContain('A port is required.');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import { getRouter } from '../../public/application/services';
import { getRemoteClusterMock } from '../../fixtures/remote_cluster';

import { PROXY_MODE } from '../../common/constants';

jest.mock('ui/new_platform');

const { setup } = pageHelpers.remoteClustersList;
Expand Down Expand Up @@ -84,12 +86,26 @@ describe('<RemoteClusterList />', () => {
const remoteCluster2 = getRemoteClusterMock({
name: `b${getRandomString()}`,
isConnected: false,
connectedNodesCount: 0,
seeds: ['localhost:9500'],
connectedSocketsCount: 0,
proxyAddress: 'localhost:9500',
isConfiguredByNode: true,
mode: PROXY_MODE,
seeds: null,
connectedNodesCount: null,
});
const remoteCluster3 = getRemoteClusterMock({
name: `c${getRandomString()}`,
isConnected: false,
connectedSocketsCount: 0,
proxyAddress: 'localhost:9500',
isConfiguredByNode: false,
mode: PROXY_MODE,
hasDeprecatedProxySetting: true,
seeds: null,
connectedNodesCount: null,
});

const remoteClusters = [remoteCluster1, remoteCluster2];
const remoteClusters = [remoteCluster1, remoteCluster2, remoteCluster3];

beforeEach(async () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse(remoteClusters);
Expand Down Expand Up @@ -118,17 +134,28 @@ describe('<RemoteClusterList />', () => {
[
'', // Empty because the first column is the checkbox to select the row
remoteCluster1.name,
remoteCluster1.seeds.join(', '),
'Connected',
'default',
remoteCluster1.seeds.join(', '),
remoteCluster1.connectedNodesCount.toString(),
'', // Empty because the last column is for the "actions" on the resource
],
[
'',
remoteCluster2.name,
remoteCluster2.seeds.join(', '),
'Not connected',
remoteCluster2.connectedNodesCount.toString(),
PROXY_MODE,
remoteCluster2.proxyAddress,
remoteCluster2.connectedSocketsCount.toString(),
'',
],
[
'',
remoteCluster3.name,
'Not connected',
PROXY_MODE,
remoteCluster2.proxyAddress,
remoteCluster2.connectedSocketsCount.toString(),
'',
],
]);
Expand All @@ -141,6 +168,14 @@ describe('<RemoteClusterList />', () => {
).toBe(1);
});

test('should have a tooltip to indicate that the cluster has a deprecated setting', () => {
const secondRow = rows[2].reactWrapper; // The third cluster has been defined with deprecated setting
expect(
findTestSubject(secondRow, 'remoteClustersTableListClusterWithDeprecatedSettingTooltip')
.length
).toBe(1);
});

describe('bulk delete button', () => {
test('should be visible when a remote cluster is selected', () => {
expect(exists('remoteClusterBulkDeleteButton')).toBe(false);
Expand Down Expand Up @@ -199,8 +234,8 @@ describe('<RemoteClusterList />', () => {
errors: [],
});

// Make sure that we have our 2 remote clusters in the table
expect(rows.length).toBe(2);
// Make sure that we have our 3 remote clusters in the table
expect(rows.length).toBe(3);

actions.selectRemoteClusterAt(0);
actions.clickBulkDeleteButton();
Expand All @@ -211,7 +246,7 @@ describe('<RemoteClusterList />', () => {

({ rows } = table.getMetaData('remoteClusterListTable'));

expect(rows.length).toBe(1);
expect(rows.length).toBe(2);
expect(rows[0].columns[1].value).toEqual(remoteCluster2.name);
});
});
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/remote_clusters/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ export const PLUGIN = {
};

export const API_BASE_PATH = '/api/remote_clusters';

export const SNIFF_MODE = 'sniff';
export const PROXY_MODE = 'proxy';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { deserializeCluster, serializeCluster } from './cluster_serialization';
describe('cluster_serialization', () => {
describe('deserializeCluster()', () => {
it('should throw an error for invalid arguments', () => {
// @ts-ignore
expect(() => deserializeCluster('foo', 'bar')).toThrowError();
});

Expand Down Expand Up @@ -60,6 +61,39 @@ describe('cluster_serialization', () => {
});
});

it('should deserialize a cluster that contains a deprecated proxy address', () => {
expect(
deserializeCluster(
'test_cluster',
{
seeds: ['localhost:9300'],
connected: true,
num_nodes_connected: 1,
max_connections_per_cluster: 3,
initial_connect_timeout: '30s',
skip_unavailable: false,
transport: {
ping_schedule: '-1',
compress: false,
},
},
'localhost:9300'
)
).toEqual({
name: 'test_cluster',
proxyAddress: 'localhost:9300',
mode: 'proxy',
hasDeprecatedProxySetting: true,
isConnected: true,
connectedNodesCount: 1,
maxConnectionsPerCluster: 3,
initialConnectTimeout: '30s',
skipUnavailable: false,
transportPingSchedule: '-1',
transportCompress: false,
});
});

it('should deserialize a cluster object with arbitrary missing properties', () => {
expect(
deserializeCluster('test_cluster', {
Expand All @@ -84,6 +118,7 @@ describe('cluster_serialization', () => {

describe('serializeCluster()', () => {
it('should throw an error for invalid arguments', () => {
// @ts-ignore
expect(() => serializeCluster('foo')).toThrowError();
});

Expand All @@ -105,8 +140,13 @@ describe('cluster_serialization', () => {
cluster: {
remote: {
test_cluster: {
mode: null,
node_connections: null,
proxy_address: null,
proxy_socket_connections: null,
seeds: ['localhost:9300'],
skip_unavailable: false,
server_name: null,
},
},
},
Expand All @@ -125,8 +165,13 @@ describe('cluster_serialization', () => {
cluster: {
remote: {
test_cluster: {
mode: null,
node_connections: null,
proxy_address: null,
proxy_socket_connections: null,
seeds: ['localhost:9300'],
skip_unavailable: null,
server_name: null,
},
},
},
Expand Down

0 comments on commit 77a859d

Please sign in to comment.