Skip to content

Commit

Permalink
tests : improve integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Zvi Grinberg <[email protected]>
  • Loading branch information
zvigrinberg committed Oct 12, 2023
1 parent de8d1cb commit e85ab07
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 4 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
115 changes: 114 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion 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\" --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 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'

Check failure on line 2 in test/it/end-to-end.js

View workflow job for this annotation

GitHub Actions / Lint and test project (latest)

'AnalysisReport' is defined but never used
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",

Check failure on line 30 in test/it/end-to-end.js

View workflow job for this annotation

GitHub Actions / Lint and test project (latest)

Mixed spaces and tabs
"go",

Check failure on line 31 in test/it/end-to-end.js

View workflow job for this annotation

GitHub Actions / Lint and test project (latest)

Mixed spaces and tabs
"pip"

Check failure on line 32 in test/it/end-to-end.js

View workflow job for this annotation

GitHub Actions / Lint and test project (latest)

Mixed spaces and tabs
].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 e85ab07

Please sign in to comment.