mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Synthetics] Fixes all spaces params usage in monitors (#153826)
Co-authored-by: Dominique Clarke <dominique.clarke@elastic.co>
This commit is contained in:
parent
c9dde2fbb3
commit
78450b0fae
9 changed files with 63 additions and 11 deletions
|
@ -37,7 +37,7 @@ describe('StatusRuleExecutor', () => {
|
|||
getSpaceId: jest.fn().mockReturnValue('test-space'),
|
||||
},
|
||||
},
|
||||
encryptedSavedObjects: mockEncryptedSO,
|
||||
encryptedSavedObjects: mockEncryptedSO(),
|
||||
} as unknown as UptimeServerSetup;
|
||||
|
||||
const syntheticsService = new SyntheticsService(serverMock);
|
||||
|
|
|
@ -53,7 +53,7 @@ describe('syncEditedMonitor', () => {
|
|||
buildPackagePolicyFromPackage: jest.fn().mockReturnValue({}),
|
||||
},
|
||||
},
|
||||
encryptedSavedObjects: mockEncryptedSO,
|
||||
encryptedSavedObjects: mockEncryptedSO(),
|
||||
} as unknown as UptimeServerSetup;
|
||||
|
||||
const editedMonitor = {
|
||||
|
|
|
@ -37,7 +37,7 @@ describe('processMonitors', () => {
|
|||
getSpaceId: jest.fn().mockReturnValue('test-space'),
|
||||
},
|
||||
},
|
||||
encryptedSavedObjects: mockEncryptedSO,
|
||||
encryptedSavedObjects: mockEncryptedSO(),
|
||||
} as unknown as UptimeServerSetup;
|
||||
|
||||
const syntheticsService = new SyntheticsService(serverMock);
|
||||
|
|
|
@ -122,7 +122,7 @@ describe('ProjectMonitorFormatter', () => {
|
|||
getSpaceId: jest.fn().mockReturnValue('test-space'),
|
||||
},
|
||||
},
|
||||
encryptedSavedObjects: mockEncryptedSO,
|
||||
encryptedSavedObjects: mockEncryptedSO(),
|
||||
} as unknown as UptimeServerSetup;
|
||||
|
||||
const syntheticsService = new SyntheticsService(serverMock);
|
||||
|
|
|
@ -116,7 +116,7 @@ describe('ProjectMonitorFormatterLegacy', () => {
|
|||
getSpaceId: jest.fn().mockReturnValue('test-space'),
|
||||
},
|
||||
},
|
||||
encryptedSavedObjects: mockEncryptedSO,
|
||||
encryptedSavedObjects: mockEncryptedSO(),
|
||||
} as unknown as UptimeServerSetup;
|
||||
|
||||
const syntheticsService = new SyntheticsService(serverMock);
|
||||
|
|
|
@ -44,7 +44,7 @@ describe('SyntheticsMonitorClient', () => {
|
|||
manifestUrl: 'http://localhost:8080/api/manifest',
|
||||
},
|
||||
},
|
||||
encryptedSavedObjects: mockEncryptedSO,
|
||||
encryptedSavedObjects: mockEncryptedSO(),
|
||||
} as unknown as UptimeServerSetup;
|
||||
|
||||
const syntheticsService = new SyntheticsService(serverMock);
|
||||
|
@ -181,6 +181,9 @@ describe('SyntheticsMonitorClient', () => {
|
|||
{
|
||||
monitor,
|
||||
configId: id,
|
||||
params: {
|
||||
username: 'elastic',
|
||||
},
|
||||
},
|
||||
]);
|
||||
expect(syntheticsService.deleteConfigs).toHaveBeenCalledTimes(1);
|
||||
|
|
|
@ -38,7 +38,7 @@ describe('SyntheticsService', () => {
|
|||
manifestUrl: 'http://localhost:8080/api/manifest',
|
||||
},
|
||||
},
|
||||
encryptedSavedObjects: mockEncryptedSO,
|
||||
encryptedSavedObjects: mockEncryptedSO(),
|
||||
} as unknown as UptimeServerSetup;
|
||||
|
||||
const getMockedService = (locationsNum: number = 1) => {
|
||||
|
@ -175,4 +175,49 @@ describe('SyntheticsService', () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSyntheticsParams', () => {
|
||||
it('returns the params for all spaces', async () => {
|
||||
const { service } = getMockedService();
|
||||
|
||||
(axios as jest.MockedFunction<typeof axios>).mockResolvedValue({} as AxiosResponse);
|
||||
|
||||
const params = await service.getSyntheticsParams();
|
||||
|
||||
expect(params).toEqual({
|
||||
'*': {
|
||||
username: 'elastic',
|
||||
},
|
||||
});
|
||||
});
|
||||
it('returns the params for specific space', async () => {
|
||||
const { service } = getMockedService();
|
||||
|
||||
const params = await service.getSyntheticsParams({ spaceId: 'default' });
|
||||
|
||||
expect(params).toEqual({
|
||||
'*': {
|
||||
username: 'elastic',
|
||||
},
|
||||
default: {
|
||||
username: 'elastic',
|
||||
},
|
||||
});
|
||||
});
|
||||
it('returns the space limited params', async () => {
|
||||
const { service } = getMockedService();
|
||||
|
||||
serverMock.encryptedSavedObjects = mockEncryptedSO([
|
||||
{ attributes: { key: 'username', value: 'elastic' }, namespaces: ['default'] },
|
||||
]) as any;
|
||||
|
||||
const params = await service.getSyntheticsParams({ spaceId: 'default' });
|
||||
|
||||
expect(params).toEqual({
|
||||
default: {
|
||||
username: 'elastic',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -528,7 +528,7 @@ export class SyntheticsService {
|
|||
if (paramsBySpace[ALL_SPACES_ID]) {
|
||||
Object.keys(paramsBySpace).forEach((space) => {
|
||||
if (space !== ALL_SPACES_ID) {
|
||||
paramsBySpace[space] = Object.assign(paramsBySpace[space], paramsBySpace['*']);
|
||||
paramsBySpace[space] = Object.assign(paramsBySpace[ALL_SPACES_ID], paramsBySpace[space]);
|
||||
}
|
||||
});
|
||||
if (spaceId) {
|
||||
|
|
|
@ -7,16 +7,20 @@
|
|||
|
||||
import { EncryptedSavedObjectsClient } from '@kbn/encrypted-saved-objects-plugin/server';
|
||||
|
||||
export const mockEncryptedSO = {
|
||||
export const mockEncryptedSO = (
|
||||
data: any = [{ attributes: { key: 'username', value: 'elastic' }, namespaces: ['*'] }]
|
||||
) => ({
|
||||
getClient: jest.fn().mockReturnValue({
|
||||
getDecryptedAsInternalUser: jest.fn(),
|
||||
createPointInTimeFinderDecryptedAsInternalUser: jest.fn().mockImplementation(() => ({
|
||||
close: jest.fn(),
|
||||
find: jest.fn().mockReturnValue({
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield { saved_objects: [{ attributes: { key: 'username', value: 'elastic' } }] };
|
||||
yield {
|
||||
saved_objects: data,
|
||||
};
|
||||
},
|
||||
}),
|
||||
})),
|
||||
} as jest.Mocked<EncryptedSavedObjectsClient>),
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue