Skip to content

Commit 5a4cd4d

Browse files
authored
[Synthetics] Fix params sharing !! (elastic#219675)
## Summary Fix params sharing, added a unit test for the change !!
1 parent 4748d4f commit 5a4cd4d

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

x-pack/solutions/observability/plugins/synthetics/server/synthetics_service/synthetics_service.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ describe('SyntheticsService', () => {
450450
},
451451
});
452452
});
453+
453454
it('returns the space limited params', async () => {
454455
const { service } = getMockedService();
455456
jest.spyOn(service, 'getSyntheticsParams').mockRestore();
@@ -471,6 +472,44 @@ describe('SyntheticsService', () => {
471472
},
472473
});
473474
});
475+
476+
it('returns the params from mixed spaces', async () => {
477+
const { service } = getMockedService();
478+
jest.spyOn(service, 'getSyntheticsParams').mockRestore();
479+
480+
serverMock.encryptedSavedObjects = mockEncryptedSO({
481+
params: [
482+
{
483+
attributes: { key: 'username', value: 'elastic' },
484+
namespaces: ['default'],
485+
},
486+
{
487+
attributes: { key: 'username-shared', value: 'elastic' },
488+
namespaces: ['*'],
489+
},
490+
{
491+
attributes: { key: 'username-test-space', value: 'elastic' },
492+
namespaces: ['test'],
493+
},
494+
],
495+
});
496+
497+
const params = await service.getSyntheticsParams({ spaceId: 'default' });
498+
499+
expect(params).toEqual({
500+
'*': {
501+
'username-shared': 'elastic',
502+
},
503+
default: {
504+
username: 'elastic',
505+
'username-shared': 'elastic',
506+
},
507+
test: {
508+
'username-shared': 'elastic',
509+
'username-test-space': 'elastic',
510+
},
511+
});
512+
});
474513
});
475514

476515
describe('pagination', () => {

x-pack/solutions/observability/plugins/synthetics/server/synthetics_service/synthetics_service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,10 @@ export class SyntheticsService {
618618
if (paramsBySpace[ALL_SPACES_ID]) {
619619
Object.keys(paramsBySpace).forEach((space) => {
620620
if (space !== ALL_SPACES_ID) {
621-
paramsBySpace[space] = Object.assign(paramsBySpace[ALL_SPACES_ID], paramsBySpace[space]);
621+
paramsBySpace[space] = {
622+
...(paramsBySpace[space] ?? {}),
623+
...(paramsBySpace[ALL_SPACES_ID] ?? {}),
624+
};
622625
}
623626
});
624627
if (spaceId) {

0 commit comments

Comments
 (0)