SasanLabs / VulnerableApp-facade

VulnerableApp-facade is probably most modern lightweight distributed farm of Vulnerable Applications built for handling wide range of vulnerabilities across tech stacks.
Apache License 2.0
45 stars 48 forks source link

Adding unit testing framework and unit tests to VulnerableApp Facade #56

Closed preetkaran20 closed 1 year ago

preetkaran20 commented 2 years ago

Adding unit testing framework and unit tests to VulnerableApp Facade

Dripcoding commented 2 years ago

@preetkaran20 I'd like to help with this effort by setting up jest and react-testing-library for the React application.

preetkaran20 commented 2 years ago

Sure assigned.

Dripcoding commented 2 years ago

@preetkaran20 First PR towards this effort :)

Dripcoding commented 2 years ago

took a break but am back. Wrote some unit tests for the LeftNav https://github.com/SasanLabs/VulnerableApp-facade/pull/69

Dripcoding commented 2 years ago

added unit tests for the HomePage.tsx https://github.com/SasanLabs/VulnerableApp-facade/pull/70

Dripcoding commented 2 years ago

added unit tests for the VulnerableApp CommandInjection main content https://github.com/SasanLabs/VulnerableApp-facade/pull/72

preetkaran20 commented 2 years ago

@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?

Dripcoding commented 2 years ago

@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.

Dripcoding commented 2 years ago

@preetkaran20 Ok I think this should fix the errors

https://github.com/SasanLabs/VulnerableApp-facade/pull/74

preetkaran20 commented 2 years ago

@Dripcoding thanks for looking into the issue.

preetkaran20 commented 2 years ago

@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.

Dripcoding commented 2 years ago

hm ok I've opened another PR: https://github.com/SasanLabs/VulnerableApp-facade/pull/76/

preetkaran20 commented 2 years ago

sure, let me check again.

preetkaran20 commented 2 years ago

@Dripcoding I was checking the percentage of code coverage for VulnerableApp Facade, and it is 40%. Thanks a lot and amazing work.

preetkaran20 commented 2 years ago
image image
Dripcoding commented 2 years ago

Your welcome :) I'm very happy to see the code coverage going up. We can definitely improve it if we do some refactoring and exclude files that don't need to be included in the reports.

I ran the Jest code coverage tool locally to obtain some more detailed results:

codeCoverage
preetkaran20 commented 2 years ago

Command to update the Jest snapshots: npm test -- --updateSnapshot