Skip to content

Commit

Permalink
[Fleet] Fix agent policy namespace validation (elastic#200258)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored and jesuswr committed Nov 18, 2024
1 parent f399a5f commit e1ce698
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
>
<EuiFormRow
fullWidth
error={touchedFields.namespace && validation.namespace ? validation.namespace : null}
isInvalid={Boolean(touchedFields.namespace && validation.namespace)}
error={validation.namespace ? validation.namespace : null}
isInvalid={Boolean(validation.namespace)}
isDisabled={disabled}
>
<EuiComboBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server';

import { appContextService } from '../app_context';

import { saveSpaceSettings } from './space_settings';
import { getSpaceSettings, saveSpaceSettings } from './space_settings';

jest.mock('../app_context');

Expand Down Expand Up @@ -102,3 +102,35 @@ describe('saveSpaceSettings', () => {
});
});
});

describe('getSpaceSettings', () => {
function createSavedsClientMock(settingsAttributes?: any) {
const client = savedObjectsClientMock.create();

if (settingsAttributes) {
client.get.mockResolvedValue({
attributes: settingsAttributes,
} as any);
} else {
client.get.mockRejectedValue(
SavedObjectsErrorHelpers.createGenericNotFoundError('Not found')
);
}

jest.mocked(appContextService.getInternalUserSOClientForSpaceId).mockReturnValue(client);

return client;
}
it('should work with managedBy:null', async () => {
createSavedsClientMock({
allowed_namespace_prefixes: ['test'],
managed_by: null,
});
const res = await getSpaceSettings();

expect(res).toEqual({
allowed_namespace_prefixes: ['test'],
managed_by: undefined,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getSpaceSettings(spaceId?: string) {

return {
allowed_namespace_prefixes: settings?.attributes?.allowed_namespace_prefixes ?? [],
managed_by: settings?.attributes?.managed_by,
managed_by: settings?.attributes?.managed_by ?? undefined,
};
}

Expand Down

0 comments on commit e1ce698

Please sign in to comment.