-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
191 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
cypress/e2e/edge-firewall/create-edge-firewall-rule-engine-rate-limit.cy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* eslint-disable cypress/no-unnecessary-waiting */ | ||
import generateUniqueName from '../../support/utils' | ||
import selectors from '../../support/selectors' | ||
|
||
let firewallName, ruleName | ||
|
||
describe('Edge Firewall spec', { tags: ['@dev5'] }, () => { | ||
beforeEach(() => { | ||
cy.login() | ||
firewallName = generateUniqueName('EdgeFirewall') | ||
ruleName = generateUniqueName('EdgeFirewallRule') | ||
}) | ||
|
||
it('should create an Edge Firewall and set a rate limit', () => { | ||
cy.openProduct('Edge Firewall') | ||
|
||
// Act - create Edge Firewall | ||
cy.get(selectors.edgeFirewall.createButton).click() | ||
cy.get(selectors.edgeFirewall.nameInput).clear() | ||
cy.get(selectors.edgeFirewall.nameInput).type(firewallName) | ||
cy.get(selectors.edgeFirewall.edgeFunctionSwitch).click() | ||
cy.get(selectors.edgeFirewall.wafEnabledSwitch).click() | ||
cy.get(selectors.edgeFirewall.saveButton).click() | ||
cy.verifyToast('success', 'Your Edge Firewall has been created') | ||
|
||
cy.get(selectors.edgeFirewall.rulesEngineTab).click() | ||
cy.get(selectors.edgeFirewall.createRuleButton).click() | ||
cy.get(selectors.edgeFirewall.ruleNameInput).click() | ||
cy.get(selectors.edgeFirewall.ruleNameInput).type(ruleName) | ||
cy.get(selectors.edgeFirewall.ruleDescriptionInput).clear() | ||
cy.get(selectors.edgeFirewall.ruleDescriptionInput).type('My Rule Description') | ||
cy.get(selectors.edgeFirewall.ruleCriteriaVariableDropdown).click() | ||
cy.get(selectors.edgeFirewall.ruleCriteriaVariableDropdownHeaderAccept).click() | ||
cy.get(selectors.edgeFirewall.ruleCriteriaOperatorDropdown).click() | ||
cy.get(selectors.edgeFirewall.ruleCriteriaOperatorMatches).click() | ||
cy.get(selectors.edgeFirewall.ruleCriteriaInput).clear() | ||
cy.get(selectors.edgeFirewall.ruleCriteriaInput).type('test') | ||
|
||
cy.get(selectors.edgeFirewall.ruleBehaviorDropdown).click() | ||
cy.get(selectors.edgeFirewall.ruleBehaviorSetRateLimit).click() | ||
cy.get(selectors.edgeFirewall.behaviorRateLimitType).click() | ||
cy.get(selectors.edgeFirewall.behaviorRateLimitTypeFirstOption).click() | ||
cy.get(selectors.edgeFirewall.behaviorAverageRateLimitInput).type('1') | ||
cy.get(selectors.edgeFirewall.behaviorLimitBy).click() | ||
cy.get(selectors.edgeFirewall.behaviorLimitByFirstOption).click() | ||
|
||
cy.intercept('POST', '/api/v4/edge_firewall/firewalls/*/rules*').as('addEdgeFirewallRule') | ||
|
||
cy.get(selectors.edgeFirewall.ruleSubmit).click() | ||
|
||
cy.wait('@addEdgeFirewallRule').then((interception) => { | ||
const requestBody = interception.request.body | ||
expect(requestBody.criteria[0][0].operator).to.equal('matches') | ||
}) | ||
|
||
cy.verifyToast('success', 'Rule Engine successfully created') | ||
|
||
// Assert - Find the created rule | ||
cy.get(selectors.edgeFirewall.rulesTableSearchInput).clear() | ||
cy.get(selectors.edgeFirewall.rulesTableSearchInput).type(`${ruleName}{enter}`) | ||
cy.get(selectors.edgeFirewall.rulesTableColumnName).should('have.text', ruleName) | ||
cy.get(selectors.edgeFirewall.rulesTableColumnDescriptionShowMore).click() | ||
cy.get(selectors.edgeFirewall.rulesTableColumnDescription).should( | ||
'have.text', | ||
'My Rule Description' | ||
) | ||
|
||
// Cleanup - Remove the created rule | ||
cy.deleteEntityFromLoadedList().then(() => { | ||
cy.verifyToast('Rules Engine successfully deleted') | ||
}) | ||
|
||
// Assert - Find the created firewall | ||
cy.get(selectors.edgeFirewall.mainSettingsTab).click() | ||
cy.get(selectors.edgeFirewall.cancelButton).click() | ||
cy.get(selectors.edgeFirewall.searchInput).clear() | ||
cy.get(selectors.edgeFirewall.searchInput).type(`${firewallName}{enter}`) | ||
cy.get(selectors.edgeFirewall.nameRow).should('have.text', firewallName) | ||
cy.get(selectors.edgeFirewall.activeRow).should('have.text', 'Active') | ||
}) | ||
|
||
afterEach(() => { | ||
// Delete the firewall | ||
cy.deleteEntityFromList({ entityName: firewallName, productName: 'Edge Firewall' }).then(() => { | ||
cy.verifyToast('Edge Firewall successfully deleted') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/services/edge-application-rules-engine-services/v4/helper-criteria.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const isExistenceOperator = (operator) => ['exists', 'does_not_exist'].includes(operator) | ||
|
||
const processCriteria = (criteria) => { | ||
if (!isExistenceOperator(criteria.operator)) { | ||
return criteria | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const { argument, ...processedCriteria } = criteria | ||
return processedCriteria | ||
} | ||
|
||
export const adaptCriteria = (criterias) => { | ||
return criterias.map((criteriaArray) => { | ||
return criteriaArray.map(processCriteria) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters