-
Notifications
You must be signed in to change notification settings - Fork 75
Wizard: make users optional for image mode builds (HMS-11164) #4739
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
Closed
lucasgarfield
wants to merge
1
commit into
lucas/cockpit/5-container-installer
from
lucas/cockpit/6-optional-users
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/Components/CreateImageWizard/steps/Review/components/NoUsersAlert.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { Alert, Content } from '@patternfly/react-core'; | ||
|
|
||
| import { useAppSelector } from '@/store/hooks'; | ||
| import { | ||
| selectImageTypes, | ||
| selectIsImageMode, | ||
| selectUsers, | ||
| type SupportedImageTypes, | ||
| } from '@/store/slices/wizard'; | ||
|
|
||
| const DISK_IMAGE_TYPES: SupportedImageTypes[] = ['guest-image', 'aws', 'ami']; | ||
|
|
||
| const NoUsersAlert = () => { | ||
| const isImageMode = useAppSelector(selectIsImageMode); | ||
| const imageTypes = useAppSelector(selectImageTypes); | ||
| const users = useAppSelector(selectUsers); | ||
|
|
||
| const hasUser = users.some((user) => (user.name || '').trim() !== ''); | ||
| const isDiskImage = imageTypes.some((imageType) => | ||
| DISK_IMAGE_TYPES.includes(imageType), | ||
| ); | ||
|
|
||
| if (!isImageMode || !isDiskImage || hasUser) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Alert variant='warning' isInline title='No users added' ouiaId='NoUsers'> | ||
| <Content component='p'> | ||
| This image has no user accounts, so you won't be able to log in to | ||
| it directly. To log in, use cloud-init to create a user when you launch | ||
| the image, or go back to the Users step and add one now. | ||
| </Content> | ||
| </Alert> | ||
| ); | ||
| }; | ||
|
|
||
| export default NoUsersAlert; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/Components/CreateImageWizard/steps/Review/components/tests/NoUsersAlert.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { screen } from '@testing-library/react'; | ||
|
|
||
| import { initialState } from '@/store/slices/wizard'; | ||
| import { renderWithRedux, type WizardStateOverrides } from '@/test/testUtils'; | ||
|
|
||
| import NoUsersAlert from '../NoUsersAlert'; | ||
|
|
||
| const testUser = { | ||
| name: 'testuser', | ||
| password: '', | ||
| ssh_key: '', | ||
| isAdministrator: false, | ||
| groups: [], | ||
| hasPassword: false, | ||
| }; | ||
|
|
||
| const imageModeOverrides = ( | ||
| overrides: WizardStateOverrides = {}, | ||
| ): WizardStateOverrides => ({ | ||
| details: { | ||
| ...initialState.details, | ||
| blueprint: { ...initialState.details.blueprint, mode: 'image' }, | ||
| }, | ||
| output: { | ||
| ...initialState.output, | ||
| imageTypes: ['guest-image'], | ||
| }, | ||
| ...overrides, | ||
| }); | ||
|
|
||
| describe('NoUsersAlert', () => { | ||
| test('warns when a disk image has no users', async () => { | ||
| renderWithRedux(<NoUsersAlert />, imageModeOverrides()); | ||
|
|
||
| expect(await screen.findByText(/no users added/i)).toBeInTheDocument(); | ||
| expect(screen.getByText(/cloud-init/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('does not warn for the container installer', () => { | ||
| renderWithRedux( | ||
| <NoUsersAlert />, | ||
| imageModeOverrides({ | ||
| output: { | ||
| ...initialState.output, | ||
| imageTypes: ['bootable-container-iso'], | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| expect(screen.queryByText(/no users added/i)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('does not warn when a user is configured', () => { | ||
| renderWithRedux( | ||
| <NoUsersAlert />, | ||
| imageModeOverrides({ | ||
| system: { | ||
| ...initialState.system, | ||
| users: [testUser], | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| expect(screen.queryByText(/no users added/i)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('does not warn in package mode', () => { | ||
| renderWithRedux(<NoUsersAlert />, { | ||
| output: { | ||
| ...initialState.output, | ||
| imageTypes: ['guest-image'], | ||
| }, | ||
| }); | ||
|
|
||
| expect(screen.queryByText(/no users added/i)).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
suggestion (testing): Consider covering all supported disk image types and mixed-type outputs
The current test only exercises the
guest-imagetype, butNoUsersAlerttreatsguest-image,aws, andamias disk images. To better align tests with the implementation, please:awsandami(e.g., via a parameterized test) to confirm they also show the warning when no users are configured.imageTypesmixes disk and non-disk types (e.g.['guest-image', 'bootable-container-iso']) to confirm that any disk image still triggers the alert.This will keep the tests resilient if
DISK_IMAGE_TYPESchanges in the future.