Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
coutoPL committed Oct 5, 2024
1 parent 57a5e40 commit 0b47186
Show file tree
Hide file tree
Showing 26 changed files with 192 additions and 141 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ elk-ror/elk-ror.log
e2e-tests/node_modules
plugins/*
results/*
**/subst-ror
8 changes: 4 additions & 4 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,12 +26,12 @@ You can bootstrap the test env and run tests separately (to not build the ES+KBN

To run the env:
```bash
$ ./elk-ror/start.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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
kibanaVersion: 'KIBANA_VERSION_NOT_SET_YET',
elasticsearchUrl: 'https://localhost:9200',
enterpriseActivationKey: 'PROVIDE_YOUR_ACTIVATION_KEY',
kibanaUserCredentials: "kibana:kibana"
kibanaUserCredentials: 'kibana:kibana'
},
video: true,
screenshotOnRunFailure: true,
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
46 changes: 21 additions & 25 deletions e2e-tests/cypress/e2e/Direct-kibana-request.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ describe('Direct kibana request', () => {

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

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

it('should check direct kibana request', () => {
Expand All @@ -23,7 +23,7 @@ describe('Direct kibana request', () => {

cy.log('Import saved objects for user1');
cy.kbnImport({
endpoint: "api/saved_objects/_import?overwrite=true",
endpoint: 'api/saved_objects/_import?overwrite=true',
credentials: user1,
fixtureFilename: 'file.ndjson'
});
Expand All @@ -33,25 +33,23 @@ describe('Direct kibana request', () => {
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(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);
});
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(user1, "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'
);
// eslint-disable-next-line no-unused-expressions
expect(actual).to.be.false;
});
};

const verifyDataViews = () => {
Expand All @@ -69,14 +67,12 @@ describe('Direct kibana request', () => {
);

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');
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;
});
// eslint-disable-next-line no-unused-expressions
expect(actual).to.be.false;
});
};

verifySavedObjects();
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/cypress/e2e/Reporting-index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Settings } from '../support/page-objects/Settings';

describe.skip('Reporting index', () => {
beforeEach(() => {
Settings.setSettingsData("reportingSettings.yaml");
Settings.setSettingsData('reportingSettings.yaml');
cy.visit(Cypress.config().baseUrl);
cy.on('url:changed', () => {
sessionStorage.setItem('ror:ignoreTrialInfo', 'true');
Expand All @@ -17,7 +17,7 @@ describe.skip('Reporting index', () => {
});

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

it('should correctly match index pattern when audit index_template contains .reporting', () => {
Expand All @@ -28,4 +28,4 @@ describe.skip('Reporting index', () => {
cy.contains('acl_history:').should('be.visible');
cy.contains(indexPattern).should('be.visible');
});
});
});
6 changes: 3 additions & 3 deletions e2e-tests/cypress/e2e/Sanity-check-ro-kibana-access.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ describe('sanity check ro kibana access', () => {
});

afterEach(() => {
Settings.setSettingsData("defaultSettings.yaml");
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.yaml");
RoAndRoStrictKibanaAccessAssertions.runAssertions('roSettings.yaml');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ describe('sanity check ro_strict kibana access', () => {
});

afterEach(() => {
Settings.setSettingsData("defaultSettings.yaml");
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.yaml");
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
26 changes: 12 additions & 14 deletions e2e-tests/cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions)

const agent: Agent = new Agent({
rejectUnauthorized: false,
secureProtocol: 'TLSv1_2_method',
secureProtocol: 'TLSv1_2_method'
});

try {
const response: Response = await fetch(url, {
method,
headers: headers,
body: body,
agent,
agent
} as RequestInit);

if (!response.ok) {
throw new Error(`HTTP error: ${method} ${url}: HTTP STATUS ${response.status}; Body: ${await response.text()}`)
throw new Error(
`HTTP error: ${method} ${url}: HTTP STATUS ${response.status}; Body: ${await response.text()}`
);
}

const contentType = response.headers.get('content-type') || '';
const data = contentType.includes('application/json')
? await response.json()
: await response.text();
const data = contentType.includes('application/json') ? await response.json() : await response.text();

console.log(`Response: ${method} ${url}: HTTP STATUS ${response.status}; Body: ${data}`) // todo: do we need that?
console.log(`Response: ${method} ${url}: HTTP STATUS ${response.status}; Body: ${data}`); // todo: do we need that?
return data;
} catch (error) {
console.error('HTTP Request failed:', {
error: (error as Error).message,
url,
method,
headers,
body,
body
});
throw error;
}
Expand All @@ -47,7 +47,7 @@ module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions)

const agent: Agent = new Agent({
rejectUnauthorized: false,
secureProtocol: 'TLSv1_2_method',
secureProtocol: 'TLSv1_2_method'
});

const form = new FormData();
Expand All @@ -58,7 +58,7 @@ module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions)

const combinedHeaders: { [key: string]: string } = {
...headers,
...form.getHeaders(),
...form.getHeaders()
};

try {
Expand All @@ -74,9 +74,7 @@ module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions)
}

const contentType = response.headers.get('content-type') || '';
const data = contentType.includes('application/json')
? await response.json()
: await response.text();
const data = contentType.includes('application/json') ? await response.json() : await response.text();

console.log('HTTP Request successful. Response data:', data); // todo: do we need that?
return data;
Expand All @@ -89,7 +87,7 @@ module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions)
});
throw error;
}
},
}
});
};

Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function httpCall(
headers: {
'Content-Type': 'application/json',
authorization: `Basic ${btoa(credentials)}`,
...headers,
...headers
},
body: payload ? JSON.stringify(payload) : null
};
Expand All @@ -119,7 +119,7 @@ function uploadFile(
url,
headers: {
authorization: `Basic ${btoa(credentials)}`,
...headers,
...headers
},
file: {
fileName: fixtureFilename,
Expand Down
Loading

0 comments on commit 0b47186

Please sign in to comment.