Adding unit testing framework and unit tests to VulnerableApp Facade
preetkaran20 opened this issue · comments
Adding unit testing framework and unit tests to VulnerableApp Facade
@preetkaran20 I'd like to help with this effort by setting up jest and react-testing-library for the React application.
Sure assigned.
@preetkaran20 First PR towards this effort :)
took a break but am back. Wrote some unit tests for the LeftNav
#69
added unit tests for the HomePage.tsx #70
added unit tests for the VulnerableApp CommandInjection main content #72
@Dripcoding I am seeing some errors while running npm test in my PR: https://github.com/SasanLabs/VulnerableApp-facade/runs/7307184077?check_suite_focus=true
It seems like it is trying to connect to the docker container. Do we need docker container to be running?
@preetkaran20 Thanks for bringing this up! I assume you mean these warnings:
console.error Error: Error: connect ECONNREFUSED 127.0.0.1:80 at Object.dispatchError (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19) at Request.<anonymous> (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18) at Request.emit (events.js:412:35) at ClientRequest.<anonymous> (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14) at ClientRequest.emit (events.js:400:28) at Socket.socketErrorListener (_http_client.js:475:9) at Socket.emit (events.js:400:28) at emitErrorNT (internal/streams/destroy.js:106:8) at emitErrorCloseNT (internal/streams/destroy.js:74:3) at processTicksAndRejections (internal/process/task_queues.js:82:21) undefined at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45) at Object.dispatchError (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:66:53) at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18) at ClientRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14)
It looks like the tests are attempting to fetch the content from the BE service which is not ideal. I'll work on a fix for this.
@preetkaran20 Ok I think this should fix the errors
@Dripcoding thanks for looking into the issue.
@Dripcoding I am still facing this issue:
console.error
Error: Error: connect ECONNREFUSED 127.0.0.1:80
at Object.dispatchError (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19)
at Request.<anonymous> (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
at Request.emit (events.js:412:35)
at ClientRequest.<anonymous> (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14)
at ClientRequest.emit (events.js:400:28)
at Socket.socketErrorListener (_http_client.js:475:9)
at Socket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) undefined
at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
at Object.dispatchError (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:66:53)
at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
at ClientRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14)
console.error
Error: Error: connect ECONNREFUSED 127.0.0.1:80
at Object.dispatchError (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19)
at Request.<anonymous> (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
at Request.emit (events.js:412:35)
at ClientRequest.<anonymous> (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14)
at ClientRequest.emit (events.js:400:28)
at Socket.socketErrorListener (_http_client.js:475:9)
at Socket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) undefined
at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
at Object.dispatchError (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:66:53)
at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
at ClientRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14)
console.error
Error: Error: connect ECONNREFUSED 127.0.0.1:80
at Object.dispatchError (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19)
at Request.<anonymous> (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
at Request.emit (events.js:412:35)
at ClientRequest.<anonymous> (/home/runner/work/VulnerableApp-facade/VulnerableApp-facade/facade-app/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14)
at ClientRequest.emit (events.js:400:28)
at Socket.socketErrorListener (_http_client.js:475:9)
at Socket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) undefined
at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
at Object.dispatchError (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:66:53)
at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
at ClientRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14)
though i have merged the newer code changes.
hm ok I've opened another PR: #76
sure, let me check again.
@Dripcoding I was checking the percentage of code coverage for VulnerableApp Facade, and it is 40%. Thanks a lot and amazing work.
Command to update the Jest snapshots: npm test -- --updateSnapshot