From f89a9cc093b32cbe863a57dcb6bf056d16a0d959 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Fri, 27 Sep 2024 14:29:57 -0700 Subject: [PATCH 1/3] integ tests for denied ips Signed-off-by: Riya Saxena --- .cypress/integration/channels.spec.js | 86 ++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/.cypress/integration/channels.spec.js b/.cypress/integration/channels.spec.js index f9d36954..735b2e20 100644 --- a/.cypress/integration/channels.spec.js +++ b/.cypress/integration/channels.spec.js @@ -185,6 +185,90 @@ describe('Test create channels', () => { cy.contains('successfully created.').should('exist'); }); + function cidrToIpList(cidr) { + const [base, bits] = cidr.split('/'); + const baseParts = base.split('.').map(Number); + const numAddresses = 1 << (32 - bits); // Calculate the number of IPs in the range + const ipList = []; + + for (let i = 0; i < numAddresses; i++) { + const ip = [ + baseParts[0] + ((i >> 24) & 255), + baseParts[1] + ((i >> 16) & 255), + baseParts[2] + ((i >> 8) & 255), + baseParts[3] + (i & 255), + ].join('.'); + ipList.push(ip); + } + return ipList; + } + + const updateLocalClusterSettings = (denyList) => { + cy.request({ + method: 'PUT', + url: 'http://localhost:9200/_cluster/settings', // Change to your local Elasticsearch URL + body: { + persistent: { + opensearch: { + notifications: { + core: { + http: { + host_deny_list: denyList, + }, + }, + }, + }, + }, + }, + }).then((response) => { + // Optionally handle the response to confirm the settings were updated + expect(response.status).to.eq(200); + expect(response.body).to.have.property('acknowledged', true); + }); + }; + + it('sends a test message for denied IPs', () => { + const deniedIps = [ + '127.0.0.1', + '169.254.0.1', + '10.0.0.1', + '255.255.255.255' + ]; // List of CIDRs to test + + updateLocalClusterSettings(deniedIps); + + cy.get('[placeholder="Enter channel name"]').type('Test denied webhook channels'); + + cy.get('.euiSuperSelectControl').contains('Slack').click({ force: true }); + cy.wait(delay); + // Optionally, add a check to ensure the dropdown options are visible/loaded + cy.get('.euiContextMenuItem__text').should('be.visible'); + cy.get('.euiContextMenuItem__text') + .contains('Custom webhook') + .click({ force: true }); + cy.wait(delay); + + deniedIps.forEach(ip => { + // Constructing the custom webhook URL for each IP + const webhookUrl = `https://${ip}:8888/test-path?params1=value1¶ms2=value2¶ms3=value3¶ms4=value4¶ms5=values5¶ms6=values6¶ms7=values7`; + + cy.get('[data-test-subj="custom-webhook-url-input"]').clear().type(webhookUrl); + + // Send the test message + cy.get('[data-test-subj="create-channel-send-test-message-button"]').click({ + force: true, + }); + cy.wait(delay); + + // Check for the expected error message indicating the host is denied + cy.contains('Failed to send the test message').should('exist'); + cy.get('.euiButton__text').should('be.visible'); + cy.get('.euiButton__text').contains('See the full error').click({ force: true }); + cy.contains('Host of url is denied').should('exist'); + cy.get('.euiButton__text').contains('Close').click({ force: true }); + }); + }); + it('creates an sns channel', () => { cy.get('[placeholder="Enter channel name"]').type('test-sns-channel'); @@ -333,7 +417,7 @@ describe('Test channel details', () => { cy.contains('Actions').click({ force: true }); cy.contains('Delete').click({ force: true }); cy.get('input[placeholder="delete"]').type('delete'); - cy.get('[data-test-subj="delete-channel-modal-delete-button"]').click({force: true}) + cy.get('[data-test-subj="delete-channel-modal-delete-button"]').click({ force: true }) cy.contains('successfully deleted.').should('exist'); cy.contains('Test slack channel').should('exist'); }) From 926113c4fbcb06d11e46053c11a9f9641af4ac34 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Fri, 27 Sep 2024 14:31:21 -0700 Subject: [PATCH 2/3] integ tests for denied ips Signed-off-by: Riya Saxena --- .cypress/integration/channels.spec.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.cypress/integration/channels.spec.js b/.cypress/integration/channels.spec.js index 735b2e20..803b223f 100644 --- a/.cypress/integration/channels.spec.js +++ b/.cypress/integration/channels.spec.js @@ -185,24 +185,6 @@ describe('Test create channels', () => { cy.contains('successfully created.').should('exist'); }); - function cidrToIpList(cidr) { - const [base, bits] = cidr.split('/'); - const baseParts = base.split('.').map(Number); - const numAddresses = 1 << (32 - bits); // Calculate the number of IPs in the range - const ipList = []; - - for (let i = 0; i < numAddresses; i++) { - const ip = [ - baseParts[0] + ((i >> 24) & 255), - baseParts[1] + ((i >> 16) & 255), - baseParts[2] + ((i >> 8) & 255), - baseParts[3] + (i & 255), - ].join('.'); - ipList.push(ip); - } - return ipList; - } - const updateLocalClusterSettings = (denyList) => { cy.request({ method: 'PUT', From b7a8891ff1bbaa3eeb88b75c96dc99fb50ce8cf0 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Fri, 27 Sep 2024 14:32:15 -0700 Subject: [PATCH 3/3] integ tests for denied ips Signed-off-by: Riya Saxena --- .cypress/integration/channels.spec.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.cypress/integration/channels.spec.js b/.cypress/integration/channels.spec.js index 803b223f..c135949b 100644 --- a/.cypress/integration/channels.spec.js +++ b/.cypress/integration/channels.spec.js @@ -188,7 +188,7 @@ describe('Test create channels', () => { const updateLocalClusterSettings = (denyList) => { cy.request({ method: 'PUT', - url: 'http://localhost:9200/_cluster/settings', // Change to your local Elasticsearch URL + url: 'http://localhost:9200/_cluster/settings', body: { persistent: { opensearch: { @@ -203,7 +203,6 @@ describe('Test create channels', () => { }, }, }).then((response) => { - // Optionally handle the response to confirm the settings were updated expect(response.status).to.eq(200); expect(response.body).to.have.property('acknowledged', true); }); @@ -215,7 +214,7 @@ describe('Test create channels', () => { '169.254.0.1', '10.0.0.1', '255.255.255.255' - ]; // List of CIDRs to test + ]; updateLocalClusterSettings(deniedIps);