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

[7.13] [Uptime] [Synthetics Integration] ensure that proxy url is not overwritten (#99944) #100077

Merged
merged 1 commit into from
May 13, 2021
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 @@ -9,7 +9,7 @@ import React, { memo, useContext, useEffect } from 'react';
import useDebounce from 'react-use/lib/useDebounce';
import { PackagePolicyCreateExtensionComponentProps } from '../../../../fleet/public';
import { useTrackPageview } from '../../../../observability/public';
import { Config, ConfigKeys } from './types';
import { Config, ConfigKeys, DataStream } from './types';
import {
SimpleFieldsContext,
HTTPAdvancedFieldsContext,
Expand Down Expand Up @@ -63,6 +63,11 @@ export const SyntheticsPolicyCreateExtension = memo<PackagePolicyCreateExtension
...httpAdvancedFields,
...tcpAdvancedFields,
...tlsFields,
// ensure proxyUrl is not overwritten
[ConfigKeys.PROXY_URL]:
simpleFields[ConfigKeys.MONITOR_TYPE] === DataStream.HTTP
? httpAdvancedFields[ConfigKeys.PROXY_URL]
: tcpAdvancedFields[ConfigKeys.PROXY_URL],
}));
},
250,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const defaultNewPolicy: NewPackagePolicy = {
type: 'text',
},
timeout: {
value: 1600,
type: 'integer',
value: '16s',
type: 'text',
},
max_redirects: {
value: 0,
Expand Down Expand Up @@ -173,7 +173,7 @@ const defaultNewPolicy: NewPackagePolicy = {
type: 'text',
},
timeout: {
type: 'integer',
type: 'text',
},
max_redirects: {
type: 'integer',
Expand Down Expand Up @@ -246,7 +246,7 @@ const defaultNewPolicy: NewPackagePolicy = {
type: 'text',
},
timeout: {
type: 'integer',
type: 'text',
},
max_redirects: {
type: 'integer',
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('<SyntheticsPolicyCreateExtension />', () => {
});
});

it('handles updating each field', async () => {
it('handles updating fields', async () => {
const { getByLabelText } = render(<WrappedComponent />);
const url = getByLabelText('URL') as HTMLInputElement;
const proxyUrl = getByLabelText('Proxy URL') as HTMLInputElement;
Expand All @@ -336,6 +336,54 @@ describe('<SyntheticsPolicyCreateExtension />', () => {
expect(apmServiceName.value).toEqual('APM Service');
expect(maxRedirects.value).toEqual('2');
expect(timeout.value).toEqual('3');

await waitFor(() => {
expect(onChange).toBeCalledWith({
isValid: true,
updatedPolicy: {
...defaultNewPolicy,
inputs: [
{
...defaultNewPolicy.inputs[0],
streams: [
{
...defaultNewPolicy.inputs[0].streams[0],
vars: {
...defaultNewPolicy.inputs[0].streams[0].vars,
urls: {
value: 'http://elastic.co',
type: 'text',
},
proxy_url: {
value: 'http://proxy.co',
type: 'text',
},
schedule: {
value: '"@every 1m"',
type: 'text',
},
'service.name': {
value: 'APM Service',
type: 'text',
},
max_redirects: {
value: '2',
type: 'integer',
},
timeout: {
value: '3s',
type: 'text',
},
},
},
],
},
defaultNewPolicy.inputs[1],
defaultNewPolicy.inputs[2],
],
},
});
});
});

it('handles calling onChange', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TCPAdvancedFieldsContext,
TLSFieldsContext,
} from './contexts';
import { Config, ConfigKeys } from './types';
import { Config, ConfigKeys, DataStream } from './types';
import { CustomFields } from './custom_fields';
import { useUpdatePolicy } from './use_update_policy';
import { validate } from './validation';
Expand Down Expand Up @@ -48,6 +48,11 @@ export const SyntheticsPolicyEditExtension = memo<SyntheticsPolicyEditExtensionP
...httpAdvancedFields,
...tcpAdvancedFields,
...tlsFields,
// ensure proxyUrl is not overwritten
[ConfigKeys.PROXY_URL]:
simpleFields[ConfigKeys.MONITOR_TYPE] === DataStream.HTTP
? httpAdvancedFields[ConfigKeys.PROXY_URL]
: tcpAdvancedFields[ConfigKeys.PROXY_URL],
}));
},
250,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const defaultNewPolicy: NewPackagePolicy = {
type: 'text',
},
timeout: {
type: 'integer',
type: 'text',
},
max_redirects: {
type: 'integer',
Expand Down Expand Up @@ -247,7 +247,7 @@ const defaultNewPolicy: NewPackagePolicy = {
type: 'text',
},
timeout: {
type: 'integer',
type: 'text',
},
max_redirects: {
type: 'integer',
Expand Down Expand Up @@ -339,7 +339,7 @@ describe('<SyntheticsPolicyEditExtension />', () => {
expect(queryByLabelText('Monitor type')).not.toBeInTheDocument();
});

it('handles updating each field', async () => {
it('handles updating fields', async () => {
const { getByLabelText } = render(<WrappedComponent />);
const url = getByLabelText('URL') as HTMLInputElement;
const proxyUrl = getByLabelText('Proxy URL') as HTMLInputElement;
Expand All @@ -364,6 +364,54 @@ describe('<SyntheticsPolicyEditExtension />', () => {
expect(apmServiceName.value).toEqual('APM Service');
expect(maxRedirects.value).toEqual('2');
expect(timeout.value).toEqual('3');

await waitFor(() => {
expect(onChange).toBeCalledWith({
isValid: true,
updatedPolicy: {
...defaultNewPolicy,
inputs: [
{
...defaultNewPolicy.inputs[0],
streams: [
{
...defaultNewPolicy.inputs[0].streams[0],
vars: {
...defaultNewPolicy.inputs[0].streams[0].vars,
urls: {
value: 'http://elastic.co',
type: 'text',
},
proxy_url: {
value: 'http://proxy.co',
type: 'text',
},
schedule: {
value: '"@every 1m"',
type: 'text',
},
'service.name': {
value: 'APM Service',
type: 'text',
},
max_redirects: {
value: '2',
type: 'integer',
},
timeout: {
value: '3s',
type: 'text',
},
},
},
],
},
defaultNewPolicy.inputs[1],
defaultNewPolicy.inputs[2],
],
},
});
});
});

it('handles calling onChange', async () => {
Expand Down