Wizard: add tests for satellite registration
This commit is contained in:
parent
75792bcc0a
commit
d2c9b77957
6 changed files with 111 additions and 13 deletions
|
|
@ -3,7 +3,6 @@ import React from 'react';
|
|||
import {
|
||||
DropEvent,
|
||||
FileUpload,
|
||||
Form,
|
||||
FormGroup,
|
||||
FormHelperText,
|
||||
HelperText,
|
||||
|
|
@ -24,13 +23,11 @@ const SatelliteRegistration = () => {
|
|||
const caCertificate = useAppSelector(selectSatelliteCaCertificate);
|
||||
const [isRejected, setIsRejected] = React.useState(false);
|
||||
const stepValidation = useRegistrationValidation();
|
||||
const validated =
|
||||
stepValidation.errors['certificate'] === 'default'
|
||||
? 'default'
|
||||
: stepValidation.errors['certificate']
|
||||
? 'error'
|
||||
: 'success';
|
||||
|
||||
const validated = stepValidation.errors['certificate']
|
||||
? 'error'
|
||||
: stepValidation.errors['certificate'] === undefined && caCertificate
|
||||
? 'success'
|
||||
: 'default';
|
||||
const handleClear = () => {
|
||||
dispatch(changeSatelliteCaCertificate(''));
|
||||
};
|
||||
|
|
@ -51,7 +48,7 @@ const SatelliteRegistration = () => {
|
|||
setIsRejected(true);
|
||||
};
|
||||
return (
|
||||
<Form>
|
||||
<>
|
||||
<SatelliteRegistrationCommand />
|
||||
<FormGroup label="Certificate authority (CA)" isRequired>
|
||||
<FileUpload
|
||||
|
|
@ -72,7 +69,7 @@ const SatelliteRegistration = () => {
|
|||
maxSize: 512000,
|
||||
onDropRejected: handleFileRejected,
|
||||
}}
|
||||
validated={isRejected ? 'error' : 'default'}
|
||||
validated={isRejected ? 'error' : validated}
|
||||
browseButtonText="Upload"
|
||||
allowEditingUploadedText={true}
|
||||
/>
|
||||
|
|
@ -80,7 +77,11 @@ const SatelliteRegistration = () => {
|
|||
<HelperText>
|
||||
<HelperTextItem
|
||||
variant={
|
||||
isRejected || validated === 'error' ? 'error' : 'default'
|
||||
isRejected || validated === 'error'
|
||||
? 'error'
|
||||
: validated === 'success'
|
||||
? 'success'
|
||||
: 'default'
|
||||
}
|
||||
hasIcon
|
||||
>
|
||||
|
|
@ -88,12 +89,14 @@ const SatelliteRegistration = () => {
|
|||
? 'Must be a .PEM/.CER/.CRT file no larger than 512 KB'
|
||||
: validated === 'error'
|
||||
? stepValidation.errors['certificate']
|
||||
: validated === 'success'
|
||||
? 'Certificate was uploaded'
|
||||
: 'Drag and drop a valid certificate file or upload one'}
|
||||
</HelperTextItem>
|
||||
</HelperText>
|
||||
</FormHelperText>
|
||||
</FormGroup>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import { CheckCircleIcon } from '@patternfly/react-icons';
|
||||
|
||||
import { jwtDecode } from 'jwt-decode';
|
||||
|
||||
import { UNIQUE_VALIDATION_DELAY } from '../../../constants';
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ import {
|
|||
ImageRequest,
|
||||
} from '../../../../../store/imageBuilderApi';
|
||||
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
|
||||
import {
|
||||
CERTIFICATE,
|
||||
SATELLITE_COMMAND,
|
||||
SATELLITE_COMMAND_EXPIRED_TOKEN,
|
||||
} from '../../../../fixtures/customizations';
|
||||
import { registrationCreateBlueprintRequest } from '../../../../fixtures/editMode';
|
||||
import { server } from '../../../../mocks/server';
|
||||
import {
|
||||
|
|
@ -29,6 +34,8 @@ import {
|
|||
clickBack,
|
||||
verifyCancelButton,
|
||||
clickReviewAndFinish,
|
||||
getNextButton,
|
||||
clickRegisterSatellite,
|
||||
} from '../../wizardTestUtils';
|
||||
|
||||
const localStorageMock = (() => {
|
||||
|
|
@ -88,6 +95,29 @@ const selectActivationKey = async (key: string) => {
|
|||
await screen.findByDisplayValue(key);
|
||||
};
|
||||
|
||||
const addSatelliteRegistrationCommandViaKeyDown = async (command: string) => {
|
||||
const user = userEvent.setup({ delay: null });
|
||||
const satelliteRegistrationCommand = await screen.findByPlaceholderText(
|
||||
/registration command/i
|
||||
);
|
||||
|
||||
await waitFor(() => user.type(satelliteRegistrationCommand, command));
|
||||
};
|
||||
|
||||
const uploadFile = async (scriptName: string): Promise<void> => {
|
||||
const user = userEvent.setup();
|
||||
const fileInput: HTMLElement | null =
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
document.querySelector('input[type="file"]');
|
||||
|
||||
if (fileInput) {
|
||||
const file = new File([scriptName], 'certificate.pem', {
|
||||
type: 'application/x-pem-file',
|
||||
});
|
||||
await waitFor(() => user.upload(fileInput, file));
|
||||
}
|
||||
};
|
||||
|
||||
const goToReviewStep = async () => {
|
||||
await clickNext(); // Registration
|
||||
await clickNext(); // OpenSCAP
|
||||
|
|
@ -389,6 +419,29 @@ describe('Registration request generated correctly', () => {
|
|||
// clear mocked values in localStorage so they don't affect following tests
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
test('register with satellite', async () => {
|
||||
await renderCreateMode();
|
||||
await goToRegistrationStep();
|
||||
await clickRegisterSatellite();
|
||||
|
||||
const nextButton = await getNextButton();
|
||||
expect(nextButton).toBeDisabled();
|
||||
|
||||
await uploadFile(CERTIFICATE);
|
||||
expect(nextButton).toBeDisabled();
|
||||
await addSatelliteRegistrationCommandViaKeyDown(
|
||||
SATELLITE_COMMAND_EXPIRED_TOKEN
|
||||
);
|
||||
|
||||
const expiredTokenHelper = await screen.findByText(
|
||||
/The token is already expired or will expire by next day. Expiration date/i
|
||||
);
|
||||
await waitFor(() => expect(expiredTokenHelper).toBeInTheDocument());
|
||||
|
||||
await addSatelliteRegistrationCommandViaKeyDown(SATELLITE_COMMAND);
|
||||
expect(nextButton).toBeEnabled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Registration edit mode', () => {
|
||||
|
|
|
|||
|
|
@ -122,6 +122,17 @@ export const clickRegisterLater = async () => {
|
|||
await waitFor(() => user.click(registerLaterRadio));
|
||||
};
|
||||
|
||||
export const clickRegisterSatellite = async () => {
|
||||
const user = userEvent.setup();
|
||||
await screen.findByRole('heading', {
|
||||
name: /Register systems using this image/,
|
||||
});
|
||||
const registerLaterRadio = await screen.findByRole('radio', {
|
||||
name: /register with satellite/i,
|
||||
});
|
||||
await waitFor(() => user.click(registerLaterRadio));
|
||||
};
|
||||
|
||||
export const goToOscapStep = async () => {
|
||||
await clickNext(); // Registration
|
||||
await clickRegisterLater();
|
||||
|
|
|
|||
30
src/test/fixtures/customizations.ts
vendored
30
src/test/fixtures/customizations.ts
vendored
|
|
@ -63,3 +63,33 @@ export const customizations: Customizations = {
|
|||
'base-url': 'https://cdn.redhat.com/',
|
||||
},
|
||||
};
|
||||
|
||||
export const SATELLITE_COMMAND = `
|
||||
set -o pipefail && curl -sS ‘https://ec2-107-23-89.compute-1.amazonaws.com/register?activation_keys=ak&location_id=2&organization_id=1&update_packages=false’
|
||||
// -H ‘Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjQxMDI0NDQ4MDB9.CQ6hOQJLJDfD_P5gaEIEseY5iMRLhnk7iC5ZJ4Rzno0 | bash`;
|
||||
|
||||
export const SATELLITE_COMMAND_EXPIRED_TOKEN = `
|
||||
set -o pipefail && curl -sS ‘https://ec2-107-23-89.compute-1.amazonaws.com/register?activation_keys=ak&location_id=2&organization_id=1&update_packages=false’
|
||||
// -H ‘Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE3MjM4Mzc3MjIsImp0aSI6IjBhNTU3MDM3ZDIyNzUyMDYwM2M3MWIzZDI4NGYwZjQ1NmFjYjE5NzEyNmFmNTk5NzU0NWJmODcwZDczM2RhY2YiLCJleHAiOjE3MjM4NTIxMjIsInNjb3BlIjoicmVnaXN0cmF0aW9uI2dsb2JhbCByZWdpc3RyYXRpb24jaG9zdCJ9.HsSnZEqq--MIJfP3_awn6SflEruoEm77iSWh0Pi6EW4’
|
||||
// | bash`;
|
||||
|
||||
export const CERTIFICATE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w1x99UIJBcobOx+Kw/
|
||||
zB92/XFIBwOZArUmGDaiL5MnqhmFWfc6mtIELxIRKCj9LQG9y7L1JoVyqug3thgZ
|
||||
CdoLGtbHXri9BSR+8ogXu4JWp0YwMHTul6AEb2kcSZHTrYj6lUkXJMsw+E5jV37G
|
||||
jZKGigLMSUp2z4jT+aX+HblYHrvTbrKct23EMeJeANQzF08e
|
||||
-----END CERTIFICATE-----`;
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ vi.mock('@unleash/proxy-client-react', () => ({
|
|||
return true;
|
||||
case 'image-builder.edge.local-image-table':
|
||||
return true;
|
||||
case 'image-builder.satellite.enabled':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue