Skip to content

Commit

Permalink
YAML Rule Editor Support (opensearch-project#201)
Browse files Browse the repository at this point in the history
* remove unused service

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* refactor form state

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* extract model and mappers

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* Extract Visual Rule Editor Component

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* fix missing default id

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* yaml editor

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* yaml rule editor mappings

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* more mapping guards

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* remove console.log's

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* YAML editor - cypress test

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* yaml editor snapshot test

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* rename model

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* more validations on yaml editor

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* use eui form validation error box

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

* re-generate snapshot

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>
  • Loading branch information
djindjic authored Dec 9, 2022
1 parent eee1258 commit 597f677
Show file tree
Hide file tree
Showing 13 changed files with 923 additions and 274 deletions.
37 changes: 36 additions & 1 deletion cypress/integration/2_rules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import { PLUGIN_NAME, TWENTY_SECONDS_TIMEOUT } from '../support/constants';

const uniqueId = Cypress._.random(0, 1e6);
const SAMPLE_RULE = {
name: 'Cypress test rule',
name: `Cypress test rule ${uniqueId}`,
logType: 'windows',
description: 'This is a rule used to test the rule creation workflow. Not for production use.',
detection:
Expand All @@ -26,6 +27,26 @@ const SAMPLE_RULE = {
status: 'experimental',
};

const YAML_RULE_LINES = [
`title: ${SAMPLE_RULE.name}`,
`description:`,
`${SAMPLE_RULE.description}`,
`level: ${SAMPLE_RULE.severity}`,
`tags:`,
`- ${SAMPLE_RULE.tags[0]}`,
`- ${SAMPLE_RULE.tags[1]}`,
`- ${SAMPLE_RULE.tags[2]}`,
`references:`,
`- '${SAMPLE_RULE.references}'`,
`falsepositives:`,
`- ${SAMPLE_RULE.falsePositive}`,
`author: ${SAMPLE_RULE.author}`,
`status: ${SAMPLE_RULE.status}`,
`logsource:`,
`product: ${SAMPLE_RULE.logType}`,
...SAMPLE_RULE.detection.replaceAll(' ', '').replaceAll('{backspace}', '').split('\n'),
];

describe('Rules', () => {
before(() => {
// Deleting pre-existing test rules
Expand Down Expand Up @@ -93,6 +114,20 @@ describe('Rules', () => {
SAMPLE_RULE.status
);

// Switch to YAML editor
cy.get(
'[data-test-subj="change-editor-type"] label:nth-child(2)',
TWENTY_SECONDS_TIMEOUT
).click({
force: true,
});

YAML_RULE_LINES.forEach((line) =>
cy
.get('[data-test-subj="rule_yaml_editor"]', TWENTY_SECONDS_TIMEOUT)
.contains(line, TWENTY_SECONDS_TIMEOUT)
);

// Click "create" button
cy.get('[data-test-subj="create_rule_button"]', TWENTY_SECONDS_TIMEOUT).click({
force: true,
Expand Down
6 changes: 3 additions & 3 deletions models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export interface Rule {
log_source: string;
title: string;
description: string;
tags: { value: string }[];
false_positives: { value: string }[];
tags: Array<{ value: string }>;
false_positives: Array<{ value: string }>;
level: string;
status: string;
references: { value: string }[];
references: Array<{ value: string }>;
author: string;
detection: string;
}
Expand Down
Loading

0 comments on commit 597f677

Please sign in to comment.