-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix MTLS settings for synthetics service in Kibana (#136267)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
b552e42
commit f9e2ed4
Showing
3 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/synthetics/server/synthetics_service/service_api_client.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { Logger } from '@kbn/core/server'; | ||
import { ServiceAPIClient } from './service_api_client'; | ||
import { UptimeServerSetup } from '../legacy_uptime/lib/adapters'; | ||
import { ServiceConfig } from '../../common/config'; | ||
|
||
jest.mock('@kbn/server-http-tools', () => ({ | ||
SslConfig: jest.fn().mockImplementation(({ certificate, key }) => ({ certificate, key })), | ||
})); | ||
|
||
describe('getHttpsAgent', () => { | ||
it('does not use certs if basic auth is set', () => { | ||
const apiClient = new ServiceAPIClient( | ||
jest.fn() as unknown as Logger, | ||
{ username: 'u', password: 'p' }, | ||
{ isDev: true } as UptimeServerSetup | ||
); | ||
const { options: result } = apiClient.getHttpsAgent('https://localhost:10001'); | ||
expect(result).not.toHaveProperty('cert'); | ||
expect(result).not.toHaveProperty('key'); | ||
}); | ||
|
||
it('rejectUnauthorised is true for requests out of localhost even in dev', () => { | ||
const apiClient = new ServiceAPIClient( | ||
jest.fn() as unknown as Logger, | ||
{ tls: { certificate: 'crt', key: 'k' } } as ServiceConfig, | ||
{ isDev: true } as UptimeServerSetup | ||
); | ||
|
||
const { options: result } = apiClient.getHttpsAgent('https://example.com'); | ||
expect(result).toEqual(expect.objectContaining({ rejectUnauthorized: true })); | ||
}); | ||
|
||
it('use rejectUnauthorised as true out of dev for localhost', () => { | ||
const apiClient = new ServiceAPIClient( | ||
jest.fn() as unknown as Logger, | ||
{ tls: { certificate: 'crt', key: 'k' } } as ServiceConfig, | ||
{ isDev: false } as UptimeServerSetup | ||
); | ||
|
||
const { options: result } = apiClient.getHttpsAgent('https://localhost:10001'); | ||
expect(result).toEqual(expect.objectContaining({ rejectUnauthorized: true })); | ||
}); | ||
|
||
it('uses certs when defined', () => { | ||
const apiClient = new ServiceAPIClient( | ||
jest.fn() as unknown as Logger, | ||
{ tls: { certificate: 'crt', key: 'k' } } as ServiceConfig, | ||
{ isDev: false } as UptimeServerSetup | ||
); | ||
|
||
const { options: result } = apiClient.getHttpsAgent('https://localhost:10001'); | ||
expect(result).toEqual(expect.objectContaining({ cert: 'crt', key: 'k' })); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters