Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Adds support to run Cypress test in an ODFE cluster with security enabled #235

Merged
merged 15 commits into from
Jan 15, 2021

Conversation

ftianli-amzn
Copy link

@ftianli-amzn ftianli-amzn commented Jan 14, 2021

Issue #, if available:

Description of changes:

  • Add an environment variable security_enabled to mark if security feature is enabled in the ODFE cluster.
    When security_enabled is true:
  1. Switch the base URL for Elasticsearch to https://localhost:9200
  2. Overwrite cy.visit() and cy.request() to add a basic authentication header (admin:admin) into the http requests.
  • Change the way of clean-up used for the test from deleting all indices to only delete monitors or destinations, mainly because admin user doesn't have permission to delete system indices
  • Add custom Cypress commands for deleteMonitorByName, deleteAllMonitors, deleteAllDestinations, createIndexByName, deleteIndexByName and insertDocumentToIndex
  • Change the test implementations about "alert", due to alert history can not be removed by admin user.
    A noticeable change is adding a unique number in the monitor names to filter the desired alert out.
  • Add an assertion before clearing all the text in input textfield, because when text in textfields is too long, the removing operation can't wait for the text loading and results in uncompleted removing.

Usage:
The environment variable security_enabled is set to false by default.
Appending --env security_enabled=true to the cypress command to change the value, other ways to set the environment variable please refers to the link.

Reference: opendistro-for-elasticsearch/anomaly-detection-kibana-plugin@455e3f8

Result for running cypress run --env security_enabled=true in an ODFE cluster with security enabled:

       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  alert_spec.js                            02:30        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  destination_spec.js                      00:30        4        4        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  monitor_spec.js                          00:40        6        6        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        03:42       15       15        -        -        -  

Result for running cypress run in an Elasticsearch cluster with only Alerting plugin:

       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  alert_spec.js                            02:24        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  destination_spec.js                      00:29        4        4        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  monitor_spec.js                          00:26        6        6        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        03:20       15       15        -        -        -  

Result for running yarn test:jest

Test Suites: 6 skipped, 83 passed, 83 of 89 total
Tests:       20 skipped, 385 passed, 405 total
Snapshots:   135 passed, 135 total
Time:        61.195 s
Ran all test suites.
✨  Done in 62.55s.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ftianli-amzn
Copy link
Author

ftianli-amzn commented Jan 14, 2021

The latest successful workflow run: https://github.com/opendistro-for-elasticsearch/alerting-kibana-plugin/actions/runs/484258034
(Can also be accessed from the ✅ on above commit.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
testing adds or improves tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants