Skip to content

YAML Rule Editor Support #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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
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