Skip to content

Commit

Permalink
test: improve integration tests (#62)
Browse files Browse the repository at this point in the history
* tests : improve integration tests

* test: analysis_test.js tests broke in node 20.8.1
interception of http requests are without request' headers ( in node version 20.8.0 it didn't happen)

---------

Signed-off-by: Zvi Grinberg <[email protected]>
  • Loading branch information
zvigrinberg authored Oct 15, 2023
1 parent de8d1cb commit 894a1e6
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 68 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ jobs:
run: npm run compile

- name: Run integration tests
working-directory: integration
run: EXHORT_ITS_USE_REAL_API=true bash ./run_its.sh
run: npm run integration-tests

- name: Upload coverage reports
if: ${{ matrix.node == env.MAIN_NODE_VER }}
Expand Down
104 changes: 42 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
"lint:fix": "eslint src test --ext js --fix",
"test": "c8 npm run tests",
"localtest": "EXHORT_PIP3_PATH=/home/zgrinber/python3.9/bin/pip3 EXHORT_PYTHON3_PATH=/home/zgrinber/python3.9/bin/python3 c8 npm run tests",
"tests": "mocha",
"tests": "mocha --grep \"Integration Tests|.*analysis module.*\" --invert",
"tests:rep": "mocha --reporter-option maxDiffSize=0 --reporter json > unit-tests-result.json",
"integration-tests": "mocha --grep \"Integration Tests\"",
"precompile": "rm -rf dist",
"compile": "tsc -p tsconfig.json",
"pregen:backend": "rm -rf generated",
Expand All @@ -58,7 +59,7 @@
"eslint": "^8.42.0",
"eslint-plugin-editorconfig": "^4.0.3",
"mocha": "^10.2.0",
"msw": "^1.2.2",
"msw": "^1.3.2",
"sinon": "^15.1.2",
"sinon-chai": "^3.7.0",
"typescript": "^5.1.3"
Expand All @@ -80,7 +81,8 @@
],
"exclude": [
"src/cli.js",
"src/index.js"
"src/index.js",
"src/analysis.js"
],
"lines": 85,
"reporter": [
Expand Down
101 changes: 101 additions & 0 deletions test/it/end-to-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import fs from "node:fs";
// import {AnalysisReport} from '../../generated/backend/AnalysisReport.js'
import index from "../../src/index.js"
import { expect } from 'chai'
// import fs from 'node:fs'

function getManifestNamePerPm(packageManager) {
return packageManagersDict[packageManager];
}

const packageManagersDict =
{
"maven" : "pom.xml",
"npm" : "package.json",
"go" : "go.mod",
"pip" : "requirements.txt"
}

function getParsedSummaryFromHtml(html) {
return JSON.parse(html.substring(html.indexOf("\"summary\"") + 10,html.indexOf("\"}]}") + 4));
}

suite('Integration Tests', () => {
// let opts = {
// EXHORT_DEV_MODE: "true",
// EXHORT_SNYK_TOKEN: "ee64316c-a4ba-4ca0-a785-18cb05ed3f25"
//
// }
["maven",
"npm",
"go",
"pip"
].forEach(packageManager => {
test(`Stack Analysis json for ${packageManager}`, async () => {
// process.env["EXHORT_DEBUG"]= "true"
// process.env["EXHORT_DEV_MODE"]= "false"
// process.env["EXHORT_GO_PATH"]= "/home/zgrinber/test-go/go/bin/go"
// process.env["RHDA_TOKEN"] = "34JKLDS-4234809-66666666666"
// process.env["RHDA_SOURCE"] = "Zvika Client"
// let result = await index.stackAnalysis("/tmp/rajan-0410/go.mod", false, opts);
if(packageManager === "pip")
{
process.env["EXHORT_PYTHON_VIRTUAL_ENV"] = "true"
}
else
{
process.env["EXHORT_PYTHON_VIRTUAL_ENV"] = ""
}
let manifestName = getManifestNamePerPm(packageManager)
let pomPath = `test/it/test_manifests/${packageManager}/${manifestName}`
let providedDataForStack = await index.stackAnalysis(pomPath)
console.log(JSON.stringify(providedDataForStack.summary,null , 4))
expect(providedDataForStack.summary.dependencies.scanned).greaterThan(0)
// python transitive count for stack analysis is awaiting fix in exhort backend
if(packageManager !== "pip")
{
expect(providedDataForStack.summary.dependencies.transitive).greaterThan(0)
}
expect(providedDataForStack.summary.vulnerabilities.total).greaterThanOrEqual(0)
providedDataForStack.summary.providerStatuses.forEach(provider => expect(provider.status).equals(200))
}).timeout(15000);

test(`Stack Analysis html for ${packageManager}`, async () => {
let manifestName = getManifestNamePerPm(packageManager)
let pomPath = `test/it/test_manifests/${packageManager}/${manifestName}`
let html = await index.stackAnalysis(pomPath,true)
if(packageManager === "pip")
{
process.env["EXHORT_PYTHON_VIRTUAL_ENV"] = "true"
}
else
{
process.env["EXHORT_PYTHON_VIRTUAL_ENV"] = ""
}
let parsedSummaryFromHtml = getParsedSummaryFromHtml(html);
expect( typeof html).equals("string")
expect(html).include("html").include("svg")
expect(parsedSummaryFromHtml.dependencies.scanned).greaterThan(0)
// python transitive count for stack analysis is awaiting fix in exhort backend
if(packageManager !== "pip")
{
expect(parsedSummaryFromHtml.dependencies.transitive).greaterThan(0)
}
expect(parsedSummaryFromHtml.vulnerabilities.total).greaterThanOrEqual(0)
parsedSummaryFromHtml.providerStatuses.forEach(provider => expect(provider.status).equals(200))
}).timeout(15000);

test(`Component Analysis for ${packageManager}`, async () => {
let manifestName = getManifestNamePerPm(packageManager)
let pomPath = `test/it/test_manifests/${packageManager}/${manifestName}`
let analysisReport = await index.componentAnalysis(manifestName,fs.readFileSync(pomPath).toString())

expect(analysisReport.summary.dependencies.scanned).greaterThan(0)
expect(analysisReport.summary.dependencies.transitive).equal(0)
expect(analysisReport.summary.vulnerabilities.total).greaterThanOrEqual(0)
analysisReport.summary.providerStatuses.forEach(provider => expect(provider.status).equals(200))
}).timeout(10000);


});
});
10 changes: 10 additions & 0 deletions test/it/test_manifests/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/test-golang-namespace/test-golang-app

go 1.19

require(

github.com/gin-gonic/gin v1.6.0
github.com/ipld/go-car v0.3.0
go.elastic.co/apm v1.11.0
)
30 changes: 30 additions & 0 deletions test/it/test_manifests/maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>pom-with-deps-no-ignore</groupId>
<artifactId>pom-with-dependency-not-ignored-for-tests</artifactId>
<version>0.0.1</version>

<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.0</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 894a1e6

Please sign in to comment.