-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Fleet] Support space_id
in preconfiguration
#183920
Changes from all commits
d9aca86
7fbd009
6735f1d
69009c9
50c5699
f530ab5
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 |
---|---|---|
|
@@ -306,6 +306,7 @@ jest.mock('./app_context', () => ({ | |
getExperimentalFeatures: jest.fn().mockReturnValue({ | ||
agentless: false, | ||
}), | ||
getInternalUserSOClientForSpaceId: jest.fn(), | ||
}, | ||
})); | ||
|
||
|
@@ -1124,6 +1125,69 @@ describe('policy preconfiguration', () => { | |
expect(policies[0].id).toBe('test-id'); | ||
expect(nonFatalErrorsB.length).toBe(0); | ||
}); | ||
|
||
it('should used a namespaced saved objet client if the agent policy space_id is set', async () => { | ||
const TEST_NAMESPACE = 'test'; | ||
const namespacedSOClient = getPutPreconfiguredPackagesMock(); | ||
const soClient = getPutPreconfiguredPackagesMock(); | ||
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; | ||
|
||
jest | ||
.mocked(appContextService) | ||
.getInternalUserSOClientForSpaceId.mockReturnValue(namespacedSOClient); | ||
|
||
await ensurePreconfiguredPackagesAndPolicies( | ||
soClient, | ||
esClient, | ||
[ | ||
{ | ||
name: 'Test policy', | ||
namespace: 'default', | ||
id: 'test-id', | ||
space_id: TEST_NAMESPACE, | ||
is_managed: true, | ||
package_policies: [ | ||
{ | ||
package: { name: 'test_package' }, | ||
name: 'test_package1', | ||
}, | ||
], | ||
}, | ||
] as PreconfiguredAgentPolicy[], | ||
[{ name: 'test_package', version: '3.0.0' }], | ||
mockDefaultOutput, | ||
mockDefaultDownloadService, | ||
DEFAULT_SPACE_ID | ||
); | ||
|
||
jest.mocked(appContextService.getExperimentalFeatures).mockReturnValue({ | ||
agentless: true, | ||
} as any); | ||
|
||
expect(appContextService.getInternalUserSOClientForSpaceId).toBeCalledTimes(1); | ||
expect(appContextService.getInternalUserSOClientForSpaceId).toBeCalledWith(TEST_NAMESPACE); | ||
|
||
expect(mockedPackagePolicyService.create).toBeCalledTimes(1); | ||
expect(mockedPackagePolicyService.create).toBeCalledWith( | ||
namespacedSOClient, // namespaced so client | ||
expect.anything(), // es client | ||
expect.objectContaining({ | ||
name: 'test_package1', | ||
}), | ||
expect.anything() // options | ||
); | ||
|
||
expect(spyAgentPolicyServiceUpdate).toBeCalledTimes(1); | ||
expect(spyAgentPolicyServiceUpdate).toBeCalledWith( | ||
namespacedSOClient, // namespaced so client | ||
expect.anything(), // es client | ||
expect.anything(), // id | ||
expect.objectContaining({ | ||
is_managed: true, | ||
}), | ||
expect.anything() // options | ||
); | ||
}); | ||
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. it would be nice to add another test for changing the when I tested manually, it just created another policy in the second space, rather than "moving" the original policy, because |
||
}); | ||
|
||
describe('with bundled packages', () => { | ||
|
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.