Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 1 addition & 5 deletions src/providers/requirements_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { Language, Parser, Query } from 'web-tree-sitter';
const require = createRequire(import.meta.url);

async function init() {
await Parser.init({
locateFile() {
return require.resolve('web-tree-sitter/web-tree-sitter.wasm')
}
});
await Parser.init();
return await Language.load(require.resolve('tree-sitter-requirements/tree-sitter-requirements.wasm'));
}

Expand Down
92 changes: 46 additions & 46 deletions test/providers/python_pip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function sharedComponentAnalysisTestFlow(testCase, usePipDepTreeUtility) {
let expectedSbom = fs.readFileSync(`test/providers/tst_manifests/pip/${testCase}/expected_component_sbom.json`).toString().trim()
expectedSbom = JSON.stringify(JSON.parse(expectedSbom))
// invoke sut stack analysis for scenario manifest
let opts = { "TRUSTIFY_DA_PIP_USE_DEP_TREE" : usePipDepTreeUtility }
Comment thread
Strum355 marked this conversation as resolved.
let opts = { TRUSTIFY_DA_PIP_USE_DEP_TREE: usePipDepTreeUtility.toString() }
let providedDatForComponent = await pythonPip.provideComponent(`test/providers/tst_manifests/pip/${testCase}/requirements.txt`, opts)
// verify returned data matches expectation
expect(providedDatForComponent).to.deep.equal({
Expand All @@ -34,7 +34,7 @@ async function sharedStackAnalysisTestFlow(testCase, usePipDepTreeUtility) {
} catch (error) {
throw new Error('fail installing requirements.txt manifest in created virtual python environment', {cause: error})
}
let opts = { "TRUSTIFY_DA_PIP_USE_DEP_TREE" : usePipDepTreeUtility }
let opts = { TRUSTIFY_DA_PIP_USE_DEP_TREE: usePipDepTreeUtility.toString() }
let providedDataForStack = await pythonPip.provideStack(`test/providers/tst_manifests/pip/${testCase}/requirements.txt`, opts)
// new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date

Expand All @@ -48,14 +48,14 @@ async function sharedStackAnalysisTestFlow(testCase, usePipDepTreeUtility) {
}

suite('testing the python-pip data provider', () => {
// [
// {name: 'requirements.txt', expected: true},
// {name: 'some_other.file', expected: false}
// ].forEach(testCase => {
// test(`verify isSupported returns ${testCase.expected} for ${testCase.name}`, () =>
// expect(pythonPip.isSupported(testCase.name)).to.equal(testCase.expected)
// )
// });
[
{name: 'requirements.txt', expected: true},
{name: 'some_other.file', expected: false}
].forEach(testCase => {
test(`verify isSupported returns ${testCase.expected} for ${testCase.name}`, () =>
expect(pythonPip.isSupported(testCase.name)).to.equal(testCase.expected)
)
});

[
// "pip_requirements_txt_no_ignore",
Expand All @@ -72,46 +72,46 @@ suite('testing the python-pip data provider', () => {
// these test cases takes ~1400-2000 ms each pr >10000 in CI (for the first test-case)
}).timeout(process.env.GITHUB_ACTIONS ? 15000 : 10000)

// test(`verify requirements.txt sbom provided for stack analysis using pipdeptree utility with scenario ${scenario}`, () => {
// sharedStackAnalysisTestFlow(testCase, true);
// // these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
// }).timeout(process.env.GITHUB_ACTIONS ? 30000 : 10000)
test(`verify requirements.txt sbom provided for stack analysis using pipdeptree utility with scenario ${scenario}`, async () => {
await sharedStackAnalysisTestFlow(testCase, true);
// these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
}).timeout(process.env.GITHUB_ACTIONS ? 30000 : 10000)

// test(`verify requirements.txt sbom provided for component analysis using pipdeptree utility with scenario ${scenario}`, () => {
// sharedComponentAnalysisTestFlow(testCase, true);
// // these test cases takes ~1400-2000 ms each pr >10000 in CI (for the first test-case)
// }).timeout(process.env.GITHUB_ACTIONS ? 15000 : 10000)
test(`verify requirements.txt sbom provided for component analysis using pipdeptree utility with scenario ${scenario}`, async () => {
await sharedComponentAnalysisTestFlow(testCase, true);
// these test cases takes ~1400-2000 ms each pr >10000 in CI (for the first test-case)
}).timeout(process.env.GITHUB_ACTIONS ? 15000 : 10000)
});

}).beforeAll(() => clock = useFakeTimers(new Date('2023-10-01T00:00:00.000Z'))).afterAll(()=> clock.restore());

// suite('testing the python-pip data provider with virtual environment', () => {
// [
// "pip_requirements_virtual_env_txt_no_ignore",
// "pip_requirements_virtual_env_with_ignore"
// ].forEach(testCase => {
// let scenario = testCase.replace('pip_requirements_', '').replaceAll('_', ' ')
// test(`verify requirements.txt sbom provided for stack analysis using virutal python environment, with scenario ${scenario}`, async () => {
// // load the expected sbom stack analysis
// let expectedSbom = fs.readFileSync(`test/providers/tst_manifests/pip/${testCase}/expected_stack_sbom.json`,).toString()
// process.env["TRUSTIFY_DA_PYTHON_VIRTUAL_ENV"] = "true"
// // process.env["TRUSTIFY_DA_DEBUG"] = "true"
// expectedSbom = JSON.stringify(JSON.parse(expectedSbom), null, 4)
// // invoke sut stack analysis for scenario manifest
// let providedDataForStack = await pythonPip.provideStack(`test/providers/tst_manifests/pip/${testCase}/requirements.txt`)
// // new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date
suite('testing the python-pip data provider with virtual environment', () => {
[
"pip_requirements_virtual_env_txt_no_ignore",
"pip_requirements_virtual_env_with_ignore"
].forEach(testCase => {
let scenario = testCase.replace('pip_requirements_', '').replaceAll('_', ' ')
test(`verify requirements.txt sbom provided for stack analysis using virutal python environment, with scenario ${scenario}`, async () => {
// load the expected sbom stack analysis
let expectedSbom = fs.readFileSync(`test/providers/tst_manifests/pip/${testCase}/expected_stack_sbom.json`,).toString()
expectedSbom = JSON.stringify(JSON.parse(expectedSbom), null, 4)
// invoke sut stack analysis for scenario manifest
let providedDataForStack = await pythonPip.provideStack(`test/providers/tst_manifests/pip/${testCase}/requirements.txt`, {
TRUSTIFY_DA_PYTHON_VIRTUAL_ENV: "true"
})
// new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date

// // providedDataForStack.content = providedDataForStack.content.replaceAll("\"timestamp\":\"[a-zA-Z0-9\\-\\:]+\"","")
// // verify returned data matches expectation
// providedDataForStack.content = JSON.stringify(JSON.parse(providedDataForStack.content), null, 4)
// expect(providedDataForStack.content).to.deep.equal(expectedSbom)
// // expect(providedDataForStack).to.deep.equal({
// // ecosystem: 'pip',
// // contentType: 'application/vnd.cyclonedx+json',
// // content: expectedSbom
// // })
// // these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
// }).timeout(process.env.GITHUB_ACTIONS ? 60000 : 30000)
// })
// providedDataForStack.content = providedDataForStack.content.replaceAll("\"timestamp\":\"[a-zA-Z0-9\\-\\:]+\"","")
// verify returned data matches expectation
providedDataForStack.content = JSON.stringify(JSON.parse(providedDataForStack.content), null, 4)
expect(providedDataForStack.content).to.deep.equal(expectedSbom)
// expect(providedDataForStack).to.deep.equal({
// ecosystem: 'pip',
// contentType: 'application/vnd.cyclonedx+json',
// content: expectedSbom
// })
// these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
}).timeout(process.env.GITHUB_ACTIONS ? 60000 : 30000)
})

// }).beforeAll(() => {clock = useFakeTimers(new Date('2023-10-01T00:00:00.000Z'))}).afterAll(()=> clock.restore());
}).beforeAll(() => {clock = useFakeTimers(new Date('2023-10-01T00:00:00.000Z'))}).afterAll(()=> clock.restore());
Loading