Skip to content

Commit

Permalink
[RORDEV-1257] refactoring (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
coutoPL authored Oct 7, 2024
1 parent 0b75e9a commit f4a6159
Show file tree
Hide file tree
Showing 77 changed files with 1,151 additions and 691 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/trigger-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ jobs:
e2e-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: [8x, 7x]
version: ["8.15.2", "7.17.24"]
env: [docker]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Run tests
run: ./run-${{ matrix.version }}.sh
run: ./run-env-and-tests.sh ${{ matrix.version }} ${{ matrix.env }}
env:
ROR_ACTIVATION_KEY: ${{ secrets.ROR_KBN_LICENSE }}
- name: S3 Upload Videos & show logs
Expand All @@ -27,4 +33,5 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws configure set region eu-west-1
aws s3 cp results/videos/ s3://readonlyrest-data/e2e-tests/build_${{ github.run_id }}/${{ matrix.version }}/ --recursive
aws s3 cp results/videos/ s3://readonlyrest-data/e2e-tests/build_${{ github.run_id }}/${{ matrix.env }}/${{ matrix.version }}/ --recursive
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
elk-ror/elk-ror.log
**/.DS_Store
.idea
environments/**/*.log
environments/**/*.zip
environments/**/plugins
e2e-tests/node_modules
plugins/*
results/*
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Prerequisites:
To bootstrap a Docker-based test environment (ES with latest ROR + KBN with latest ROR) and run Cypress E2E tests run:

```bash
$ ./run-8x.sh
./run-env-and-tests.sh 8.15.2 docker
```

```bash
$ ./run-7x.sh
./run-env-and-tests.sh 7.17.24 docker
```

#### Tested environment & E2E tests separately
Expand All @@ -26,18 +26,18 @@ You can bootstrap the test env and run tests separately (to not build the ES+KBN

To run the env:
```bash
$ ./elk-ror/run.sh --es "8.10.0" --kbn "8.10.0"
./environments/elk-ror/start.sh --es "8.15.0" --kbn "8.15.2"
```

To run tests on the env:
```bash
$ ./e2e-tests/run.sh "8.10.0"
$ ./e2e-tests/run-tests.sh "8.15.2"
```

#### Cypress tests in interactive GUI

```bash
$ cd e2e-tests; yarn cypress open
$ cd e2e-tests; yarn cypress open --env kibanaVersion=[KBN_VERSION]
```

### In docker isolated environment
Expand All @@ -61,7 +61,7 @@ $ ./docker-based-ror-dev-env/runE2ETests7xInDocker.sh

### Test environment

The test environment is created with the Docker Compose. All code is located in the `elk-ror` folder. Currently, the latest version of ROR is downloaded for the sake of tests. In the future, we are going to improve it and build plugins from sources too.
The test environment is created with the Docker Compose. All code is located in the `environments/elk-ror` folder. Currently, the latest version of ROR is downloaded for the sake of tests. In the future, we are going to improve it and build plugins from sources too.

### Cypress tests

Expand Down
6 changes: 2 additions & 4 deletions docker-based-ror-dev-env/runInDocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ fi
docker run --rm $DIND_OPTIONS $DOCKER_RUN_OPTIONS \
-e ROR_ACTIVATION_KEY="$ROR_ACTIVATION_KEY" \
-v ./../e2e-tests:/app/e2e-tests \
-v ./../elk-ror:/app/elk-ror \
-v ./../enviroments/elk-ror:/app/enviroments/elk-ror \
-v ./../results:/app/results \
-v ./../run.sh:/app/run.sh \
-v ./../run-7x.sh:/app/run-7x.sh \
-v ./../run-8x.sh:/app/run-8x.sh \
-v ./../run-env-and-tests.sh:/app/run-env-and-tests.sh \
e2e-tests-dev-env:"$DOCKER_BASED_ROR_DEV_ENV_HASH" "$COMMAND"
4 changes: 2 additions & 2 deletions docker-based-ror-dev-env/src/processRorEnvCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ npm i -g yarn

case "$1" in
e2e-tests-7x )
/app/run-7x.sh
/app/run-env-and-tests.sh "7.17.24" "docker"
;;
e2e-tests-8x )
/app/run-8x.sh
/app/run-env-and-tests.sh "8.15.2" "docker"
;;
bash )
bash
Expand Down
8 changes: 4 additions & 4 deletions e2e-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default defineConfig({
login: 'admin',
password: 'dev',
kibanaVersion: 'KIBANA_VERSION_NOT_SET_YET',
elasticsearchUrl: 'http://localhost:19200',
elasticsearchUrl: 'https://localhost:9200',
enterpriseActivationKey: 'PROVIDE_YOUR_ACTIVATION_KEY',
kibanaUserCredentials: "kibana:kibana"
kibanaUserCredentials: 'kibana:kibana'
},
video: true,
screenshotOnRunFailure: true,
Expand All @@ -28,9 +28,9 @@ export default defineConfig({
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
// eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
return require('./cypress/plugins/index.js')(on, config);
return require('./cypress/plugins/index.ts')(on, config);
},
baseUrl: 'http://localhost:5601',
baseUrl: 'https://localhost:5601',
videosFolder: '../results/videos',
screenshotsFolder: '../results/screenshots'
}
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/e2e/Activation-keys.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe.skip('Activation key', () => {

afterEach(() => {
cy.kbnPost({
endpoint: "api/ror/license?overwrite=true",
endpoint: 'api/ror/license?overwrite=true',
credentials: userCredentials,
payload: { license: `${Cypress.env().enterpriseActivationKey}` }
});
Expand Down
80 changes: 42 additions & 38 deletions e2e-tests/cypress/e2e/Direct-kibana-request.cy.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,58 @@
import * as semver from 'semver';
import { getKibanaVersion, userCredentials } from '../support/helpers';
import { kbnApiAdvancedClient } from '../support/helpers/KbnApiAdvancedClient';
import { rorApiClient } from '../support/helpers/RorApiClient';

describe('Direct kibana request', () => {
const user = 'user1:dev';
const user1 = 'user1:dev';
const admin = 'admin:dev';

afterEach(() => {
const clearDirectKibanaRequestState = () => {
kbnApiAdvancedClient.deleteSavedObjects(user);
if (semver.gte(getKibanaVersion(), '8.0.0')) {
kbnApiAdvancedClient.deleteDataViews(user);
}
};
beforeEach(() => {
clearDirectKibanaRequestState();
rorApiClient.configureRorIndexMainSettings('defaultSettings.yaml');
});

afterEach(() => {
clearDirectKibanaRequestState();
rorApiClient.configureRorIndexMainSettings('defaultSettings.yaml');
});

it('should check direct kibana request', () => {
const verifySavedObjects = () => {
kbnApiAdvancedClient.deleteSavedObjects(user);
kbnApiAdvancedClient.deleteSavedObjects(user1);

cy.log('Import saved objects for user1');
cy.kbnImport({
endpoint: "api/saved_objects/_import?overwrite=true",
credentials: user,
filename: 'cypress/fixtures/file.ndjson'
endpoint: 'api/saved_objects/_import?overwrite=true',
credentials: user1,
fixtureFilename: 'file.ndjson'
});

cy.log('Get imported saved objects for user1 Administrators group');
kbnApiAdvancedClient.getSavedObjects(user).then(result => {
kbnApiAdvancedClient.getSavedObjects(user1).then(result => {
expect(result.saved_objects[0].id).equal('my-pattern');
expect(result.saved_objects[1].id).equal('my-dashboard');
})
expect(result.saved_objects).to.have.length(2);
});

cy.log('Get imported saved objects for admin Administrators group');
kbnApiAdvancedClient
.getSavedObjects(userCredentials)
.then(result => {
expect(result.saved_objects[0].id).equal('my-pattern');
expect(result.saved_objects[1].id).equal('my-dashboard');
expect(result.saved_objects).to.have.length(2);
});
kbnApiAdvancedClient.getSavedObjects(admin).then(result => {
expect(result.saved_objects[0].id).equal('my-pattern');
expect(result.saved_objects[1].id).equal('my-dashboard');
expect(result.saved_objects).to.have.length(2);
});

cy.log('Get imported saved objects for user1 infosec group');
kbnApiAdvancedClient.getSavedObjects(user, "infosec_group")
.then(result => {
const actual = result.saved_objects.some(
saved_object => saved_object.id === 'my-pattern' || saved_object.id === 'my-dashboard'
);
// eslint-disable-next-line no-unused-expressions
expect(actual).to.be.false;
});
kbnApiAdvancedClient.getSavedObjects(user1, 'infosec_group').then(result => {
const actual = result.saved_objects.some(
saved_object => saved_object.id === 'my-pattern' || saved_object.id === 'my-dashboard'
);
expect(actual).to.be.false;
});
};

const verifyDataViews = () => {
kbnApiAdvancedClient.deleteDataViews(user);
kbnApiAdvancedClient.deleteDataViews(user1);
cy.log('Create data_views for user1 Administrators group');
kbnApiAdvancedClient.createDataView(
{
Expand All @@ -64,22 +62,28 @@ describe('Direct kibana request', () => {
name: 'My Logstash Data View'
}
},
user
user1
);

cy.log('get all data_views for user1 infosec group');
kbnApiAdvancedClient
.getDataViews(userCredentials, "infosec_group")
.then(result => {
const actual = result.data_view.some(saved_object => saved_object.id === 'logstash');
// eslint-disable-next-line no-unused-expressions
expect(actual).to.be.false;
});
kbnApiAdvancedClient.getDataViews(userCredentials, 'infosec_group').then(result => {
const actual = result.data_view.some(saved_object => saved_object.id === 'logstash');
expect(actual).to.be.false;
});
};

verifySavedObjects();
if (semver.gte(getKibanaVersion(), '8.0.0')) {
verifyDataViews();
}
});

const clearDirectKibanaRequestState = () => {
kbnApiAdvancedClient.deleteSavedObjects(user1);
kbnApiAdvancedClient.deleteSavedObjects(admin);
if (semver.gte(getKibanaVersion(), '8.0.0')) {
kbnApiAdvancedClient.deleteDataViews(user1);
kbnApiAdvancedClient.deleteDataViews(admin);
}
};
});
4 changes: 2 additions & 2 deletions e2e-tests/cypress/e2e/Impersonate.cy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Login } from '../support/page-objects/Login';
import { Impersonate } from '../support/page-objects/Impersonate';
import { SecuritySettings } from '../support/page-objects/SecuritySettings';
import { KibanaNavigation } from '../support/page-objects/KibanaNavigation';
import { TestSettings } from '../support/page-objects/TestSettings';
import { Settings } from '../support/page-objects/Settings';
import { rorApiClient } from '../support/helpers/RorApiClient';

describe('impersonate', () => {
beforeEach(() => {
Expand All @@ -26,6 +25,7 @@ describe('impersonate', () => {
cy.log('should check service lists rendering');

Impersonate.setTestSettingsData();

TestSettings.open();
Impersonate.open();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { Login } from '../support/page-objects/Login';
import { Loader } from '../support/page-objects/Loader';
import { RorMenu } from '../support/page-objects/RorMenu';
import { Discover } from '../support/page-objects/Discover';
import defaultSettingsData from '../fixtures/defaultSettings.json';
import reportingSettingsData from '../fixtures/reportingSettings.json';
import { Settings } from '../support/page-objects/Settings';

describe('Reporting index', () => {
// todo: the test fails. Please fix me
describe.skip('Reporting index', () => {
beforeEach(() => {
Settings.setSettingsData(reportingSettingsData);
Settings.setSettingsData('reportingSettings.yaml');
cy.visit(Cypress.config().baseUrl);
cy.on('url:changed', () => {
sessionStorage.setItem('ror:ignoreTrialInfo', 'true');
Expand All @@ -19,7 +18,7 @@ describe('Reporting index', () => {
});

afterEach(() => {
Settings.setSettingsData(defaultSettingsData);
Settings.setSettingsData('defaultSettings.yaml');
});

it('should correctly match index pattern when audit index_template contains .reporting', () => {
Expand Down
10 changes: 4 additions & 6 deletions e2e-tests/cypress/e2e/Sanity-check-ro-kibana-access.cy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Login } from '../support/page-objects/Login';
import { RoAndRoStrictKibanaAccessAssertions } from '../support/page-objects/RoAndRoStrictKibanaAccessAssertions';
import roSettings from '../fixtures/roSettings.json';
import { Settings } from '../support/page-objects/Settings';
import defaultSettings from '../fixtures/defaultSettings.json';
import { kbnApiClient, KbnApiClient } from '../support/helpers/KbnApiClient';
import { kbnApiClient } from '../support/helpers/KbnApiClient';
import { userCredentials } from '../support/helpers';

describe('sanity check ro kibana access', () => {
Expand All @@ -12,11 +10,11 @@ describe('sanity check ro kibana access', () => {
});

afterEach(() => {
Settings.setSettingsData(defaultSettings);
kbnApiClient.deleteSampleData("ecommerce", userCredentials, "template_group");
Settings.setSettingsData('defaultSettings.yaml');
kbnApiClient.deleteSampleData('ecommerce', userCredentials, 'template_group');
});

it('should verify that everything works', () => {
RoAndRoStrictKibanaAccessAssertions.runAssertions(roSettings);
RoAndRoStrictKibanaAccessAssertions.runAssertions('roSettings.yaml');
});
});
10 changes: 4 additions & 6 deletions e2e-tests/cypress/e2e/Sanity-check-ro_strict-kibana-access.cy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Login } from '../support/page-objects/Login';
import { RoAndRoStrictKibanaAccessAssertions } from '../support/page-objects/RoAndRoStrictKibanaAccessAssertions';
import roStrictSettings from '../fixtures/roStrictSettings.json';
import { Settings } from '../support/page-objects/Settings';
import defaultSettings from '../fixtures/defaultSettings.json';
import { kbnApiClient, KbnApiClient } from '../support/helpers/KbnApiClient';
import { kbnApiClient } from '../support/helpers/KbnApiClient';
import { userCredentials } from '../support/helpers';

describe('sanity check ro_strict kibana access', () => {
Expand All @@ -12,11 +10,11 @@ describe('sanity check ro_strict kibana access', () => {
});

afterEach(() => {
Settings.setSettingsData(defaultSettings);
kbnApiClient.deleteSampleData("ecommerce", userCredentials, "template_group");
Settings.setSettingsData('defaultSettings.yaml');
kbnApiClient.deleteSampleData('ecommerce', userCredentials, 'template_group');
});

it('should verify that everything works', () => {
RoAndRoStrictKibanaAccessAssertions.runAssertions(roStrictSettings);
RoAndRoStrictKibanaAccessAssertions.runAssertions('roStrictSettings.yaml');
});
});
8 changes: 4 additions & 4 deletions e2e-tests/cypress/e2e/Sanity-check.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { SampleData } from '../support/helpers/SampleData';

describe('sanity check', () => {
beforeEach(() => {
SampleData.createSampleData("sample_index", 1)
SampleData.createSampleData('sample_index', 1);
Login.initialization();
});

afterEach(() => {
esApiAdvancedClient.deleteIndex("sample_index");
kbnApiAdvancedClient.deleteSavedObjects("admin:dev");
kbnApiAdvancedClient.deleteSavedObjects("admin:dev", "infosec_group")
esApiAdvancedClient.deleteIndex('sample_index');
kbnApiAdvancedClient.deleteSavedObjects('admin:dev');
kbnApiAdvancedClient.deleteSavedObjects('admin:dev', 'infosec_group');
esApiAdvancedClient.pruneAllReportingIndices();
});

Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/e2e/Saved-objects.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Saved objects', () => {
});

afterEach(() => {
kbnApiAdvancedClient.deleteSavedObjects("admin:dev");
kbnApiAdvancedClient.deleteSavedObjects('admin:dev');
});

it('should display saved objects list', () => {
Expand Down
3 changes: 0 additions & 3 deletions e2e-tests/cypress/fixtures/defaultSettings.json

This file was deleted.

Loading

0 comments on commit f4a6159

Please sign in to comment.