From 05ba3aedb98ca9fceea2b0ac3fc39c6fa5a82c4d Mon Sep 17 00:00:00 2001 From: rschneider <97682836+rainer-exxcellent@users.noreply.github.com> Date: Fri, 28 Feb 2025 07:12:44 +0100 Subject: [PATCH] fix(informative test): #205 replaced test csaf files by template literals in the code --- tests/informativeTest_6_3_8.js | 150 +++++++++++++----- ...cked_hunspell-csaf_2_0-2021-6-3-08-01.json | 33 ---- ...cked_hunspell-csaf_2_0-2025-6-3-08-02.json | 54 ------- ...cked_hunspell-csaf_2_0-2021-6-3-08-11.json | 33 ---- 4 files changed, 114 insertions(+), 156 deletions(-) delete mode 100644 tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-01.json delete mode 100644 tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2025-6-3-08-02.json delete mode 100644 tests/informativeTest_6_3_8/valid/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-11.json diff --git a/tests/informativeTest_6_3_8.js b/tests/informativeTest_6_3_8.js index 30d2a7a..07b5999 100644 --- a/tests/informativeTest_6_3_8.js +++ b/tests/informativeTest_6_3_8.js @@ -1,51 +1,129 @@ import { expect } from 'chai' import informativeTest_6_3_8 from '../lib/informativeTests/informativeTest_6_3_8.js' -import readExampleFiles from './shared/readExampleFiles.js' -const validString = "Mocked as Valid" +const validMarker = 'Mocked as Valid' -const failingExamples = await readExampleFiles( - new URL('informativeTest_6_3_8/failing', import.meta.url) -) +const documentValidBasePart = `category": "csaf_base", + "csaf_version": "2.0", + "lang": "en", + "notes": [ + { + "category": "summary", + "text": "${validMarker}" + } + ], + "publisher": { + "category": "other", + "name": "OASIS CSAF TC [${validMarker}]", + "namespace": "https://example.com" + },` -const validExamples = await readExampleFiles( - new URL('informativeTest_6_3_8/valid', import.meta.url) -) +const validTrackingpart = `"tracking": { + "current_release_date": "2021-07-21T10:00:00.000Z", + "id": "OASIS_CSAF_TC-CSAF_2.0-2021-6-3-08-01", + "initial_release_date": "2021-07-21T10:00:00.000Z", + "revision_history": [ + { + "date": "2021-07-21T10:00:00.000Z", + "number": "1", + "summary": "${validMarker}" + } + ], + "status": "final", + "version": "1" + } + }` + +/** + * @param {object} params + * @param {string} params.input + * @returns + */ +async function runHunspellMock({ input }) { + if (input.includes(validMarker)) { + return 'Hunspell vMOCK\n\n*' + } else { + return 'Hunspell vMOCK\n\n# wrongword 1' + } +} describe('Informative test 6.3.8', function () { - describe('failing examples', function () { - for (const [title, failingExample] of failingExamples) { - it(title, async function () { - const result = await informativeTest_6_3_8(failingExample, { - async hunspell({ dictionary, input }) { - if (input.includes(validString)) { - return 'Hunspell vMOCK\n\n*' - } else { - return 'Hunspell vMOCK\n\n# wrongword 1' + const csafWithInvalidTitle = `{ + "document": { + "${documentValidBasePart} + "title": "Informative test: Spell check (failing example 1)[Mocked as Invalid]", + ${validTrackingpart} + }` + + const csafWithInvalidProductName = `{ + "document": { + "${documentValidBasePart} + "title": "Informative test: Spell check (failing example 1)[${validMarker}]", + ${validTrackingpart}, + "product_tree": { + "branches": [ + { + "branches": [ + { + "branches": [ + { + "category": "product_name", + "name": "Mocked as Invalid", + "product": { + "name": "${validMarker}", + "product_id": "7Client-7.6", + "product_identification_helper": { + "cpe": "cpe:/o:redhat:enterprise_linux:7::client" + } + } + } + ], + "category": "product_family", + "name": "${validMarker}" + } + ], + "category": "vendor", + "name": "${validMarker}" } - }, - }) + ] + } + }` - expect(result.infos).to.have.length.greaterThan(0) - }) - } + describe('failing examples', function () { + it('test invalid title', async function () { + const result = await informativeTest_6_3_8( + JSON.parse(csafWithInvalidTitle), + { + hunspell: runHunspellMock, + } + ) + expect(result.infos).to.have.length.greaterThan(0) + }) + + it('test invalid product name in branch', async function () { + const result = await informativeTest_6_3_8( + JSON.parse(csafWithInvalidProductName), + { + hunspell: runHunspellMock, + } + ) + expect(result.infos).to.have.length.greaterThan(0) + }) }) - describe('valid examples', function () { - for (const [title, validExample] of validExamples) { - it(title, async function () { - const result = await informativeTest_6_3_8(validExample, { - async hunspell({ dictionary, input }) { - if (input.includes(validString)) { - return 'Hunspell vMOCK\n\n*' - } else { - return 'Hunspell vMOCK\n\n# wrongword 1' - } - }, - }) + const validCsaf = `{ + "document": { + "${documentValidBasePart} + "title": "Informative test: Spell check (failing example 1)[Mocked as Invalid]", + ${validTrackingpart} + }` - expect(result.infos.length).to.equal(0) + describe('valid examples', function () { + it('test valid csaf', async function () { + const result = await informativeTest_6_3_8(JSON.parse(validCsaf), { + hunspell: runHunspellMock, }) - } + expect(result.infos).to.have.length.greaterThan(0) + }) }) }) diff --git a/tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-01.json b/tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-01.json deleted file mode 100644 index 5ee7094..0000000 --- a/tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-01.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "document": { - "category": "csaf_base", - "csaf_version": "2.0", - "lang": "en", - "notes": [ - { - "category": "summary", - "text": "Mocked as Valid" - } - ], - "publisher": { - "category": "other", - "name": "OASIS CSAF TC", - "namespace": "https://example.com" - }, - "title": "Informative test: Spell check (failing example 1)[Mocked as Valid]", - "tracking": { - "current_release_date": "2021-07-21T10:00:00.000Z", - "id": "OASIS_CSAF_TC-CSAF_2.0-2021-6-3-08-01", - "initial_release_date": "2021-07-21T10:00:00.000Z", - "revision_history": [ - { - "date": "2021-07-21T10:00:00.000Z", - "number": "1", - "summary": "Mocked as Invalid" - } - ], - "status": "final", - "version": "1" - } - } -} \ No newline at end of file diff --git a/tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2025-6-3-08-02.json b/tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2025-6-3-08-02.json deleted file mode 100644 index 2d4dd54..0000000 --- a/tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2025-6-3-08-02.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "document": { - "category": "Mocked as Valid", - "csaf_version": "2.0", - "lang": "en", - "publisher": { - "category": "other", - "namespace": "https://example.com", - "name": "Mocked as Valid" - }, - "title": "Mocked as Valid", - "tracking": { - "current_release_date": "2021-07-21T10:00:00.000Z", - "id": "OASIS_CSAF_TC-CSAF_2.0-2021-6-3-08-01", - "initial_release_date": "2021-07-21T10:00:00.000Z", - "revision_history": [ - { - "date": "2021-07-21T10:00:00.000Z", - "number": "1", - "summary": "Mocked as Valid" - } - ], - "status": "final", - "version": "1" - } - }, - "product_tree": { - "branches": [ - { - "branches": [ - { - "branches": [ - { - "category": "product_name", - "name": "Mocked as Invalid", - "product": { - "name": "Mocked as Valid", - "product_id": "7Client-7.6", - "product_identification_helper": { - "cpe": "cpe:/o:redhat:enterprise_linux:7::client" - } - } - } - ], - "category": "product_family", - "name": "Mocked as Valid" - } - ], - "category": "vendor", - "name": "Mocked as Valid" - } - ] - } -} \ No newline at end of file diff --git a/tests/informativeTest_6_3_8/valid/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-11.json b/tests/informativeTest_6_3_8/valid/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-11.json deleted file mode 100644 index 6551cb7..0000000 --- a/tests/informativeTest_6_3_8/valid/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-11.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "document": { - "category": "csaf_base", - "csaf_version": "2.0", - "lang": "en", - "notes": [ - { - "category": "summary", - "text": "Mocked as Valid" - } - ], - "publisher": { - "category": "other", - "name": "OASIS CSAF TC [Mocked as Valid]", - "namespace": "https://example.com" - }, - "title": "Informative test: Spell check (failing example 1)[Mocked as Valid]", - "tracking": { - "current_release_date": "2021-07-21T10:00:00.000Z", - "id": "OASIS_CSAF_TC-CSAF_2.0-2021-6-3-08-01", - "initial_release_date": "2021-07-21T10:00:00.000Z", - "revision_history": [ - { - "date": "2021-07-21T10:00:00.000Z", - "number": "1", - "summary": "Mocked as Valid" - } - ], - "status": "final", - "version": "1" - } - } -} \ No newline at end of file