Skip to content

Commit

Permalink
ensure that proxy url is not overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke committed May 12, 2021
1 parent bc2b846 commit 0f7d1cb
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 10 deletions.
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

0 comments on commit 0f7d1cb

Please sign in to comment.