Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ describe('Create Remote cluster', () => {
});

describe('seeds', () => {
test('should only allow alpha-numeric characters and "-" (dash) in the node "host" part', async () => {
test('should only allow hostname, ipv4 and ipv6 format in the node "host" part', async () => {
await actions.formStep.button.click(); // display form errors

const expectInvalidChar = (char: string) => {
actions.formStep.seedsInput.setValue(`192.16${char}:3000`);
expect(actions.getErrorMessages()).toContain(
`Seed node must use host:port format. Example: 127.0.0.1:9400, localhost:9400. Hosts can only consist of letters, numbers, and dashes.`
`Seed node must use host:port format. Example: 127.0.0.1:9400, [::1]:9400 or localhost:9400. Hosts can only consist of letters, numbers, and dashes.`
);
};

Expand Down Expand Up @@ -289,7 +289,7 @@ describe('Create Remote cluster', () => {
const expectInvalidChar = (char: string) => {
actions.formStep.proxyAddressInput.setValue(`192.16${char}:3000`);
expect(actions.getErrorMessages()).toContain(
'Address must use host:port format. Example: 127.0.0.1:9400, localhost:9400. Hosts can only consist of letters, numbers, and dashes.'
'Address must use host:port format. Example: 127.0.0.1:9400, [::1]:9400 or localhost:9400. Hosts can only consist of letters, numbers, and dashes.'
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,41 +135,52 @@ describe('cluster_serialization', () => {
});
});

it('should deserialize a cluster that contains a deprecated proxy address and is in cloud', () => {
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,
it.each([
{ title: '(hostname)', address: 'localhost:3000', host: 'localhost' },
{ title: '(IPv4)', address: '123.1.2.142:3000', host: '123.1.2.142' },
{
title: '(IPv6)',
address: '[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:3000',
host: '[2001:0db8:85a3:0000:0000:8a2e:0370:7334]',
},
])(
'should deserialize a cluster that contains a deprecated proxy address and is in cloud $title',
({ address, host }) => {
expect(
deserializeCluster(
'test_cluster',
{
seeds: [address],
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',
true
)
).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,
serverName: 'localhost',
securityModel: SECURITY_MODEL.CERTIFICATE,
});
});
address,
true
)
).toEqual({
name: 'test_cluster',
proxyAddress: address,
mode: 'proxy',
hasDeprecatedProxySetting: true,
isConnected: true,
connectedNodesCount: 1,
maxConnectionsPerCluster: 3,
initialConnectTimeout: '30s',
skipUnavailable: false,
transportPingSchedule: '-1',
transportCompress: false,
serverName: host,
securityModel: SECURITY_MODEL.CERTIFICATE,
});
}
);

it('should deserialize a cluster object with arbitrary missing properties', () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { extractHostAndPort } from './validate_address';
import { PROXY_MODE, SNIFF_MODE, SECURITY_MODEL } from '../constants';

// Values returned from ES GET /_remote/info
Expand Down Expand Up @@ -143,19 +144,21 @@ export function deserializeCluster(
};
}

const deprecatedProxyHost = deprecatedProxyAddress
? extractHostAndPort(deprecatedProxyAddress)?.host
: undefined;

// If a user has a remote cluster with the deprecated proxy setting,
// we transform the data to support the new implementation and also flag the deprecation
if (deprecatedProxyAddress) {
// Cloud-specific logic: Create default server name, since field doesn't exist in deprecated implementation
const defaultServerName = deprecatedProxyAddress.split(':')[0];

if (deprecatedProxyAddress && deprecatedProxyHost) {
deserializedClusterObject = {
...deserializedClusterObject,
proxyAddress: deprecatedProxyAddress,
seeds: undefined,
hasDeprecatedProxySetting: true,
mode: PROXY_MODE,
serverName: isCloudEnabled ? defaultServerName : undefined,
// Cloud-specific logic: Create default server name, since this field doesn't exist in deprecated implementation
serverName: isCloudEnabled ? deprecatedProxyHost : undefined,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export type {
ClusterPayloadEs,
} from './cluster_serialization';
export { deserializeCluster, serializeCluster } from './cluster_serialization';
export { extractHostAndPort, isAddressValid, isPortValid } from './validate_address';
Loading