-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Reporting] Internally correct the hostname to "localhost" if "server.host" is "0.0.0.0" #117022
Changes from 2 commits
42a1296
3b4cd51
987abef
86fd8ce
7af5772
6480620
3d91c33
5ca5a4d
82053bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,27 +5,29 @@ | |||||
* 2.0. | ||||||
*/ | ||||||
|
||||||
import * as Rx from 'rxjs'; | ||||||
import { CoreSetup, PluginInitializerContext } from 'src/core/server'; | ||||||
import { coreMock } from 'src/core/server/mocks'; | ||||||
import { LevelLogger } from '../lib'; | ||||||
import { createMockConfigSchema } from '../test_helpers'; | ||||||
import { LevelLogger } from '../lib/level_logger'; | ||||||
import { createMockConfigSchema, createMockLevelLogger } from '../test_helpers'; | ||||||
import { ReportingConfigType } from './'; | ||||||
import { createConfig$ } from './create_config'; | ||||||
|
||||||
const createMockConfig = ( | ||||||
mockInitContext: PluginInitializerContext<unknown> | ||||||
): Rx.Observable<ReportingConfigType> => mockInitContext.config.create(); | ||||||
|
||||||
describe('Reporting server createConfig$', () => { | ||||||
let mockCoreSetup: CoreSetup; | ||||||
let mockInitContext: PluginInitializerContext; | ||||||
let mockLogger: LevelLogger; | ||||||
let mockLogger: jest.Mocked<LevelLogger>; | ||||||
|
||||||
beforeEach(() => { | ||||||
mockCoreSetup = coreMock.createSetup(); | ||||||
mockInitContext = coreMock.createPluginInitializerContext( | ||||||
createMockConfigSchema({ kibanaServer: {} }) | ||||||
); | ||||||
mockLogger = { | ||||||
warn: jest.fn(), | ||||||
debug: jest.fn(), | ||||||
clone: jest.fn().mockImplementation(() => mockLogger), | ||||||
} as unknown as LevelLogger; | ||||||
mockLogger = createMockLevelLogger(); | ||||||
}); | ||||||
|
||||||
afterEach(() => { | ||||||
|
@@ -37,19 +39,12 @@ describe('Reporting server createConfig$', () => { | |||||
...createMockConfigSchema({ kibanaServer: {} }), | ||||||
encryptionKey: undefined, | ||||||
}); | ||||||
const mockConfig$: any = mockInitContext.config.create(); | ||||||
const mockConfig$ = createMockConfig(mockInitContext); | ||||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise(); | ||||||
|
||||||
expect(result.encryptionKey).toMatch(/\S{32,}/); // random 32 characters | ||||||
expect(result.kibanaServer).toMatchInlineSnapshot(` | ||||||
Object { | ||||||
"hostname": "localhost", | ||||||
"port": 80, | ||||||
"protocol": "http", | ||||||
} | ||||||
`); | ||||||
expect((mockLogger.warn as any).mock.calls.length).toBe(1); | ||||||
expect((mockLogger.warn as any).mock.calls[0]).toMatchObject([ | ||||||
expect(mockLogger.warn.mock.calls.length).toBe(1); | ||||||
expect(mockLogger.warn.mock.calls[0]).toMatchObject([ | ||||||
'Generating a random key for xpack.reporting.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.reporting.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.', | ||||||
]); | ||||||
}); | ||||||
|
@@ -60,10 +55,10 @@ describe('Reporting server createConfig$', () => { | |||||
encryptionKey: 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii', | ||||||
}) | ||||||
); | ||||||
const mockConfig$: any = mockInitContext.config.create(); | ||||||
const mockConfig$ = createMockConfig(mockInitContext); | ||||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise(); | ||||||
expect(result.encryptionKey).toMatch('iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii'); | ||||||
expect((mockLogger.warn as any).mock.calls.length).toBe(0); | ||||||
expect(mockLogger.warn.mock.calls.length).toBe(0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
|
||||||
it('uses the user-provided encryption key, reporting kibanaServer settings to override server info', async () => { | ||||||
|
@@ -77,7 +72,7 @@ describe('Reporting server createConfig$', () => { | |||||
}, | ||||||
}) | ||||||
); | ||||||
const mockConfig$: any = mockInitContext.config.create(); | ||||||
const mockConfig$ = createMockConfig(mockInitContext); | ||||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise(); | ||||||
|
||||||
expect(result).toMatchInlineSnapshot(` | ||||||
|
@@ -108,7 +103,25 @@ describe('Reporting server createConfig$', () => { | |||||
}, | ||||||
} | ||||||
`); | ||||||
expect((mockLogger.warn as any).mock.calls.length).toBe(0); | ||||||
expect(mockLogger.warn.mock.calls.length).toBe(0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
|
||||||
it('show warning when kibanaServer.hostName === "0.0.0.0"', async () => { | ||||||
tsullivan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
mockInitContext = coreMock.createPluginInitializerContext({ | ||||||
encryptionKey: 'aaaaaaaaaaaaabbbbbbbbbbbbaaaaaaaaa', | ||||||
kibanaServer: { hostname: '0.0.0.0', port: 5601 }, | ||||||
capture: { browser: { chromium: {} } }, | ||||||
}); | ||||||
const mockConfig$ = createMockConfig(mockInitContext); | ||||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise(); | ||||||
|
||||||
expect(result.kibanaServer).toMatchInlineSnapshot(` | ||||||
Object { | ||||||
"hostname": "localhost", | ||||||
"port": 5601, | ||||||
"protocol": "http", | ||||||
} | ||||||
`); | ||||||
}); | ||||||
|
||||||
it('uses user-provided disableSandbox: false', async () => { | ||||||
|
@@ -118,11 +131,11 @@ describe('Reporting server createConfig$', () => { | |||||
capture: { browser: { chromium: { disableSandbox: false } } }, | ||||||
}) | ||||||
); | ||||||
const mockConfig$: any = mockInitContext.config.create(); | ||||||
const mockConfig$ = createMockConfig(mockInitContext); | ||||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise(); | ||||||
|
||||||
expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: false }); | ||||||
expect((mockLogger.warn as any).mock.calls.length).toBe(0); | ||||||
expect(mockLogger.warn.mock.calls.length).toBe(0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
|
||||||
it('uses user-provided disableSandbox: true', async () => { | ||||||
|
@@ -132,11 +145,11 @@ describe('Reporting server createConfig$', () => { | |||||
capture: { browser: { chromium: { disableSandbox: true } } }, | ||||||
}) | ||||||
); | ||||||
const mockConfig$: any = mockInitContext.config.create(); | ||||||
const mockConfig$ = createMockConfig(mockInitContext); | ||||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise(); | ||||||
|
||||||
expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: true }); | ||||||
expect((mockLogger.warn as any).mock.calls.length).toBe(0); | ||||||
expect(mockLogger.warn.mock.calls.length).toBe(0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
|
||||||
it('provides a default for disableSandbox', async () => { | ||||||
|
@@ -145,10 +158,10 @@ describe('Reporting server createConfig$', () => { | |||||
encryptionKey: '888888888888888888888888888888888', | ||||||
}) | ||||||
); | ||||||
const mockConfig$: any = mockInitContext.config.create(); | ||||||
const mockConfig$ = createMockConfig(mockInitContext); | ||||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise(); | ||||||
|
||||||
expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: expect.any(Boolean) }); | ||||||
expect((mockLogger.warn as any).mock.calls.length).toBe(0); | ||||||
expect(mockLogger.warn.mock.calls.length).toBe(0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that the change was about removing the
any
. Since I have more relevant feedback below, maybe we can commit the following to prettify the code even more.