Skip to content

Commit

Permalink
synthetics - fall back to checking verification mode to determine if …
Browse files Browse the repository at this point in the history
…tls is enabled (elastic#117181)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
2 people authored and TinLe committed Nov 20, 2021
1 parent a80e6e6 commit e37c647
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -573,16 +573,43 @@ describe('<SyntheticsPolicyEditExtension />', () => {
});
});

it('shows tls fields when metadata.is_tls_enabled is true', async () => {
const { getByLabelText } = render(<WrappedComponent />);
const verificationMode = getByLabelText('Verification mode') as HTMLInputElement;
const enableTLSConfig = getByLabelText('Enable TLS configuration') as HTMLInputElement;
expect(enableTLSConfig.getAttribute('aria-checked')).toEqual('true');
expect(verificationMode).toBeInTheDocument();
expect(verificationMode.value).toEqual(
`${defaultHTTPConfig[ConfigKeys.TLS_VERIFICATION_MODE]}`
);
});
it.each([[true], [false]])(
'shows tls fields when metadata.is_tls_enabled is or verification mode is truthy true',
async (isTLSEnabledInUIMetadataKey) => {
const currentPolicy = {
...defaultCurrentPolicy,
inputs: [
{
...defaultNewPolicy.inputs[0],
enabled: true,
streams: [
{
...defaultNewPolicy.inputs[0].streams[0],
vars: {
...defaultNewPolicy.inputs[0].streams[0].vars,
__ui: {
type: 'yaml',
value: JSON.stringify({
is_tls_enabled: isTLSEnabledInUIMetadataKey,
}),
},
},
},
],
},
],
};

const { getByLabelText } = render(<WrappedComponent policy={currentPolicy} />);
const verificationMode = getByLabelText('Verification mode') as HTMLInputElement;
const enableTLSConfig = getByLabelText('Enable TLS configuration') as HTMLInputElement;
expect(enableTLSConfig.getAttribute('aria-checked')).toEqual('true');
expect(verificationMode).toBeInTheDocument();
expect(verificationMode.value).toEqual(
`${defaultHTTPConfig[ConfigKeys.TLS_VERIFICATION_MODE]}`
);
}
);

it('handles browser validation', async () => {
const currentPolicy = {
Expand Down Expand Up @@ -1128,6 +1155,7 @@ describe('<SyntheticsPolicyEditExtension />', () => {
expect(getByText(text)).toBeInTheDocument();
}
);

it('hides tls fields when metadata.is_tls_enabled is false', async () => {
const { getByLabelText, queryByLabelText } = render(
<WrappedComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ export const SyntheticsPolicyEditExtensionWrapper = memo<PackagePolicyEditExtens
};

enableTLS =
formattedDefaultConfigForMonitorType[ConfigKeys.METADATA].is_tls_enabled || false;
formattedDefaultConfigForMonitorType[ConfigKeys.METADATA].is_tls_enabled ||
Boolean(vars?.[ConfigKeys.TLS_VERIFICATION_MODE]?.value);
enableZipUrlTLS =
formattedDefaultConfigForMonitorType[ConfigKeys.METADATA].is_zip_url_tls_enabled || false;
formattedDefaultConfigForMonitorType[ConfigKeys.METADATA].is_zip_url_tls_enabled ||
Boolean(vars?.[ConfigKeys.ZIP_URL_TLS_VERIFICATION_MODE]?.value);

const formattedDefaultConfig: Partial<PolicyConfig> = {
[type]: formattedDefaultConfigForMonitorType,
Expand Down

0 comments on commit e37c647

Please sign in to comment.