Skip to content

Commit 6db7b73

Browse files
authored
[Backport 2.x] Run cypress tests with security (#1202) (#1204)
* Run cypress tests with security Signed-off-by: Craig Perkins <[email protected]> * Switch to upload-artifact v4 Signed-off-by: Craig Perkins <[email protected]> * Add cypress.config.js Signed-off-by: Craig Perkins <[email protected]> * Remove readCertAndKey Signed-off-by: Craig Perkins <[email protected]> --------- Signed-off-by: Craig Perkins <[email protected]>
1 parent cb8156c commit 6db7b73

File tree

18 files changed

+316
-223
lines changed

18 files changed

+316
-223
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
name: 'Runs the cypress test suite'
2+
description: 'Re-usable workflow to run cypress tests against a cluster with or without security'
3+
4+
inputs:
5+
with-security:
6+
description: 'Whether security should be installed on the cluster the tests are run with'
7+
required: true
8+
9+
runs:
10+
using: "composite"
11+
steps:
12+
- name: Set up JDK
13+
uses: actions/setup-java@v1
14+
with:
15+
# TODO: Parse this from index management plugin
16+
java-version: 21
17+
- name: Checkout index management
18+
uses: actions/checkout@v2
19+
with:
20+
path: index-management
21+
repository: opensearch-project/index-management
22+
ref: '2.x'
23+
- name: Run opensearch with plugin
24+
shell: bash
25+
if: ${{ inputs.with-security == 'false' }}
26+
run: |
27+
cd index-management
28+
./gradlew run &
29+
sleep 300
30+
# timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done'
31+
- name: Run opensearch with plugin
32+
shell: bash
33+
if: ${{ inputs.with-security == 'true' }}
34+
run: |
35+
cd index-management
36+
./gradlew run -Dsecurity=true -Dhttps=true &
37+
sleep 300
38+
# timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done'
39+
- name: Checkout Index Management Dashboards plugin
40+
uses: actions/checkout@v2
41+
with:
42+
path: index-management-dashboards-plugin
43+
- name: Checkout Security Dashboards plugin
44+
uses: actions/checkout@v2
45+
with:
46+
repository: opensearch-project/security-dashboards-plugin
47+
path: security-dashboards-plugin
48+
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
49+
- name: Checkout OpenSearch-Dashboards
50+
uses: actions/checkout@v2
51+
with:
52+
repository: opensearch-project/OpenSearch-Dashboards
53+
path: OpenSearch-Dashboards
54+
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
55+
- name: Setup Node
56+
uses: actions/setup-node@v3
57+
with:
58+
node-version-file: './OpenSearch-Dashboards/.nvmrc'
59+
registry-url: 'https://registry.npmjs.org'
60+
- name: Install Yarn
61+
# Need to use bash to avoid having a windows/linux specific step
62+
shell: bash
63+
run: |
64+
YARN_VERSION=$(node -p "require('./OpenSearch-Dashboards/package.json').engines.yarn")
65+
echo "Installing yarn@$YARN_VERSION"
66+
npm i -g yarn@$YARN_VERSION
67+
- run: node -v
68+
shell: bash
69+
- run: yarn -v
70+
shell: bash
71+
- name: Configure OpenSearch Dashboards for cypress
72+
shell: bash
73+
if: ${{ inputs.with-security == 'true' }}
74+
run: |
75+
cat << 'EOT' > ./OpenSearch-Dashboards/config/opensearch_dashboards.yml
76+
server.host: "0.0.0.0"
77+
opensearch.hosts: ["https://localhost:9200"]
78+
opensearch.ssl.verificationMode: none
79+
opensearch.username: "kibanaserver"
80+
opensearch.password: "kibanaserver"
81+
opensearch.requestHeadersWhitelist: [ authorization,securitytenant ]
82+
opensearch_security.multitenancy.enabled: true
83+
opensearch_security.multitenancy.tenants.preferred: ["Private", "Global"]
84+
opensearch_security.readonly_mode.roles: ["kibana_read_only"]
85+
opensearch_security.cookie.secure: false
86+
EOT
87+
- name: Print Dashboards Config
88+
shell: bash
89+
if: ${{ inputs.with-security == 'true' }}
90+
run: |
91+
cat ./OpenSearch-Dashboards/config/opensearch_dashboards.yml
92+
- name: Bootstrap plugin/OpenSearch-Dashboards
93+
shell: bash
94+
if: ${{ inputs.with-security == 'false' }}
95+
run: |
96+
mkdir -p OpenSearch-Dashboards/plugins
97+
mv index-management-dashboards-plugin OpenSearch-Dashboards/plugins
98+
- name: Bootstrap plugin/OpenSearch-Dashboards
99+
shell: bash
100+
if: ${{ inputs.with-security == 'true' }}
101+
run: |
102+
mkdir -p OpenSearch-Dashboards/plugins
103+
mv index-management-dashboards-plugin OpenSearch-Dashboards/plugins
104+
mv security-dashboards-plugin OpenSearch-Dashboards/plugins
105+
- name: Bootstrap the OpenSearch Dashboard
106+
uses: nick-fields/retry@v2
107+
with:
108+
timeout_minutes: 20
109+
max_attempts: 2
110+
command: yarn --cwd OpenSearch-Dashboards osd bootstrap --oss --single-version=loose
111+
- name: Compile OpenSearch Dashboards
112+
shell: bash
113+
run: |
114+
cd OpenSearch-Dashboards
115+
node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers=10 --verbose
116+
- name: Run OpenSearch-Dashboards server
117+
shell: bash
118+
run: |
119+
cd OpenSearch-Dashboards
120+
yarn start --no-base-path --no-watch --server.host="0.0.0.0" &
121+
sleep 30
122+
# in main branch, OSD server requires more time to bundle and bootstrap
123+
# timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done'
124+
# for now just chrome, use matrix to do all browsers later
125+
- name: Cypress tests
126+
uses: cypress-io/github-action@v2
127+
if: ${{ inputs.with-security == 'false' }}
128+
with:
129+
working-directory: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin
130+
command: yarn run cypress run
131+
wait-on: 'http://localhost:5601'
132+
browser: chrome
133+
- name: Cypress tests
134+
uses: cypress-io/github-action@v2
135+
if: ${{ inputs.with-security == 'true' }}
136+
with:
137+
working-directory: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin
138+
command: yarn run cypress run --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200,WAIT_FOR_LOADER_BUFFER_MS=500
139+
wait-on: 'http://localhost:5601'
140+
browser: chrome
141+
# Screenshots are only captured on failure, will change this once we do visual regression tests
142+
- uses: actions/upload-artifact@v4
143+
if: failure()
144+
with:
145+
name: cypress-screenshots
146+
path: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin/cypress/screenshots
147+
# Test run video was always captured, so this action uses "always()" condition
148+
- uses: actions/upload-artifact@v4
149+
if: always()
150+
with:
151+
name: cypress-videos
152+
path: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin/cypress/videos
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: E2E tests workflow
2+
on:
3+
pull_request:
4+
branches:
5+
- "*"
6+
push:
7+
branches:
8+
- "*"
9+
env:
10+
OPENSEARCH_DASHBOARDS_VERSION: '2.x'
11+
jobs:
12+
tests:
13+
name: Run Cypress E2E tests with security
14+
runs-on: ubuntu-latest
15+
env:
16+
# prevents extra Cypress installation progress messages
17+
CI: 1
18+
# avoid warnings like "tput: No value for $TERM and no -T specified"
19+
TERM: xterm
20+
steps:
21+
- name: Checkout Branch
22+
uses: actions/checkout@v3
23+
- id: run-cypress-tests
24+
uses: ./.github/actions/run-cypress-tests
25+
with:
26+
with-security: true

.github/workflows/cypress-workflow.yml

+5-72
Original file line numberDiff line numberDiff line change
@@ -18,76 +18,9 @@ jobs:
1818
# avoid warnings like "tput: No value for $TERM and no -T specified"
1919
TERM: xterm
2020
steps:
21-
- name: Set up JDK
22-
uses: actions/setup-java@v1
21+
- name: Checkout Branch
22+
uses: actions/checkout@v3
23+
- id: run-cypress-tests
24+
uses: ./.github/actions/run-cypress-tests
2325
with:
24-
# TODO: Parse this from index management plugin
25-
java-version: 21
26-
- name: Checkout index management
27-
uses: actions/checkout@v2
28-
with:
29-
path: index-management
30-
repository: opensearch-project/index-management
31-
ref: '2.x'
32-
- name: Run opensearch with plugin
33-
run: |
34-
cd index-management
35-
./gradlew run &
36-
sleep 300
37-
# timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done'
38-
- name: Checkout Index Management Dashboards plugin
39-
uses: actions/checkout@v2
40-
with:
41-
path: index-management-dashboards-plugin
42-
- name: Checkout OpenSearch-Dashboards
43-
uses: actions/checkout@v2
44-
with:
45-
repository: opensearch-project/OpenSearch-Dashboards
46-
path: OpenSearch-Dashboards
47-
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
48-
- name: Setup Node
49-
uses: actions/setup-node@v3
50-
with:
51-
node-version-file: './OpenSearch-Dashboards/.nvmrc'
52-
registry-url: 'https://registry.npmjs.org'
53-
- name: Install Yarn
54-
# Need to use bash to avoid having a windows/linux specific step
55-
shell: bash
56-
run: |
57-
YARN_VERSION=$(node -p "require('./OpenSearch-Dashboards/package.json').engines.yarn")
58-
echo "Installing yarn@$YARN_VERSION"
59-
npm i -g yarn@$YARN_VERSION
60-
- run: node -v
61-
- run: yarn -v
62-
- name: Bootstrap plugin/OpenSearch-Dashboards
63-
run: |
64-
mkdir -p OpenSearch-Dashboards/plugins
65-
mv index-management-dashboards-plugin OpenSearch-Dashboards/plugins
66-
cd OpenSearch-Dashboards/plugins/index-management-dashboards-plugin
67-
yarn osd bootstrap
68-
- name: Run OpenSearch-Dashboards server
69-
run: |
70-
cd OpenSearch-Dashboards
71-
yarn start --no-base-path --no-watch --server.host="0.0.0.0" &
72-
sleep 300
73-
# timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done'
74-
# for now just chrome, use matrix to do all browsers later
75-
- name: Cypress tests
76-
uses: cypress-io/github-action@v2
77-
with:
78-
working-directory: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin
79-
command: yarn run cypress run
80-
wait-on: 'http://localhost:5601'
81-
browser: chrome
82-
# Screenshots are only captured on failure, will change this once we do visual regression tests
83-
- uses: actions/upload-artifact@v4
84-
if: failure()
85-
with:
86-
name: cypress-screenshots
87-
path: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin/cypress/screenshots
88-
# Test run video was always captured, so this action uses "always()" condition
89-
- uses: actions/upload-artifact@v4
90-
if: always()
91-
with:
92-
name: cypress-videos
93-
path: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin/cypress/videos
26+
with-security: false

cypress.config.js

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const { defineConfig } = require("cypress");
2-
const fs = require("fs");
3-
const path = require("path");
42

53
module.exports = defineConfig({
64
e2e: {
@@ -17,16 +15,33 @@ module.exports = defineConfig({
1715
username: "admin",
1816
password: "admin",
1917
},
18+
clientCertificates: [
19+
{
20+
url: "https://localhost:9200/.opendistro-ism*",
21+
ca: ["cypress/resources/root-ca.pem"],
22+
certs: [
23+
{
24+
cert: "cypress/resources/kirk.pem",
25+
key: "cypress/resources/kirk-key.pem",
26+
passphrase: "",
27+
},
28+
],
29+
},
30+
{
31+
url: "https://localhost:9200/.opendistro-ism-config/_update_by_query/",
32+
ca: ["cypress/resources/root-ca.pem"],
33+
certs: [
34+
{
35+
cert: "cypress/resources/kirk.pem",
36+
key: "cypress/resources/kirk-key.pem",
37+
passphrase: "",
38+
},
39+
],
40+
},
41+
],
2042
setupNodeEvents(on, config) {
21-
on("task", {
22-
readCertAndKey() {
23-
const cert = fs.readFileSync(path.resolve(__dirname, "cypress/resources/kirk.pem"));
24-
const key = fs.readFileSync(path.resolve(__dirname, "cypress/resources/kirk-key.pem"));
25-
return { cert, key };
26-
},
27-
});
2843
// implement node event listeners here
2944
return config;
3045
},
3146
},
32-
});
47+
});

cypress/resources/root-ca.pem

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIExjCCA66gAwIBAgIUDWQJmWZ9xBTsQUeOt9F5YSPpqOIwDQYJKoZIhvcNAQEL
3+
BQAwgY8xEzARBgoJkiaJk/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFt
4+
cGxlMRkwFwYDVQQKDBBFeGFtcGxlIENvbSBJbmMuMSEwHwYDVQQLDBhFeGFtcGxl
5+
IENvbSBJbmMuIFJvb3QgQ0ExITAfBgNVB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Q29tIEluYy4gUm9vdCBDQYIUDWQJmWZ9xBTsQUeOt9F5YSPpqOIwDQYJKoZIhvcN
22+
AQELBQADggEBAL3Q3AHUhMiLUy6OlLSt8wX9I2oNGDKbBu0atpUNDztk/0s3YLQC
23+
YuXgN4KrIcMXQIuAXCx407c+pIlT/T1FNn+VQXwi56PYzxQKtlpoKUL3oPQE1d0V
24+
6EoiNk+6UodvyZqpdQu7fXVentRMk1QX7D9otmiiNuX+GSxJhJC2Lyzw65O9EUgG
25+
1yVJon6RkUGtqBqKIuLksKwEr//ELnjmXit4LQKSnqKr0FTCB7seIrKJNyb35Qnq
26+
qy9a/Unhokrmdda1tr6MbqU8l7HmxLuSd/Ky+L0eDNtYv6YfMewtjg0TtAnFyQov
27+
rdXmeq1dy9HLo3Ds4AFz3Gx9076TxcRS/iI=
28+
-----END CERTIFICATE-----

cypress/utils/commands.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,7 @@ Cypress.Commands.add("login", () => {
9999
Cypress.Commands.add("deleteAllIndices", () => {
100100
cy.log("Deleting all indexes");
101101
cy.request("DELETE", `${Cypress.env("openSearchUrl")}/test_index_*,index*,sample*,opensearch_dashboards*`);
102-
cy.task("readCertAndKey").then(({ cert, key }) => {
103-
cy.request({
104-
method: "DELETE",
105-
url: `${Cypress.env("openSearchUrl")}/.opendistro-ism*?expand_wildcards=all`,
106-
headers: {},
107-
agentOptions: {
108-
cert,
109-
key,
110-
},
111-
});
112-
});
102+
cy.request("DELETE", `${Cypress.env("openSearchUrl")}/.opendistro-ism*?expand_wildcards=all`);
113103
});
114104

115105
Cypress.Commands.add("deleteADSystemIndices", () => {

cypress/utils/plugins/index-management-dashboards-plugin/commands.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Cypress.Commands.add("updateManagedIndexConfigStartTime", (index) => {
4444
source: `ctx._source['managed_index']['schedule']['interval']['start_time'] = ${startTime}L`,
4545
},
4646
};
47-
cy.request("POST", `${Cypress.env("openSearchUrl")}/${IM_CONFIG_INDEX.OPENDISTRO_ISM_CONFIG}/_update_by_query`, body);
47+
cy.request("POST", `${Cypress.env("openSearchUrl")}/${IM_CONFIG_INDEX.OPENDISTRO_ISM_CONFIG}/_update_by_query/`, body);
4848
});
4949
});
5050

0 commit comments

Comments
 (0)