Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions .cypress/integration/1_detectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,22 @@ describe('Detectors', () => {
// Create test index
cy.createIndex(cypressIndexDns, sample_dns_index_settings).then(() =>
cy
.request('POST', '_plugins/_security_analytics/rules/_search?prePackaged=true', {
from: 0,
size: 5000,
query: {
nested: {
path: 'rule',
query: { bool: { must: [{ match: { 'rule.category': 'dns' } }] } },
.request(
'POST',
`${Cypress.env(
'opensearch_url'
)}/_plugins/_security_analytics/rules/_search?pre_packaged=true`,
{
from: 0,
size: 5000,
query: {
nested: {
path: 'rule',
query: { bool: { must: [{ match: { 'rule.category': 'dns' } }] } },
},
},
},
})
}
)
.should('have.property', 'status', 200)
);

Expand Down
2 changes: 1 addition & 1 deletion .cypress/integration/2_rules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ describe('Rules', () => {

it('...can be imported with log type', () => {
getImportButton().click({ force: true });
getImportRuleFilePicker().selectFile('./cypress/fixtures/sample_aws_s3_rule_to_import.yml');
getImportRuleFilePicker().selectFile('./.cypress/fixtures/sample_aws_s3_rule_to_import.yml');
// Check that AWS S3 log type is set.
cy.contains('AWS S3');
});
Expand Down
4 changes: 4 additions & 0 deletions .cypress/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Cypress.Commands.add(
Cypress.log({ message: `Select combobox items: ${items.join(' | ')}` });
items.map((item) => {
cy.wrap(subject).type(item);

// Short wait to reduce flakiness
cy.wait(3000);

cy.get(`[title="${item}"]`).click({ force: true });
});
}
Expand Down
37 changes: 25 additions & 12 deletions .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,56 @@ env:
GRADLE_VERSION: '7.6.1'
jobs:
tests:
name: Run Cypress E2E tests
strategy:
# This setting says that all jobs should finish, even if one fails
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
include:
- os: windows-latest
os_build_args: -x integTest
cypress_cache_folder: ~/AppData/Local/Cypress/Cache
working_directory: X:\
os_java_options: -Xmx4096M
- os: ubuntu-latest
cypress_cache_folder: ~/.cache/Cypress
runs-on: ${{ matrix.os }}
env:
# prevents extra Cypress installation progress messages
CI: 1
# avoid warnings like "tput: No value for $TERM and no -T specified"
TERM: xterm

name: Run Cypress E2E tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

steps:
- name: Set up JDK
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
distribution: temurin # Temurin is a distribution of adoptium
# TODO: Parse this from security analytics plugin (https://github.com/opensearch-project/security-analytics/issues/170)
java-version: 21

- name: Enable longer filenames
if: ${{ matrix.os == 'windows-latest' }}
run: git config --system core.longpaths true

- name: Checkout security analytics
- name: Checkout security analytics backend
uses: actions/checkout@v2
with:
path: security-analytics
repository: opensearch-project/security-analytics
ref: ${{ env.SECURITY_ANALYTICS_BRANCH }}

- name: Run opensearch with plugin
- name: Set up Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: ${{ env.GRADLE_VERSION }}

- name: Run OpenSearch with plugin
run: |
cd security-analytics
./gradlew run -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} &
./gradlew run -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} -x jacocoTestReport &
sleep 300
shell: bash

Expand Down Expand Up @@ -89,13 +102,16 @@ jobs:
- name: Run OpenSearch-Dashboards server
run: |
cd OpenSearch-Dashboards
yarn start --no-base-path --no-watch --server.host="0.0.0.0" &
yarn start --no-base-path --no-watch --server.host="0.0.0.0" --opensearch.requestTimeout=120000 &
timeout 900 bash -c 'while [[ "$(curl -s http://localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do echo sleeping 5; sleep 5; done'
curl -sk localhost:5601/api/status | jq
netstat -anp tcp | grep LISTEN | grep 5601 || netstat -ntlp | grep 5601
shell: bash

# Window is slow so wait longer
- name: Sleep until OSD server starts - windows
if: ${{ matrix.os == 'windows-latest' }}
run: Start-Sleep -s 450
run: Start-Sleep -s 600
shell: powershell

- name: Sleep until OSD server starts - non-windows
Expand Down Expand Up @@ -123,18 +139,15 @@ jobs:
with:
path: ${{ matrix.cypress_cache_folder }}
key: cypress-cache-v2-${{ runner.os }}-${{ hashFiles('OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin/package.json') }}
restore-keys: |
cypress-cache-v2-${{ runner.os }}-${{ hashFiles('OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin/package.json') }}

# for now just chrome, use matrix to do all browsers later
- name: Cypress tests
- name: Run cypress tests
uses: cypress-io/github-action@v5
with:
working-directory: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
command: yarn run cypress run
wait-on: 'http://localhost:5601'
wait-on-timeout: 300
browser: chrome
env:
CYPRESS_CACHE_FOLDER: ${{ matrix.cypress_cache_folder }}

Expand Down
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = defineConfig({
responseTimeout: 300000,
env: {
opensearch_url: 'localhost:9200',
opensearch_dashboards: 'http://localhost:5601',
opensearch_dashboards: 'localhost:5601',
security_enabled: false,
},
fixturesFolder: '.cypress/fixtures',
Expand All @@ -18,7 +18,7 @@ module.exports = defineConfig({
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./.cypress/plugins/index.js')(on, config);
return require('./.cypress/plugins/index.ts')(on, config);
},
specPattern: '.cypress/integration/*.spec.js',
supportFile: '.cypress/support/index.js',
Expand Down