Skip to content
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

Wizard: Add firewall to Review step (HMS-5357) #2769

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Components/CreateImageWizard/steps/Review/ReviewStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
LocaleList,
HostnameList,
KernelList,
FirewallList,
} from './ReviewStepTextLists';

import isRhel from '../../../../../src/Utilities/isRhel';
Expand All @@ -52,6 +53,7 @@ import {
selectKeyboard,
selectTimezone,
selectNtpServers,
selectFirewall,
} from '../../../../store/wizardSlice';
import { useFlag } from '../../../../Utilities/useGetEnvironment';

Expand All @@ -71,6 +73,7 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
const keyboard = useAppSelector(selectKeyboard);
const timezone = useAppSelector(selectTimezone);
const ntpServers = useAppSelector(selectNtpServers);
const firewall = useAppSelector(selectFirewall);

const [isExpandedImageOutput, setIsExpandedImageOutput] = useState(true);
const [isExpandedTargetEnvs, setIsExpandedTargetEnvs] = useState(true);
Expand All @@ -85,13 +88,15 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
const [isExpandedLocale, setIsExpandedLocale] = useState(true);
const [isExpandedHostname, setIsExpandedHostname] = useState(true);
const [isExpandedKernel, setIsExpandedKernel] = useState(true);
const [isExpandedFirewall, setIsExpandedFirewall] = useState(true);
const [isExpandableFirstBoot, setIsExpandedFirstBoot] = useState(true);
const [isExpandedUsers, setIsExpandedUsers] = useState(true);

const isTimezoneEnabled = useFlag('image-builder.timezone.enabled');
const isLocaleEnabled = useFlag('image-builder.locale.enabled');
const isHostnameEnabled = useFlag('image-builder.hostname.enabled');
const isKernelEnabled = useFlag('image-builder.kernel.enabled');
const isFirewallEnabled = useFlag('image-builder.firewall.enabled');

const onToggleImageOutput = (isExpandedImageOutput: boolean) =>
setIsExpandedImageOutput(isExpandedImageOutput);
Expand All @@ -117,6 +122,8 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
setIsExpandedHostname(isExpandedHostname);
const onToggleKernel = (isExpandedKernel: boolean) =>
setIsExpandedKernel(isExpandedKernel);
const onToggleFirewall = (isExpandedFirewall: boolean) =>
setIsExpandedFirewall(isExpandedFirewall);
const onToggleFirstBoot = (isExpandableFirstBoot: boolean) =>
setIsExpandedFirstBoot(isExpandableFirstBoot);
const onToggleUsers = (isExpandedUsers: boolean) =>
Expand Down Expand Up @@ -420,6 +427,26 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
<KernelList />
</ExpandableSection>
)}
{isFirewallEnabled &&
(firewall.ports.length > 0 ||
firewall.services.disabled.length > 0 ||
firewall.services.enabled.length > 0) && (
<ExpandableSection
toggleContent={composeExpandable(
'Firewall',
'revisit-firewall',
'wizard-firewall'
)}
onToggle={(_event, isExpandedFirewall) =>
onToggleFirewall(isExpandedFirewall)
}
isExpanded={isExpandedFirewall}
isIndented
data-testid="firewall-expandable"
>
<FirewallList />
</ExpandableSection>
)}
{isFirstBootEnabled && (
<ExpandableSection
toggleContent={composeExpandable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
selectUserPasswordByIndex,
selectUserSshKeyByIndex,
selectKernel,
selectFirewall,
} from '../../../../store/wizardSlice';
import { toMonthAndYear, yyyyMMddFormat } from '../../../../Utilities/time';
import {
Expand Down Expand Up @@ -913,6 +914,60 @@ export const KernelList = () => {
);
};

export const FirewallList = () => {
const firewall = useAppSelector(selectFirewall);

return (
<TextContent>
<TextList component={TextListVariants.dl}>
<TextListItem
component={TextListItemVariants.dt}
className="pf-v5-u-min-width"
>
Ports
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
<CodeBlock>
<CodeBlockCode>
{firewall.ports ? firewall.ports.join(' ') : 'None'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this was the intention. 🤔

Suggested change
{firewall.ports ? firewall.ports.join(' ') : 'None'}
{firewall.ports.length ? firewall.ports.join(' ') : 'None'}

</CodeBlockCode>
</CodeBlock>
</TextListItem>
<TextListItem
component={TextListItemVariants.dt}
className="pf-v5-u-min-width"
>
Disabled services
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
<CodeBlock>
<CodeBlockCode>
{firewall.services.disabled.length > 0
? firewall.services.disabled.join(' ')
: 'None'}
</CodeBlockCode>
</CodeBlock>
</TextListItem>
<TextListItem
component={TextListItemVariants.dt}
className="pf-v5-u-min-width"
>
Enabled services
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
<CodeBlock>
<CodeBlockCode>
{firewall.services.enabled.length > 0
? firewall.services.enabled.join(' ')
: 'None'}
</CodeBlockCode>
</CodeBlock>
</TextListItem>
</TextList>
</TextContent>
);
};

export const FirstBootList = () => {
const isFirstbootEnabled = !!useAppSelector(selectFirstBootScript);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Router as RemixRouter } from '@remix-run/router';
import { screen, waitFor } from '@testing-library/react';
import { screen, waitFor, within } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';

import { CREATE_BLUEPRINT } from '../../../../../constants';
Expand Down Expand Up @@ -67,6 +67,15 @@ const addDisabledFirewallService = async (service: string) => {
await waitFor(() => user.type(disabledServiceInput, service.concat(' ')));
};

const clickRevisitButton = async () => {
const user = userEvent.setup();
const expandable = await screen.findByTestId('firewall-expandable');
const revisitButton = await within(expandable).findByTestId(
'revisit-firewall'
);
await waitFor(() => user.click(revisitButton));
};

describe('Step Firewall', () => {
beforeEach(() => {
vi.clearAllMocks();
Expand Down Expand Up @@ -119,6 +128,15 @@ describe('Step Firewall', () => {
await addPort('wrong--service');
await screen.findByText('Invalid format.');
});

test('revisit step button on Review works', async () => {
await renderCreateMode();
await goToFirewallStep();
await addPort('22:tcp');
await goToReviewStep();
await clickRevisitButton();
await screen.findByRole('heading', { name: /Firewall/ });
});
});

describe('Firewall request generated correctly', () => {
Expand Down Expand Up @@ -205,5 +223,4 @@ describe('Firewall request generated correctly', () => {
});
});

// TO DO Step Firewall -> revisit step button on Review works
// TO DO Firewall edit mode
Loading