From a716204b0f4b754480175ff2493e765f39cc6b28 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Sun, 15 Mar 2020 11:20:49 +0200 Subject: [PATCH 1/5] Updated pytest config to ignore some directories dist and node_modules --- monkey/pytest.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/monkey/pytest.ini b/monkey/pytest.ini index 3d355a4ac..3596bf5f6 100644 --- a/monkey/pytest.ini +++ b/monkey/pytest.ini @@ -4,3 +4,4 @@ log_cli_level = DEBUG log_cli_format = %(asctime)s [%(levelname)s] %(module)s.%(funcName)s.%(lineno)d: %(message)s log_cli_date_format=%H:%M:%S addopts = -v --capture=sys +norecursedirs = node_modules dist From bff9cc36b1c9409615d3c8eab436902764a0c6b8 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Sun, 15 Mar 2020 11:20:58 +0200 Subject: [PATCH 2/5] Added codecov tests to travis yml and updated readme --- .travis.yml | 27 ++++++++++++++++++--------- README.md | 24 +++++++++++++++++------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6abeb59b1..2f9fb4764 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ install: # Python - pip install -r monkey/monkey_island/requirements.txt # for unit tests - pip install flake8 pytest dlint # for next stages +- pip install coverage # for code coverage - pip install -r monkey/infection_monkey/requirements.txt # for unit tests before_script: @@ -23,24 +24,28 @@ before_script: script: # Check Python code -# Check syntax errors and fail the build if any are found. +## Check syntax errors and fail the build if any are found. - flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics -# Warn about linter issues. -# --exit-zero forces Flake8 to use the exit status code 0 even if there are errors, which means this will NOT fail the build. -# --count will print the total number of errors. -# --statistics Count the number of occurrences of each error/warning code and print a report. -# The output is redirected to a file. +## Warn about linter issues. +### --exit-zero forces Flake8 to use the exit status code 0 even if there are errors, which means this will NOT fail the build. +### --count will print the total number of errors. +### --statistics Count the number of occurrences of each error/warning code and print a report. +### The output is redirected to a file. - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics > flake8_warnings.txt -# Display the linter issues +## Display the linter issues - cat flake8_warnings.txt -# Make sure that we haven't increased the amount of warnings. +## Make sure that we haven't increased the amount of warnings. - PYTHON_WARNINGS_AMOUNT_UPPER_LIMIT=190 -- if [ $(tail -n 1 flake8_warnings.txt) -gt $PYTHON_WARNINGS_AMOUNT_UPPER_LIMIT ]; then echo "Too many warnings! Failing this build. Lower the amount of linter errors in this and try again. " && exit 1; fi +- if [ $(tail -n 1 flake8_warnings.txt) -gt $PYTHON_WARNINGS_AMOUNT_UPPER_LIMIT ]; then echo "Too many python linter warnings! Failing this build. Lower the amount of linter errors in this and try again. " && exit 1; fi +## Run unit tests - cd monkey # This is our source dir - python -m pytest # Have to use `python -m pytest` instead of `pytest` to add "{$builddir}/monkey/monkey" to sys.path. +## Calculate Code Coverage +- coverage run -m pytest discover + # Check JS code. The npm install must happen AFTER the flake8 because the node_modules folder will cause a lot of errors. - cd monkey_island/cc/ui - npm i @@ -51,6 +56,10 @@ script: - JS_WARNINGS_AMOUNT_UPPER_LIMIT=37 - eslint ./src --max-warnings $JS_WARNINGS_AMOUNT_UPPER_LIMIT +after_success: + # Upload code coverage results to codecov.io, see https://github.com/codecov/codecov-bash for more information + - bash <(curl -s https://codecov.io/bash) + notifications: slack: # Notify to slack rooms: diff --git a/README.md b/README.md index dd1d7982b..39cf1519d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # Infection Monkey -[![Build Status](https://travis-ci.com/guardicore/monkey.svg?branch=develop)](https://travis-ci.com/guardicore/monkey) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/guardicore/monkey)](https://github.com/guardicore/monkey/releases) + +[![Build Status](https://travis-ci.com/guardicore/monkey.svg?branch=develop)](https://travis-ci.com/guardicore/monkey) +[![codecov](https://codecov.io/gh/guardicore/monkey/branch/master/graph/badge.svg)](https://codecov.io/gh/guardicore/monkey) + ![GitHub stars](https://img.shields.io/github/stars/guardicore/monkey) ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/guardicore/monkey) @@ -14,14 +17,15 @@ The Infection Monkey is an open source security tool for testing a data center's - The Infection Monkey is comprised of two parts: -* Monkey - A tool which infects other machines and propagates to them -* Monkey Island - A dedicated server to control and visualize the Infection Monkey's progress inside the data center -To read more about the Monkey, visit http://infectionmonkey.com +* **Monkey** - A tool which infects other machines and propagates to them. +* **Monkey Island** - A dedicated server to control and visualize the Infection Monkey's progress inside the data center. + +To read more about the Monkey, visit [infectionmonkey.com](https://infectionmonkey.com). ## Main Features + The Infection Monkey uses the following techniques and exploits to propagate to other machines. * Multiple propagation techniques: @@ -42,13 +46,11 @@ Check out the [Setup](https://github.com/guardicore/monkey/wiki/setup) page in t The Infection Monkey supports a variety of platforms, documented [in the wiki](https://github.com/guardicore/monkey/wiki/OS-compatibility). - ## Building the Monkey from source To deploy development version of monkey you should refer to readme in the [deployment scripts](deployment_scripts) folder. If you only want to build the monkey from source, see [Setup](https://github.com/guardicore/monkey/wiki/Setup#compile-it-yourself) and follow the instructions at the readme files under [infection_monkey](infection_monkey) and [monkey_island](monkey_island). - ### Build status | Branch | Status | | ------ | :----: | @@ -56,13 +58,21 @@ and follow the instructions at the readme files under [infection_monkey](infecti | Master | [![Build Status](https://travis-ci.com/guardicore/monkey.svg?branch=master)](https://travis-ci.com/guardicore/monkey) | ## Tests + ### Unit Tests + In order to run all of the Unit Tests, run the command `python -m pytest` in the `monkey` directory. +To get a coverage report, first make sure the `coverage` package is installed using `pip install coverage`. Run the command +`coverage run -m unittest discover` in the `monkey` directory and then `coverage html`. The coverage report can be found in +`htmlcov.index`. + ### Blackbox tests + In order to run the Blackbox tests, refer to `envs/monkey_zoo/blackbox/README.md`. # License + Copyright (c) Guardicore Ltd See the [LICENSE](LICENSE) file for license rights and limitations (GPLv3). From 215dc59f12a941cc98739fa5104d7b0a45d83575 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Sun, 15 Mar 2020 11:28:46 +0200 Subject: [PATCH 3/5] Removed "discover" from coverage cmd (it's for unittest, not pytest) --- .travis.yml | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2f9fb4764..4400f7e9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,7 +44,7 @@ script: - python -m pytest # Have to use `python -m pytest` instead of `pytest` to add "{$builddir}/monkey/monkey" to sys.path. ## Calculate Code Coverage -- coverage run -m pytest discover +- coverage run -m pytest # Check JS code. The npm install must happen AFTER the flake8 because the node_modules folder will cause a lot of errors. - cd monkey_island/cc/ui diff --git a/README.md b/README.md index 39cf1519d..9e6bf5622 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ The Infection Monkey supports a variety of platforms, documented [in the wiki](h ## Building the Monkey from source To deploy development version of monkey you should refer to readme in the [deployment scripts](deployment_scripts) folder. If you only want to build the monkey from source, see [Setup](https://github.com/guardicore/monkey/wiki/Setup#compile-it-yourself) -and follow the instructions at the readme files under [infection_monkey](infection_monkey) and [monkey_island](monkey_island). +and follow the instructions at the readme files under [infection_monkey](monkey/infection_monkey) and [monkey_island](monkey/monkey_island). ### Build status | Branch | Status | @@ -64,7 +64,7 @@ and follow the instructions at the readme files under [infection_monkey](infecti In order to run all of the Unit Tests, run the command `python -m pytest` in the `monkey` directory. To get a coverage report, first make sure the `coverage` package is installed using `pip install coverage`. Run the command -`coverage run -m unittest discover` in the `monkey` directory and then `coverage html`. The coverage report can be found in +`coverage run -m unittest` in the `monkey` directory and then `coverage html`. The coverage report can be found in `htmlcov.index`. ### Blackbox tests From 9c3c9d8fba025480e50d5d2744b5687a7152eafd Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Sun, 15 Mar 2020 11:40:21 +0200 Subject: [PATCH 4/5] Created default yaml for codecov with different ranges on green (55+ is good) --- monkey/codecov.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 monkey/codecov.yml diff --git a/monkey/codecov.yml b/monkey/codecov.yml new file mode 100644 index 000000000..26d2c2031 --- /dev/null +++ b/monkey/codecov.yml @@ -0,0 +1,20 @@ +codecov: + require_ci_to_pass: yes + +coverage: + precision: 2 + round: down + range: "55...100" + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no + +comment: + layout: "reach,diff,flags,tree" + behavior: default + require_changes: no From 88fe581c2f5d38c1a0cf60dc956bd6815b81249d Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Sun, 15 Mar 2020 11:50:43 +0200 Subject: [PATCH 5/5] Updated codecov coloring. See https://docs.codecov.io/docs/coverage-configuration --- monkey/codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/codecov.yml b/monkey/codecov.yml index 26d2c2031..8d5127230 100644 --- a/monkey/codecov.yml +++ b/monkey/codecov.yml @@ -4,7 +4,7 @@ codecov: coverage: precision: 2 round: down - range: "55...100" + range: "50...90" parsers: gcov: