Wizard: handle dos scripts in first boot

Scripts in which lines are terminated by CRLF break the first boot
service, so let's make sure the line termination is correct.
This commit is contained in:
Sanne Raymaekers 2024-11-12 09:52:40 +01:00 committed by Klara Simickova
parent ba9546193e
commit 7b365dcb4d
3 changed files with 38 additions and 2 deletions

View file

@ -73,7 +73,10 @@ const FirstBootStep = () => {
isCopyEnabled
isLanguageLabelVisible
language={language}
onCodeChange={(code) => dispatch(setFirstBootScript(code))}
onCodeChange={(code) => {
// In case the user is on windows
dispatch(setFirstBootScript(code.replace('\r\n', '\n')));
}}
code={selectedScript}
height="35vh"
emptyStateButton={<span data-testid="firstboot_browse">Browse</span>}

View file

@ -9,6 +9,7 @@ import {
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import {
SCRIPT,
SCRIPT_DOS,
SCRIPT_WITHOUT_SHEBANG,
firstBootCreateBlueprintRequest,
firstBootData,
@ -199,6 +200,37 @@ describe('First boot request generated correctly', () => {
expect(receivedRequest).toEqual(expectedRequest);
});
});
test('dos2unix', async () => {
await renderCreateMode();
await selectGuestImageTarget();
await goToOscapStep();
await selectSimplifiedOscapProfile();
await goFromOscapToFirstBoot();
await openCodeEditor();
await uploadFile(SCRIPT_DOS);
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
// request created with both OpenSCAP and first boot customization
const expectedRequest = {
...blueprintRequest,
customizations: {
filesystem: [{ min_size: 10737418240, mountpoint: '/' }],
openscap: {
profile_id: 'xccdf_org.ssgproject.content_profile_standard',
},
files: firstBootData,
// services need to contain both serviced included in the OpenSCAP profile
// and the first boot script
services: { enabled: ['crond', 'emacs-service', FIRST_BOOT_SERVICE] },
},
};
await waitFor(() => {
expect(receivedRequest).toEqual(expectedRequest);
});
});
});
describe('First Boot edit mode', () => {

View file

@ -114,7 +114,8 @@ export const expectedCustomRepositories: CustomRepository[] = [
];
// First Boot
export const SCRIPT = `#!/bin/bash
export const SCRIPT_DOS = `#!/bin/bash\r\nsystemctl enable cockpit.socket`;
export const SCRIPT = `#!/bin/bash
systemctl enable cockpit.socket`;
export const BASE64_SCRIPT = btoa(SCRIPT);
export const SCRIPT_WITHOUT_SHEBANG = `echo "Hello, world!"`;