[Fleet] Fix migrating enrollment api keys for space awareness (#207847)

This commit is contained in:
Nicolas Chaulet 2025-01-22 11:24:51 -05:00 committed by GitHub
parent 59e81ee2be
commit 0d32932f6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View file

@ -119,7 +119,10 @@ export async function getEnrollmentAPIKey(
if (spaceId) {
if (spaceId === DEFAULT_SPACE_ID) {
if (body._source?.namespaces && !body._source?.namespaces.includes(DEFAULT_SPACE_ID)) {
if (
(body._source?.namespaces?.length ?? 0) > 0 &&
!body._source?.namespaces?.includes(DEFAULT_SPACE_ID)
) {
throw new EnrollmentKeyNotFoundError(`Enrollment api key ${id} not found in namespace`);
}
} else if (!body._source?.namespaces?.includes(spaceId)) {

View file

@ -517,7 +517,8 @@ export class SpaceTestApiClient {
.post(`${this.getBaseUrl(spaceId)}/internal/fleet/enable_space_awareness`)
.auth(this.auth.username, this.auth.password)
.set('kbn-xsrf', 'xxxx')
.set('elastic-api-version', '1');
.set('elastic-api-version', '1')
.expect(200);
return res;
}

View file

@ -123,6 +123,16 @@ export default function (providerContext: FtrProviderContext) {
expect(policiesTestSpaceIds.length).to.eql(0);
});
it('enrollment api keys should be available', async () => {
const defaultSpaceEnrollmentApiKeys = await apiClient.getEnrollmentApiKeys();
expect(defaultSpaceEnrollmentApiKeys.items.length).to.eql(3);
await apiClient.getEnrollmentApiKeys(defaultSpaceEnrollmentApiKeys.items[0].id);
const testSpaceEnrollmentApiKeys = await apiClient.getEnrollmentApiKeys(TEST_SPACE_1);
expect(testSpaceEnrollmentApiKeys.items.length).to.eql(0);
});
it('package policies should be migrated to the default space', async () => {
const policiesDefaultSpaceIds = (await apiClient.getPackagePolicies()).items
.map(({ id }) => id)