From 5adb8b581e1d8861851ca500d47e453c791d0c60 Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Tue, 1 Dec 2020 13:06:59 +0100 Subject: [PATCH] CreateImageWizard: Only ask for aws account id in upload step --- .../CreateImageWizard/WizardStepUploadAWS.js | 55 +++------- .../CreateImageWizard/CreateImageWizard.js | 40 ++----- .../CreateImageWizard.test.js | 101 ++++++++---------- 3 files changed, 61 insertions(+), 135 deletions(-) diff --git a/src/PresentationalComponents/CreateImageWizard/WizardStepUploadAWS.js b/src/PresentationalComponents/CreateImageWizard/WizardStepUploadAWS.js index f74efbaf..559f3206 100644 --- a/src/PresentationalComponents/CreateImageWizard/WizardStepUploadAWS.js +++ b/src/PresentationalComponents/CreateImageWizard/WizardStepUploadAWS.js @@ -1,55 +1,26 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Form, FormGroup, FormSelect, TextInput, FormSelectOption, Title } from '@patternfly/react-core'; +import { Form, FormGroup, TextInput, Title } from '@patternfly/react-core'; const WizardStepUploadAWS = (props) => { - const serviceOptions = [ - { value: 'ec2', label: 'Amazon Elastic Compute Cloud (ec2)' }, - { value: 's3', label: 'Amazon Simple Storage Service (s3)' }, - ]; - return (
Upload to AWS - + Your image will be uploaded to a temporary account on Amazon Web Services. + The image will be shared with the account ID you provide below.
+ Within the next 14 days you will need to copy the shared image to your own account. + After 14 days it will be unavailable and will have to be regenerated. +

+ - props.setUploadOptions(Object.assign(props.upload.options, { access_key_id: value })) } /> + props.setUploadOptions(Object.assign(props.upload.options, { share_with_accounts: [ value ]})) } /> - - props.setUploadOptions(Object.assign(props.upload.options, { secret_access_key: value })) } /> - - - props.setUploadOptions(Object.assign(props.upload.options, { service: value })) }> - { serviceOptions.map(option => ) } - - - - props.setUploadOptions(Object.assign(props.upload.options, { region: value })) } /> - - { props.upload.options.service === 's3' && - - props.setUploadOptions(Object.assign(props.upload.options, { bucket: value })) } /> - } ); }; diff --git a/src/SmartComponents/CreateImageWizard/CreateImageWizard.js b/src/SmartComponents/CreateImageWizard/CreateImageWizard.js index c135c172..d7f4386b 100644 --- a/src/SmartComponents/CreateImageWizard/CreateImageWizard.js +++ b/src/SmartComponents/CreateImageWizard/CreateImageWizard.js @@ -35,11 +35,7 @@ class CreateImageWizard extends Component { upload: { type: 'aws', options: { - service: 'ec2', - region: 'eu-west-2', - access_key_id: null, - secret_access_key: null, - bucket: null, + share_with_accounts: [], } }, subscription: { @@ -89,25 +85,10 @@ class CreateImageWizard extends Component { validateUploadAmazon() { let uploadErrors = {}; - if (!this.state.upload.options.access_key_id) { - uploadErrors['amazon-access-id'] = - { label: 'Access key ID', value: 'A value is required' }; - } - - if (!this.state.upload.options.secret_access_key) { - uploadErrors['amazon-access-secret'] = - { label: 'Secret access key', value: 'A value is required' }; - } - - if (!this.state.upload.options.region) { - uploadErrors['amazon-region'] = - { label: 'Region', value: 'A value is required' }; - } - - if (this.state.upload.options.service === 's3' && - !this.state.upload.options.bucket) { - uploadErrors['amazon-bucket'] = - { label: 'Bucket', value: 'A value is required' }; + let share = this.state.upload.options.share_with_accounts; + if (share.length === 0 || share[0].length !== 12 || isNaN(share[0])) { + uploadErrors['aws-account-id'] = + { label: 'AWS account ID', value: 'A 12-digit number is required' }; } this.setState({ uploadErrors }); @@ -160,16 +141,7 @@ class CreateImageWizard extends Component { upload_requests: [{ type: 'aws', options: { - region: this.state.upload.options.region, - s3: { - access_key_id: this.state.upload.options.access_key_id, - secret_access_key: this.state.upload.options.secret_access_key, - bucket: this.state.upload.options.bucket, - }, - ec2: { - access_key_id: this.state.upload.options.access_key_id, - secret_access_key: this.state.upload.options.secret_access_key, - }, + share_with_accounts: this.state.upload.options.share_with_accounts, }, }], }], diff --git a/src/test/SmartComponents/CreateImageWizard/CreateImageWizard.test.js b/src/test/SmartComponents/CreateImageWizard/CreateImageWizard.test.js index 7813b810..8e41eb85 100644 --- a/src/test/SmartComponents/CreateImageWizard/CreateImageWizard.test.js +++ b/src/test/SmartComponents/CreateImageWizard/CreateImageWizard.test.js @@ -92,7 +92,7 @@ describe('Step Image output', () => { const [ next, , ] = verifyButtons(); next.click(); - screen.getByText('Secret access key'); + screen.getByText('AWS account ID'); }); test('Back button is disabled', () => { @@ -154,55 +154,11 @@ describe('Step Upload to AWS', () => { verifyCancelButton(cancel, historySpy); }); - test('choosing S3 shows region and bucket fields', () => { - // change the select to enable the bucket field - userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 's3' ]); - - const accessKeyId = screen.getByTestId('aws-access-key'); + test('the aws account id fieldis shown and required', () => { + const accessKeyId = screen.getByTestId('aws-account-id'); expect(accessKeyId).toHaveValue(''); expect(accessKeyId).toBeEnabled(); expect(accessKeyId).toBeRequired(); - - const secretAccessKey = screen.getByTestId('aws-secret-access-key'); - expect(secretAccessKey).toHaveValue(''); - expect(secretAccessKey).toBeEnabled(); - expect(secretAccessKey).toBeRequired(); - - const region = screen.getByTestId('aws-region'); - expect(region).toHaveValue('eu-west-2'); - expect(region).toBeEnabled(); - expect(region).toBeRequired(); - - const bucket = screen.getByTestId('aws-bucket'); - expect(bucket).toHaveValue(''); - expect(bucket).toBeEnabled(); - expect(bucket).toBeRequired(); - }); - - test('choosing EC2 shows region field', async () => { - // change the select to enable the bucket field - userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 's3' ]); - - const accessKeyId = screen.getByTestId('aws-access-key'); - expect(accessKeyId).toHaveValue(''); - expect(accessKeyId).toBeEnabled(); - expect(accessKeyId).toBeRequired(); - - const secretAccessKey = screen.getByTestId('aws-secret-access-key'); - expect(secretAccessKey).toHaveValue(''); - expect(secretAccessKey).toBeEnabled(); - expect(secretAccessKey).toBeRequired(); - - const region = screen.getByTestId('aws-region'); - expect(region).toHaveValue('eu-west-2'); - expect(region).toBeEnabled(); - expect(region).toBeRequired(); - - const p1 = waitForElementToBeRemoved(() => screen.queryByTestId('aws-bucket')); - - // change the select to hide the bucket field - userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 'ec2' ]); - await p1; }); }); @@ -230,8 +186,7 @@ describe('Step Registration', () => { const [ , back, ] = verifyButtons(); back.click(); - screen.getByText('Access key ID'); - screen.getByText('Secret access key'); + screen.getByText('AWS account ID'); }); test('clicking Cancel loads landing page', () => { @@ -323,12 +278,7 @@ describe('Click through all steps', () => { next.click(); // select upload target - await screen.findByTestId('aws-access-key'); - userEvent.type(screen.getByTestId('aws-access-key'), 'key'); - userEvent.type(screen.getByTestId('aws-secret-access-key'), 'secret'); - userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 's3' ]); - userEvent.type(screen.getByTestId('aws-region'), 'us-east-1'); - userEvent.type(screen.getByTestId('aws-bucket'), 'imagebuilder'); + userEvent.type(screen.getByTestId('aws-account-id'), '012345678901'); next.click(); // registration @@ -369,9 +319,7 @@ describe('Click through all steps', () => { userEvent.selectOptions(screen.getByTestId('upload-destination'), [ 'aws' ]); next.click(); - // leave AWS access keys empty - userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 's3' ]); - userEvent.clear(screen.getByTestId('aws-region')); + // leave AWS account id empty next.click(); // registration @@ -388,6 +336,41 @@ describe('Click through all steps', () => { await screen.findByText('Register the system on first boot'); const errorMessages = await screen.findAllByText('A value is required'); - expect(errorMessages.length).toBe(5); + expect(errorMessages.length).toBe(1); + + const uploadErrorMessage = await screen.findAllByText('A 12-digit number is required'); + expect(uploadErrorMessage.length).toBe(1); + }); + + test('with invalid values', async () => { + const next = screen.getByRole('button', { name: /Next/ }); + + // select release + userEvent.selectOptions(screen.getByTestId('release-select'), [ 'rhel-8' ]); + // select upload target + userEvent.selectOptions(screen.getByTestId('upload-destination'), [ 'aws' ]); + next.click(); + + userEvent.type(screen.getByTestId('aws-account-id'), 'invalid, isNaN'); + next.click(); + + // registration + screen + .getByLabelText('Embed an activation key and register systems on first boot') + .click(); + await screen.findByTestId('subscription-activation'); + userEvent.clear(screen.getByTestId('subscription-activation')); + next.click(); + + await screen. + findByText('Review the information and click Create image to create the image using the following criteria.'); + await screen.findByText('Amazon Web Services'); + await screen.findByText('Register the system on first boot'); + + const errorMessages = await screen.findAllByText('A value is required'); + expect(errorMessages.length).toBe(1); + + const uploadErrorMessage = await screen.findAllByText('A 12-digit number is required'); + expect(uploadErrorMessage.length).toBe(1); }); });