diff --git a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/gcp_credential_form.tsx b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/gcp_credential_form.tsx index a1d280f58c7a6..909eb029f5e98 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/gcp_credential_form.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/gcp_credential_form.tsx @@ -177,12 +177,14 @@ const credentialOptionsList = [ defaultMessage: 'Credentials File', }), value: 'credentials-file', + 'data-test-subj': 'credentials_file_option_test_id', }, { text: i18n.translate('xpack.csp.gcpIntegration.credentialsJsonOption', { defaultMessage: 'Credentials JSON', }), value: 'credentials-json', + 'data-test-subj': 'credentials_json_option_test_id', }, ]; diff --git a/x-pack/test/cloud_security_posture_functional/page_objects/add_cis_integration_form_page.ts b/x-pack/test/cloud_security_posture_functional/page_objects/add_cis_integration_form_page.ts index 924a2ae6c0dca..795c2edb62dd4 100644 --- a/x-pack/test/cloud_security_posture_functional/page_objects/add_cis_integration_form_page.ts +++ b/x-pack/test/cloud_security_posture_functional/page_objects/add_cis_integration_form_page.ts @@ -62,8 +62,23 @@ export function AddCisIntegrationFormPageProvider({ }, fillInTextField: async (selector: string, text: string) => { - const test = await testSubjects.find(selector); - await test.type(text); + const textField = await testSubjects.find(selector); + await textField.type(text); + }, + + chooseDropDown: async (selector: string, text: string) => { + const credentialTypeBox = await testSubjects.find(selector); + const chosenOption = await testSubjects.find(text); + await credentialTypeBox.click(); + await chosenOption.click(); + }, + + getFieldValueInEditPage: async (field: string) => { + /* Newly added/edited integration always shows up on top by default as such we can just always click the most top if we want to check for the latest one */ + const integrationList = await testSubjects.findAll('integrationNameLink'); + await integrationList[0].click(); + const fieldValue = await (await testSubjects.find(field)).getAttribute('value'); + return fieldValue; }, }; @@ -75,8 +90,16 @@ export function AddCisIntegrationFormPageProvider({ ); }; + const navigateToIntegrationCspList = async () => { + await PageObjects.common.navigateToActualUrl( + 'integrations', // Defined in Security Solution plugin + '/detail/cloud_security_posture/policies' + ); + }; + return { cisGcp, navigateToAddIntegrationCspmPage, + navigateToIntegrationCspList, }; } diff --git a/x-pack/test/cloud_security_posture_functional/pages/cis_integration.ts b/x-pack/test/cloud_security_posture_functional/pages/cis_integration.ts index 5935fc49b06a0..20f85163521a7 100644 --- a/x-pack/test/cloud_security_posture_functional/pages/cis_integration.ts +++ b/x-pack/test/cloud_security_posture_functional/pages/cis_integration.ts @@ -16,6 +16,8 @@ const GCP_MANUAL_TEST_ID = 'gcpManualOptionTestId'; const PRJ_ID_TEST_ID = 'project_id_test_id'; const ORG_ID_TEST_ID = 'organization_id_test_id'; const CREDENTIALS_TYPE_TEST_ID = 'credentials_type_test_id'; +const CREDENTIALS_FILE_TEST_ID = 'credentials_file_test_id'; +const CREDENTIALS_JSON_TEST_ID = 'credentials_json_test_id'; // eslint-disable-next-line import/no-default-export export default function (providerContext: FtrProviderContext) { @@ -103,5 +105,75 @@ export default function (providerContext: FtrProviderContext) { ); }); }); + + describe('CIS_GCP Single', () => { + it('Post Installation Google Cloud Shell modal pops up after user clicks on Save button when adding integration, when there are no Project ID, it should use default value', async () => { + await cisIntegrationGcp.clickOptionButton(CIS_GCP_OPTION_TEST_ID); + await cisIntegrationGcp.clickOptionButton(GCP_SINGLE_ACCOUNT_TEST_ID); + await cisIntegrationGcp.clickOptionButton(GCP_CLOUD_SHELL_TEST_ID); + await cisIntegrationGcp.clickSaveButton(); + pageObjects.header.waitUntilLoadingHasFinished(); + expect((await cisIntegrationGcp.isPostInstallGoogleCloudShellModal(false)) === true).to.be( + true + ); + }); + + it('Post Installation Google Cloud Shell modal pops up after user clicks on Save button when adding integration, when there are Project ID, it should use that value', async () => { + const projectName = 'PRJ_NAME_TEST'; + await cisIntegrationGcp.clickOptionButton(CIS_GCP_OPTION_TEST_ID); + await cisIntegrationGcp.clickOptionButton(GCP_SINGLE_ACCOUNT_TEST_ID); + await cisIntegrationGcp.clickOptionButton(GCP_CLOUD_SHELL_TEST_ID); + await cisIntegrationGcp.fillInTextField('project_id_test_id', projectName); + + await cisIntegrationGcp.clickSaveButton(); + pageObjects.header.waitUntilLoadingHasFinished(); + expect( + (await cisIntegrationGcp.isPostInstallGoogleCloudShellModal(false, '', projectName)) === + true + ).to.be(true); + }); + + it('Users are able to add CIS_GCP Integration with Manual settings using Credentials File', async () => { + const projectName = 'PRJ_NAME_TEST'; + const credentialFileName = 'CRED_FILE_TEST_NAME'; + await cisIntegrationGcp.clickOptionButton(CIS_GCP_OPTION_TEST_ID); + await cisIntegrationGcp.clickOptionButton(GCP_SINGLE_ACCOUNT_TEST_ID); + await cisIntegrationGcp.clickOptionButton(GCP_MANUAL_TEST_ID); + await cisIntegrationGcp.fillInTextField(PRJ_ID_TEST_ID, projectName); + await cisIntegrationGcp.fillInTextField(CREDENTIALS_FILE_TEST_ID, credentialFileName); + + await cisIntegrationGcp.clickSaveButton(); + pageObjects.header.waitUntilLoadingHasFinished(); + expect((await cisIntegrationGcp.getPostInstallModal()) !== undefined).to.be(true); + await cisIntegration.navigateToIntegrationCspList(); + expect( + (await cisIntegrationGcp.getFieldValueInEditPage(CREDENTIALS_FILE_TEST_ID)) === + credentialFileName + ).to.be(true); + }); + + it('Users are able to add CIS_GCP Integration with Manual settings using Credentials JSON', async () => { + const projectName = 'PRJ_NAME_TEST'; + const credentialJsonName = 'CRED_JSON_TEST_NAME'; + await cisIntegrationGcp.clickOptionButton(CIS_GCP_OPTION_TEST_ID); + await cisIntegrationGcp.clickOptionButton(GCP_SINGLE_ACCOUNT_TEST_ID); + await cisIntegrationGcp.clickOptionButton(GCP_MANUAL_TEST_ID); + await cisIntegrationGcp.fillInTextField(PRJ_ID_TEST_ID, projectName); + await cisIntegrationGcp.chooseDropDown( + CREDENTIALS_TYPE_TEST_ID, + 'credentials_json_option_test_id' + ); + await cisIntegrationGcp.fillInTextField(CREDENTIALS_JSON_TEST_ID, credentialJsonName); + + await cisIntegrationGcp.clickSaveButton(); + pageObjects.header.waitUntilLoadingHasFinished(); + expect((await cisIntegrationGcp.getPostInstallModal()) !== undefined).to.be(true); + await cisIntegration.navigateToIntegrationCspList(); + expect( + (await cisIntegrationGcp.getFieldValueInEditPage(CREDENTIALS_JSON_TEST_ID)) === + credentialJsonName + ).to.be(true); + }); + }); }); }