node-yara-rs

git clone git://archive.git.mtrnord.blog/MTRNord/node-yara-rs.git
Log | Files | Refs | README | LICENSE

commit 8c3ff2b0dd7f26a7dc1eebe2bc346c0f308029d3
parent 364c7e7f5affe2196633dd15f0f715a37ea9117f
Author: MTRNord <mtrnord1@gmail.com>
Date:   Thu,  5 Oct 2023 11:22:00 +0200

Update and add some more tests

Diffstat:
M__test__/index.spec.mjs | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
A__test__/test.yara | 14++++++++++++++
Achangelog.d/+tests.misc | 2++
Achangelog.d/+update_deps.misc | 2++
4 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/__test__/index.spec.mjs b/__test__/index.spec.mjs @@ -1,8 +1,10 @@ import test from 'ava' - +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; import { YaraCompiler } from '../index.js' const TEST_RULE = "rule TestRule {\n condition:\n true\n}" +const __dirname = dirname(fileURLToPath(import.meta.url)); test('can construct YaraCompiler', (t) => { t.plan(1) @@ -20,7 +22,6 @@ test('can load string rules', (t) => { }); }) - test('can match string rules', (t) => { t.plan(2) t.notThrows(() => { @@ -39,4 +40,68 @@ test('can match string rules', (t) => { } ]) }); +}) + +test('can load file based rules', (t) => { + t.plan(1) + t.notThrows(() => { + const compiler = new YaraCompiler([{ + filename: join(__dirname, "./test.yara") + }], []); + }); +}) + + +test('can match file based rules', (t) => { + t.plan(2) + t.notThrows(() => { + const compiler = new YaraCompiler([{ + filename: join(__dirname, "./test.yara") + }], []); + const scanner = compiler.newScanner(); + const result = scanner.scanString("Test"); + t.deepEqual(result, [ + { + identifier: "TestRule", + namespace: "default", + metadatas: [ + { + identifier: 'Author', + value: 'MTRNord', + }, + { + identifier: 'Description', + value: 'Test Rule', + }, + { + identifier: 'hash', + value: '06fdc3d7d60da6b884fd69d7d1fd3c824ec417b2b7cdd40a7bb8c9fb72fb655b', + }, + { + identifier: 'Action', + value: 'Notify', + }, + ], + tags: ["test_rule"], + strings: [ + { + identifier: '$test_string', + matches: [ + { + base: 0, + data: [ + 84, + 101, + 115, + 116 + ], + length: 4, + offset: 0, + }, + ], + }, + ] + } + ]) + }); }) \ No newline at end of file diff --git a/__test__/test.yara b/__test__/test.yara @@ -0,0 +1,13 @@ +rule TestRule : test_rule +{ + meta: + Author = "MTRNord" + Description = "Test Rule" + hash = "06fdc3d7d60da6b884fd69d7d1fd3c824ec417b2b7cdd40a7bb8c9fb72fb655b" + Action = "Notify" + strings: + $test_string = "Test" ascii nocase + + condition: + $test_string +} +\ No newline at end of file diff --git a/changelog.d/+tests.misc b/changelog.d/+tests.misc @@ -0,0 +1 @@ +Test coverage has been extended +\ No newline at end of file diff --git a/changelog.d/+update_deps.misc b/changelog.d/+update_deps.misc @@ -0,0 +1 @@ +Dependencies have been updated +\ No newline at end of file