From 3f24c89b588b626c834dc11e4a6ed540fa1696c6 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Wed, 21 Dec 2022 15:57:25 -0800 Subject: [PATCH 1/7] added windows to cypress test runs Signed-off-by: Amardeepsingh Siglani --- .github/workflows/cypress-workflow.yml | 37 +++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index e34683360..d592ff4eb 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -13,7 +13,10 @@ env: jobs: tests: name: Run Cypress E2E tests - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} env: # prevents extra Cypress installation progress messages CI: 1 @@ -25,55 +28,81 @@ jobs: with: # TODO: Parse this from security analytics plugin (https://github.com/opensearch-project/security-analytics/issues/170) java-version: 11 + + - name: Enable longer filenames + if: ${{ matrix.os == 'windows-latest' }} + run: git config --system core.longpaths true + - name: Checkout security analytics uses: actions/checkout@v2 with: path: security-analytics repository: opensearch-project/security-analytics ref: ${{ env.SECURITY_ANALYTICS_BRANCH }} + - name: Run opensearch with plugin run: | cd security-analytics ./gradlew run -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} & sleep 300 # timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done' + - name: Checkout Security Analytics Dashboards plugin uses: actions/checkout@v2 with: path: security-analytics-dashboards-plugin + - name: Checkout OpenSearch-Dashboards uses: actions/checkout@v2 with: repository: opensearch-project/OpenSearch-Dashboards path: OpenSearch-Dashboards ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }} + - name: Get node and yarn versions id: versions run: | echo "::set-output name=node_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.node).match(/[.0-9]+/)[0]")" echo "::set-output name=yarn_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.yarn).match(/[.0-9]+/)[0]")" + - name: Setup node uses: actions/setup-node@v1 with: node-version: ${{ steps.versions.outputs.node_version }} registry-url: 'https://registry.npmjs.org' + - name: Install correct yarn version for OpenSearch-Dashboards run: | npm uninstall -g yarn echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}" npm i -g yarn@${{ steps.versions.outputs.yarn_version }} + + - name: Set npm to use bash for shell + if: ${{ matrix.os == 'windows-latest' }} + run: | + # Sets Windows to use bash for npm shell so the script commands work as intended + npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe" + - name: Bootstrap plugin/OpenSearch-Dashboards run: | mkdir -p OpenSearch-Dashboards/plugins mv security-analytics-dashboards-plugin OpenSearch-Dashboards/plugins cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin yarn osd bootstrap + - name: Run OpenSearch-Dashboards server run: | cd OpenSearch-Dashboards yarn start --no-base-path --no-watch & sleep 300 # timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done' + + - name: Reset npm's script shell + if: ${{ matrix.os == 'windows-latest' }} + run: | + # Resetting npm's script shell for Windows so `yarn run cypress` doesn't have conflicts + npm config delete script-shell + # for now just chrome, use matrix to do all browsers later - name: Cypress tests uses: cypress-io/github-action@v2 @@ -82,15 +111,17 @@ jobs: command: yarn run cypress run wait-on: 'http://localhost:5601' browser: chrome + # Screenshots are only captured on failure, will change this once we do visual regression tests - uses: actions/upload-artifact@v1 if: failure() with: - name: cypress-screenshots + name: cypress-screenshots-${{ matrix.os }} path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin/cypress/screenshots + # Test run video was always captured, so this action uses "always()" condition - uses: actions/upload-artifact@v1 if: always() with: - name: cypress-videos + name: cypress-videos-${{ matrix.os }} path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin/cypress/videos From ef59b99c5fd6e2991047a9313380a542aea58073 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Thu, 22 Dec 2022 11:23:13 -0800 Subject: [PATCH 2/7] clong security analytics dashboars repo directly into the plugins directory in OSD Signed-off-by: Amardeepsingh Siglani --- .github/workflows/cypress-workflow.yml | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index d592ff4eb..50ef39211 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -47,11 +47,6 @@ jobs: sleep 300 # timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done' - - name: Checkout Security Analytics Dashboards plugin - uses: actions/checkout@v2 - with: - path: security-analytics-dashboards-plugin - - name: Checkout OpenSearch-Dashboards uses: actions/checkout@v2 with: @@ -59,6 +54,11 @@ jobs: path: OpenSearch-Dashboards ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }} + - name: Checkout Security Analytics Dashboards plugin + uses: actions/checkout@v2 + with: + path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin + - name: Get node and yarn versions id: versions run: | @@ -76,17 +76,9 @@ jobs: npm uninstall -g yarn echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}" npm i -g yarn@${{ steps.versions.outputs.yarn_version }} - - - name: Set npm to use bash for shell - if: ${{ matrix.os == 'windows-latest' }} - run: | - # Sets Windows to use bash for npm shell so the script commands work as intended - npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe" - name: Bootstrap plugin/OpenSearch-Dashboards run: | - mkdir -p OpenSearch-Dashboards/plugins - mv security-analytics-dashboards-plugin OpenSearch-Dashboards/plugins cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin yarn osd bootstrap @@ -97,12 +89,6 @@ jobs: sleep 300 # timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done' - - name: Reset npm's script shell - if: ${{ matrix.os == 'windows-latest' }} - run: | - # Resetting npm's script shell for Windows so `yarn run cypress` doesn't have conflicts - npm config delete script-shell - # for now just chrome, use matrix to do all browsers later - name: Cypress tests uses: cypress-io/github-action@v2 From 9d9e106b9c380cc947a56a84f2b10c07c3ea84a1 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Thu, 22 Dec 2022 11:53:19 -0800 Subject: [PATCH 3/7] caching cypress binary Signed-off-by: Amardeepsingh Siglani --- .github/workflows/cypress-workflow.yml | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index 50ef39211..457ecee6e 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -16,6 +16,11 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] + include: + - os: windows-latest + cypress_cache_folder: ~/AppData/Local/Cypress/Cache + - os: ubuntu-latest + cypress_cache_folder: ~/.cache/Cypress runs-on: ${{ matrix.os }} env: # prevents extra Cypress installation progress messages @@ -86,9 +91,40 @@ jobs: run: | cd OpenSearch-Dashboards yarn start --no-base-path --no-watch & - sleep 300 # timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done' + # Window is slow so wait longer + - name: Sleep until OSD server starts - windows + if: ${{ matrix.os == 'windows-latest' }} + run: Start-Sleep -s 400 + shell: powershell + + - name: Sleep until OSD server starts - non-windows + if: ${{ matrix.os != 'windows-latest' }} + run: sleep 300 + shell: bash + + - name: Install Cypress + run: | + cd OpenSearch-Dashboards/plugins/custom_import_map + # This will install Cypress in case the binary is missing which can happen on Windows and Mac + # If the binary exists, this will exit quickly so it should not be an expensive operation + npx cypress install + shell: bash + + - name: Get Cypress version + id: cypress_version + run: | + cd OpenSearch-Dashboards/plugins/custom_import_map + echo "::set-output name=cypress_version::$(cat ./package.json | jq '.dependencies.cypress' | tr -d '"')" + + - name: Cache Cypress + id: cache-cypress + uses: actions/cache@v2 + with: + path: ${{ matrix.cypress_cache_folder }} + key: cypress-cache-v2-${{ runner.os }}-${{ hashFiles('**/package.json') }} + # for now just chrome, use matrix to do all browsers later - name: Cypress tests uses: cypress-io/github-action@v2 @@ -97,6 +133,8 @@ jobs: command: yarn run cypress run wait-on: 'http://localhost:5601' browser: chrome + env: + CYPRESS_CACHE_FOLDER: ${{ matrix.cypress_cache_folder }} # Screenshots are only captured on failure, will change this once we do visual regression tests - uses: actions/upload-artifact@v1 From 093ae06fe30ce5ba118425fb44e705f5b250e9e4 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Thu, 22 Dec 2022 14:39:24 -0800 Subject: [PATCH 4/7] fixed cypress install repo Signed-off-by: Amardeepsingh Siglani --- .github/workflows/cypress-workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index 457ecee6e..d81b9dd33 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -106,7 +106,7 @@ jobs: - name: Install Cypress run: | - cd OpenSearch-Dashboards/plugins/custom_import_map + cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin # This will install Cypress in case the binary is missing which can happen on Windows and Mac # If the binary exists, this will exit quickly so it should not be an expensive operation npx cypress install @@ -115,7 +115,7 @@ jobs: - name: Get Cypress version id: cypress_version run: | - cd OpenSearch-Dashboards/plugins/custom_import_map + cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin echo "::set-output name=cypress_version::$(cat ./package.json | jq '.dependencies.cypress' | tr -d '"')" - name: Cache Cypress From d2d795a62e2b26400790be516461223fd2cedeab Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Mon, 26 Dec 2022 14:59:45 +0530 Subject: [PATCH 5/7] using bash to run osd server Signed-off-by: Amardeepsingh Siglani --- .github/workflows/cypress-workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index d81b9dd33..de4c5142e 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -92,6 +92,7 @@ jobs: cd OpenSearch-Dashboards yarn start --no-base-path --no-watch & # timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done' + shell: bash # Window is slow so wait longer - name: Sleep until OSD server starts - windows From f4c8dd88a36150505e2bd2350c86768d6df2b088 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Mon, 26 Dec 2022 15:32:13 +0530 Subject: [PATCH 6/7] using bash to run os server Signed-off-by: Amardeepsingh Siglani --- .github/workflows/cypress-workflow.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index de4c5142e..02b36849f 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -50,7 +50,7 @@ jobs: cd security-analytics ./gradlew run -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} & sleep 300 - # timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done' + shell: bash - name: Checkout OpenSearch-Dashboards uses: actions/checkout@v2 @@ -91,7 +91,6 @@ jobs: run: | cd OpenSearch-Dashboards yarn start --no-base-path --no-watch & - # timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done' shell: bash # Window is slow so wait longer From 0192ed31ca82ac4ad90d275edca0c31d3594832b Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Mon, 26 Dec 2022 17:07:09 +0530 Subject: [PATCH 7/7] inceased timeout for fetching rules in create detector Signed-off-by: Amardeepsingh Siglani --- cypress/integration/1_detectors.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/1_detectors.spec.js b/cypress/integration/1_detectors.spec.js index 65d1027f2..701b3a125 100644 --- a/cypress/integration/1_detectors.spec.js +++ b/cypress/integration/1_detectors.spec.js @@ -62,7 +62,7 @@ describe('Detectors', () => { cy.get(`[placeholder="Search..."]`).type('USB Device Plugged').trigger('search'); // Disable all rules - cy.contains('tr', 'USB Device Plugged', { timeout: 20000 }); + cy.contains('tr', 'USB Device Plugged', { timeout: 60000 }); cy.get('th').within(() => { cy.get('button').first().click({ force: true }); });