|
13 | 13 | * permissions and limitations under the License. |
14 | 14 | */ |
15 | 15 |
|
16 | | -const { API, INDEX } = require("./constants"); |
| 16 | +const { API, INDEX, ADMIN_AUTH } = require("./constants"); |
17 | 17 |
|
18 | 18 | // *********************************************** |
19 | 19 | // This example commands.js shows you how to |
@@ -41,8 +41,47 @@ const { API, INDEX } = require("./constants"); |
41 | 41 | // -- This will overwrite an existing command -- |
42 | 42 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) |
43 | 43 |
|
| 44 | +Cypress.Commands.overwrite("visit", (originalFn, url, options) => { |
| 45 | + // Add the basic auth header when security enabled in the Elasticsearch cluster |
| 46 | + // https://github.com/cypress-io/cypress/issues/1288 |
| 47 | + if (Cypress.env("security_enabled")) { |
| 48 | + if (options) { |
| 49 | + options.auth = ADMIN_AUTH; |
| 50 | + } else { |
| 51 | + options = { auth: ADMIN_AUTH }; |
| 52 | + } |
| 53 | + // Add query parameters - select the default Kibana tenant |
| 54 | + options.qs = { security_tenant: "private" }; |
| 55 | + return originalFn(url, options); |
| 56 | + } else { |
| 57 | + return originalFn(url, options); |
| 58 | + } |
| 59 | +}); |
| 60 | + |
| 61 | +// Be able to add default options to cy.request(), https://github.com/cypress-io/cypress/issues/726 |
| 62 | +Cypress.Commands.overwrite("request", (originalFn, ...args) => { |
| 63 | + let defaults = {}; |
| 64 | + // Add the basic authentication header when security enabled in the Elasticsearch cluster |
| 65 | + if (Cypress.env("security_enabled")) { |
| 66 | + defaults.auth = ADMIN_AUTH; |
| 67 | + } |
| 68 | + |
| 69 | + let options = {}; |
| 70 | + if (typeof args[0] === "object" && args[0] !== null) { |
| 71 | + options = Object.assign({}, args[0]); |
| 72 | + } else if (args.length === 1) { |
| 73 | + [options.url] = args; |
| 74 | + } else if (args.length === 2) { |
| 75 | + [options.method, options.url] = args; |
| 76 | + } else if (args.length === 3) { |
| 77 | + [options.method, options.url, options.body] = args; |
| 78 | + } |
| 79 | + |
| 80 | + return originalFn(Object.assign({}, defaults, options)); |
| 81 | +}); |
| 82 | + |
44 | 83 | Cypress.Commands.add("deleteAllIndices", () => { |
45 | | - cy.request("DELETE", `${Cypress.env("elasticsearch")}/*`); |
| 84 | + cy.request("DELETE", `${Cypress.env("elasticsearch")}/index*,sample*,kibana*`); |
46 | 85 | cy.request("DELETE", `${Cypress.env("elasticsearch")}/.opendistro-ism*?expand_wildcards=all`); |
47 | 86 | }); |
48 | 87 |
|
|
0 commit comments