diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_chime_channel.json b/cypress/fixtures/plugins/notifications-dashboards/test_chime_channel.json new file mode 100644 index 000000000..feb56cc1f --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_chime_channel.json @@ -0,0 +1,11 @@ +{ + "config": { + "name": "Test chime channel", + "description": "A test chime channel", + "config_type": "chime", + "is_enabled": true, + "chime": { + "url": "https://sample-chime-webhook" + } + } +} \ No newline at end of file diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_email_recipient_group.json b/cypress/fixtures/plugins/notifications-dashboards/test_email_recipient_group.json new file mode 100644 index 000000000..6f043b7cb --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_email_recipient_group.json @@ -0,0 +1,30 @@ +{ + "config": { + "name": "Test recipient group", + "description": "A test email recipient group", + "config_type": "email_group", + "is_enabled": true, + "email_group": { + "recipient_list": [ + { + "recipient": "custom.email.1@test.com" + }, + { + "recipient": "custom.email.2@test.com" + }, + { + "recipient": "custom.email.3@test.com" + }, + { + "recipient": "custom.email.4@test.com" + }, + { + "recipient": "custom.email.5@test.com" + }, + { + "recipient": "custom.email.6@test.com" + } + ] + } + } +} \ No newline at end of file diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_ses_sender.json b/cypress/fixtures/plugins/notifications-dashboards/test_ses_sender.json new file mode 100644 index 000000000..1395b9364 --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_ses_sender.json @@ -0,0 +1,13 @@ +{ + "config": { + "name": "test-ses-sender", + "description": "A test SES sender", + "config_type": "ses_account", + "is_enabled": true, + "ses_account": { + "region": "us-east-1", + "role_arn": "arn:aws:iam::012345678912:role/NotificationsSESRole", + "from_address": "test@email.com" + } + } +} \ No newline at end of file diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_slack_channel.json b/cypress/fixtures/plugins/notifications-dashboards/test_slack_channel.json new file mode 100644 index 000000000..7643b2b0d --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_slack_channel.json @@ -0,0 +1,11 @@ +{ + "config": { + "name": "Test slack channel", + "description": "A test slack channel", + "config_type": "slack", + "is_enabled": true, + "slack": { + "url": "https://sample-slack-webhook" + } + } +} \ No newline at end of file diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_smtp_email_channel.json b/cypress/fixtures/plugins/notifications-dashboards/test_smtp_email_channel.json new file mode 100644 index 000000000..f6ddc82a9 --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_smtp_email_channel.json @@ -0,0 +1,17 @@ +{ + "config": { + "name": "Test email channel", + "description": "A test SMTP email channel", + "config_type": "email", + "is_enabled": true, + "email": { + "email_account_id": "test_smtp_sender_id", + "recipient_list": [ + { + "recipient": "custom.email@test.com" + } + ], + "email_group_id_list": [] + } + } +} \ No newline at end of file diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_sns_channel.json b/cypress/fixtures/plugins/notifications-dashboards/test_sns_channel.json new file mode 100644 index 000000000..579eabd61 --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_sns_channel.json @@ -0,0 +1,12 @@ +{ + "config": { + "name": "test-sns-channel", + "description": "A test SNS channel", + "config_type": "sns", + "is_enabled": true, + "sns": { + "topic_arn": "arn:aws:sns:us-west-2:123456789012:notifications-test", + "role_arn": "arn:aws:iam::012345678901:role/NotificationsSNSRole" + } + } +} \ No newline at end of file diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_ssl_smtp_sender.json b/cypress/fixtures/plugins/notifications-dashboards/test_ssl_smtp_sender.json new file mode 100644 index 000000000..977369a03 --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_ssl_smtp_sender.json @@ -0,0 +1,14 @@ +{ + "config": { + "name": "test-ssl-sender", + "description": "A test SSL SMTP sender", + "config_type": "smtp_account", + "is_enabled": true, + "smtp_account": { + "host": "test-host.com", + "port": 123, + "method": "ssl", + "from_address": "test@email.com" + } + } +} \ No newline at end of file diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_tls_smtp_sender.json b/cypress/fixtures/plugins/notifications-dashboards/test_tls_smtp_sender.json new file mode 100644 index 000000000..cfa9870e4 --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_tls_smtp_sender.json @@ -0,0 +1,15 @@ +{ + "config_id": "test_smtp_sender_id", + "config": { + "name": "test-tls-sender", + "description": "A test TLS SMTP sender", + "config_type": "smtp_account", + "is_enabled": true, + "smtp_account": { + "host": "test-host.com", + "port": 123, + "method": "start_tls", + "from_address": "test@email.com" + } + } +} \ No newline at end of file diff --git a/cypress/fixtures/plugins/notifications-dashboards/test_webhook_channel.json b/cypress/fixtures/plugins/notifications-dashboards/test_webhook_channel.json new file mode 100644 index 000000000..86d6ec102 --- /dev/null +++ b/cypress/fixtures/plugins/notifications-dashboards/test_webhook_channel.json @@ -0,0 +1,12 @@ +{ + "config": { + "name": "Test webhook channel", + "description": "A test webhook channel", + "config_type": "webhook", + "is_enabled": true, + "webhook": { + "url": "https://custom-webhook-test-url.com:8888/test-path?params1=value1¶ms2=value2¶ms3=value3¶ms4=value4¶ms5=values5¶ms6=values6¶ms7=values7" + } + } +} + diff --git a/cypress/integration/plugins/notifications-dashboards/1_email_senders_and_groups.spec.js b/cypress/integration/plugins/notifications-dashboards/1_email_senders_and_groups.spec.js index 49e665792..30dc4bcd4 100644 --- a/cypress/integration/plugins/notifications-dashboards/1_email_senders_and_groups.spec.js +++ b/cypress/integration/plugins/notifications-dashboards/1_email_senders_and_groups.spec.js @@ -11,9 +11,20 @@ import { NOTIFICATIONS_PLUGIN_NAME, } from '../../../utils/constants'; +import testSslSmtpSender from '../../../fixtures/plugins/notifications-dashboards/test_ssl_smtp_sender.json'; +import testTlsSmtpSender from '../../../fixtures/plugins/notifications-dashboards/test_tls_smtp_sender.json'; +import testSesSender from '../../../fixtures/plugins/notifications-dashboards/test_ses_sender.json'; +import testEmailRecipientGroup from '../../../fixtures/plugins/notifications-dashboards/test_email_recipient_group.json'; + describe('Test create email senders', () => { + before(() => { + // Delete all Notification configs + cy.deleteAllNotificationConfigs(); + }); + beforeEach(() => { cy.visit(`${BASE_PATH}/app/${NOTIFICATIONS_PLUGIN_NAME}#email-senders`); + cy.reload(true); cy.wait(NOTIFICATIONS_DELAY * 5); }); @@ -62,7 +73,7 @@ describe('Test create email senders', () => { cy.get('.euiButton__text').contains('Create').click({ force: true }); cy.contains('successfully created.').should('exist'); - cy.contains('test-ssl-sender').should('exist'); + cy.contains('test-tls-sender').should('exist'); }); it('creates SES sender', () => { @@ -89,8 +100,18 @@ describe('Test create email senders', () => { }); describe('Test edit senders', () => { + before(() => { + // Delete all Notification configs + cy.deleteAllNotificationConfigs(); + + cy.createNotificationConfig(testSslSmtpSender); + cy.createNotificationConfig(testTlsSmtpSender); + cy.createNotificationConfig(testSesSender); + }); + beforeEach(() => { cy.visit(`${BASE_PATH}/app/${NOTIFICATIONS_PLUGIN_NAME}#email-senders`); + cy.reload(true); cy.wait(NOTIFICATIONS_DELAY * 5); }); @@ -102,7 +123,7 @@ describe('Test edit senders', () => { force: true, }); cy.get('[data-test-subj="create-sender-form-email-input"]').type( - '{selectall}{backspace}edited.test@email.com' + '{selectall}{backspace}editedtest@email.com' ); cy.wait(NOTIFICATIONS_DELAY); @@ -128,15 +149,23 @@ describe('Test edit senders', () => { }); describe('Test delete senders', () => { + before(() => { + // Delete all Notification configs + cy.deleteAllNotificationConfigs(); + + cy.createNotificationConfig(testSslSmtpSender); + cy.createNotificationConfig(testTlsSmtpSender); + cy.createNotificationConfig(testSesSender); + }); + beforeEach(() => { cy.visit(`${BASE_PATH}/app/${NOTIFICATIONS_PLUGIN_NAME}#email-senders`); + cy.reload(true); cy.wait(NOTIFICATIONS_DELAY * 5); }); it('deletes smtp senders', () => { - cy.get('.euiCheckbox__input[aria-label="Select this row"]') - .eq(0) - .click({ force: true }); // ssl sender + cy.get('.euiCheckbox__input[aria-label="Select this row"]').eq(0).click(); // ssl sender cy.get('[data-test-subj="senders-table-delete-button"]').click({ force: true, }); @@ -149,9 +178,8 @@ describe('Test delete senders', () => { }); it('deletes ses senders', () => { - cy.get('.euiCheckbox__input[aria-label="Select this row"]') - .last() - .click({ force: true }); // ses sender + cy.get('.euiCheckbox__input[aria-label="Select this row"]').last().click(); // ses sender + cy.wait(NOTIFICATIONS_DELAY); cy.get('[data-test-subj="ses-senders-table-delete-button"]').click({ force: true, }); @@ -168,9 +196,15 @@ describe('Test delete senders', () => { describe('Test create, edit and delete recipient group', () => { beforeEach(() => { + // Delete all Notification configs + cy.deleteAllNotificationConfigs(); + + cy.createNotificationConfig(testEmailRecipientGroup); + cy.visit( `${BASE_PATH}/app/${NOTIFICATIONS_PLUGIN_NAME}#email-recipient-groups` ); + cy.reload(true); cy.wait(NOTIFICATIONS_DELAY * 5); }); @@ -230,14 +264,15 @@ describe('Test create, edit and delete recipient group', () => { }); it('opens email addresses popup', () => { - cy.get('.euiLink').contains('1 more').click({ force: true }); + cy.get('.euiTableCellContent--overflowingContent .euiLink') + .contains('1 more') + .click({ force: true }); cy.contains('custom.email.6@test.com').should('exist'); }); it('deletes recipient groups', () => { - cy.get('[data-test-subj="checkboxSelectAll"]') - .last() - .click({ force: true }); + cy.get('[data-test-subj="checkboxSelectAll"]').click({ force: true }); + cy.wait(NOTIFICATIONS_DELAY); cy.get('[data-test-subj="recipient-groups-table-delete-button"]').click({ force: true, }); diff --git a/cypress/integration/plugins/notifications-dashboards/2_channels.spec.js b/cypress/integration/plugins/notifications-dashboards/2_channels.spec.js index 885c45c53..f0e4ef50b 100644 --- a/cypress/integration/plugins/notifications-dashboards/2_channels.spec.js +++ b/cypress/integration/plugins/notifications-dashboards/2_channels.spec.js @@ -11,7 +11,19 @@ import { NOTIFICATIONS_PLUGIN_NAME, } from '../../../utils/constants'; +import testSlackChannel from '../../../fixtures/plugins/notifications-dashboards/test_slack_channel.json'; +import testChimeChannel from '../../../fixtures/plugins/notifications-dashboards/test_chime_channel.json'; +import testWebhookChannel from '../../../fixtures/plugins/notifications-dashboards/test_webhook_channel.json'; +import testTlsSmtpSender from '../../../fixtures/plugins/notifications-dashboards/test_tls_smtp_sender.json'; + describe('Test create channels', () => { + before(() => { + // Delete all Notification configs + cy.deleteAllNotificationConfigs(); + + cy.createNotificationConfig(testTlsSmtpSender); + }); + beforeEach(() => { cy.visit(`${BASE_PATH}/app/${NOTIFICATIONS_PLUGIN_NAME}#create-channel`); cy.wait(NOTIFICATIONS_DELAY * 5); @@ -62,7 +74,7 @@ describe('Test create channels', () => { cy.contains('successfully created.').should('exist'); }); - it('creates a email channel', () => { + it('creates an email channel', () => { cy.get('[placeholder="Enter channel name"]').type('Test email channel'); cy.get('.euiSuperSelectControl').contains('Slack').click({ force: true }); @@ -101,7 +113,7 @@ describe('Test create channels', () => { cy.contains('successfully created.').should('exist'); }); - it('creates a email channel with ses sender', () => { + it('creates an email channel with ses sender', () => { cy.get('[placeholder="Enter channel name"]').type( 'Test email channel with ses' ); @@ -168,7 +180,7 @@ describe('Test create channels', () => { cy.contains('successfully created.').should('exist'); }); - it('creates a sns channel', () => { + it('creates an sns channel', () => { cy.get('[placeholder="Enter channel name"]').type('test-sns-channel'); cy.get('.euiSuperSelectControl').contains('Slack').click({ force: true }); @@ -193,6 +205,17 @@ describe('Test create channels', () => { }); describe('Test channels table', () => { + before(() => { + // Delete all Notification configs + cy.deleteAllNotificationConfigs(); + + // Create test channels + cy.createNotificationConfig(testSlackChannel); + cy.createNotificationConfig(testChimeChannel); + cy.createNotificationConfig(testWebhookChannel); + cy.createTestEmailChannel(); + }); + beforeEach(() => { cy.visit(`${BASE_PATH}/app/${NOTIFICATIONS_PLUGIN_NAME}#channels`); cy.wait(NOTIFICATIONS_DELAY * 5); @@ -276,6 +299,9 @@ describe('Test channel details', () => { // cy.get( // '[data-test-subj="create-channel-description-input"]' // ).type('{selectall}{backspace}Updated custom webhook description'); + cy.get('[data-test-subj="create-channel-description-input"]').type( + '{selectall}{backspace}Updated custom webhook description' + ); cy.get('.euiTextArea').type( '{selectall}{backspace}Updated custom webhook description' ); diff --git a/cypress/support/index.js b/cypress/support/index.js index f4e42b3de..cd0c48704 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -29,6 +29,7 @@ import '../utils/plugins/security-dashboards-plugin/commands'; import '../utils/plugins/alerting-dashboards-plugin/commands'; import '../utils/plugins/security-analytics-dashboards-plugin/commands'; import '../utils/plugins/ml-commons-dashboards/commands'; +import '../utils/plugins/notifications-dashboards/commands'; import 'cypress-real-events'; diff --git a/cypress/utils/plugins/notifications-dashboards/commands.js b/cypress/utils/plugins/notifications-dashboards/commands.js new file mode 100644 index 000000000..f5cfae36e --- /dev/null +++ b/cypress/utils/plugins/notifications-dashboards/commands.js @@ -0,0 +1,45 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import testTlsSmtpSender from '../../../fixtures/plugins/notifications-dashboards/test_tls_smtp_sender.json'; +import testSmtpEmailChannel from '../../../fixtures/plugins/notifications-dashboards/test_smtp_email_channel.json'; +import { API } from './constants'; + +Cypress.Commands.add('deleteAllNotificationConfigs', () => { + cy.request({ + method: 'POST', + url: `${Cypress.env('openSearchUrl')}/_refresh`, + }); + + cy.request({ + method: 'GET', + url: `${Cypress.env('openSearchUrl')}${API.CONFIGS_BASE}`, + }).then((response) => { + if (response.status === 200) { + for (let i = 0; i < response.body.total_hits; i++) { + cy.request( + 'DELETE', + `${Cypress.env('openSearchUrl')}${API.CONFIGS_BASE}/${ + response.body.config_list[i].config_id + }` + ); + } + } else { + cy.log('Failed to get configs.', response); + } + }); +}); + +Cypress.Commands.add('createNotificationConfig', (notificationConfigJSON) => { + cy.request( + 'POST', + `${Cypress.env('openSearchUrl')}${API.CONFIGS_BASE}`, + notificationConfigJSON + ); +}); + +Cypress.Commands.add('createTestEmailChannel', () => { + cy.createNotificationConfig(testTlsSmtpSender); + cy.createNotificationConfig(testSmtpEmailChannel); +}); diff --git a/cypress/utils/plugins/notifications-dashboards/constants.js b/cypress/utils/plugins/notifications-dashboards/constants.js index fd6258f70..76da025b8 100644 --- a/cypress/utils/plugins/notifications-dashboards/constants.js +++ b/cypress/utils/plugins/notifications-dashboards/constants.js @@ -5,3 +5,7 @@ export const NOTIFICATIONS_PLUGIN_NAME = 'notifications-dashboards'; export const NOTIFICATIONS_DELAY = 1000; +export const NOTIFICATIONS_API_ROUTE_PREFIX = '/_plugins/_notifications'; +export const API = { + CONFIGS_BASE: `${NOTIFICATIONS_API_ROUTE_PREFIX}/configs`, +};