diff --git a/.travis.yml b/.travis.yml
index d6b9ca212..34f49efe0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,12 +9,20 @@ cache: pip
python:
- 3.7
+os: linux
+
install:
+# Python
- pip install -r monkey/monkey_island/requirements.txt # for unit tests
- pip install flake8 pytest dlint # for next stages
- pip install -r monkey/infection_monkey/requirements_linux.txt # for unit tests
before_script:
+# Set the server config to `testing`. This is required for for the UTs to pass.
+- python monkey/monkey_island/cc/set_server_config.py testing
+
+script:
+# Check Python code
# Check syntax errors and fail the build if any are found.
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
@@ -27,16 +35,22 @@ before_script:
# Display the linter issues
- cat flake8_warnings.txt
# Make sure that we haven't increased the amount of warnings.
-- WARNINGS_AMOUNT_UPPER_LIMIT=190
-- if [ $(tail -n 1 flake8_warnings.txt) -gt $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
+- 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
-# Set the server config to `testing`, for the UTs to use mongomaock and pass.
-- python monkey/monkey_island/cc/set_server_config.py testing
-
-script:
- 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.
+# 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
+- npm i -g eslint
+- cd -
+- cd monkey_island/cc/ui
+- eslint ./src --quiet
+- JS_WARNINGS_AMOUNT_UPPER_LIMIT=29
+- eslint ./src --max-warnings $JS_WARNINGS_AMOUNT_UPPER_LIMIT
+
notifications:
slack: # Notify to slack
rooms:
diff --git a/monkey/monkey_island/cc/environment/testing.py b/monkey/monkey_island/cc/environment/testing.py
index 087c3a2e3..e504a8357 100644
--- a/monkey/monkey_island/cc/environment/testing.py
+++ b/monkey/monkey_island/cc/environment/testing.py
@@ -2,6 +2,11 @@ from monkey_island.cc.environment import Environment
class TestingEnvironment(Environment):
+ """
+ Use this environment for running Unit Tests.
+ This will cause all mongo connections to happen via `mongomock` instead of using an actual mongodb instance.
+ """
+
def __init__(self):
super(TestingEnvironment, self).__init__()
self.testing = True
diff --git a/monkey/monkey_island/cc/models/__init__.py b/monkey/monkey_island/cc/models/__init__.py
index d8c1b05c8..94d56d6a8 100644
--- a/monkey/monkey_island/cc/models/__init__.py
+++ b/monkey/monkey_island/cc/models/__init__.py
@@ -6,7 +6,7 @@ from monkey_island.cc.environment.environment import env
# If testing, use mongomock which only emulates mongo. for more information, see
# http://docs.mongoengine.org/guide/mongomock.html .
# Otherwise, use an actual mongod instance with connection parameters supplied by env.
-if env.testing:
+if env.testing: # See monkey_island.cc.environment.testing
connect('mongoenginetest', host='mongomock://localhost')
else:
connect(db=env.mongo_db_name, host=env.mongo_db_host, port=env.mongo_db_port)
diff --git a/monkey/monkey_island/cc/services/reporting/zero_trust_service.py b/monkey/monkey_island/cc/services/reporting/zero_trust_service.py
index 9937c0b6d..dd6fad1bc 100644
--- a/monkey/monkey_island/cc/services/reporting/zero_trust_service.py
+++ b/monkey/monkey_island/cc/services/reporting/zero_trust_service.py
@@ -68,7 +68,8 @@ class ZeroTrustService(object):
all_statuses |= set(Finding.objects(test=test).distinct("status"))
for status in all_statuses:
- if zero_trust_consts.ORDERED_TEST_STATUSES.index(status) < zero_trust_consts.ORDERED_TEST_STATUSES.index(worst_status):
+ if zero_trust_consts.ORDERED_TEST_STATUSES.index(status) \
+ < zero_trust_consts.ORDERED_TEST_STATUSES.index(worst_status):
worst_status = status
return worst_status
@@ -95,7 +96,8 @@ class ZeroTrustService(object):
"""
current_worst_status = zero_trust_consts.STATUS_UNEXECUTED
for finding in all_findings_for_test:
- if zero_trust_consts.ORDERED_TEST_STATUSES.index(finding.status) < zero_trust_consts.ORDERED_TEST_STATUSES.index(current_worst_status):
+ if zero_trust_consts.ORDERED_TEST_STATUSES.index(finding.status) \
+ < zero_trust_consts.ORDERED_TEST_STATUSES.index(current_worst_status):
current_worst_status = finding.status
return current_worst_status
diff --git a/monkey/monkey_island/cc/ui/package.json b/monkey/monkey_island/cc/ui/package.json
index b6f2fdc9f..8a0cf167c 100644
--- a/monkey/monkey_island/cc/ui/package.json
+++ b/monkey/monkey_island/cc/ui/package.json
@@ -5,8 +5,8 @@
"scripts": {
"clean": "rimraf dist/*",
"copy": "copyfiles -f ./src/index.html ./src/favicon.ico ./dist",
- "dist": "webpack --mode production",
- "dev": "webpack --mode development",
+ "dist": "webpack --mode production && copyfiles -f ./src/favicon.ico ./dist",
+ "dev": "webpack --mode development && copyfiles -f ./src/favicon.ico ./dist",
"lint": "eslint ./src",
"posttest": "npm run lint",
"release:major": "npm version major && npm publish && git push --follow-tags",
@@ -14,7 +14,7 @@
"release:patch": "npm version patch && npm publish && git push --follow-tags",
"serve": "node server.js --env=dev",
"serve:dist": "node server.js --env=dist",
- "start": "webpack-dev-server --mode development --open --history-api-fallback --port 8000",
+ "start": "webpack-dev-server --verbose --mode development --open --history-api-fallback --port 8000",
"test": "karma start",
"test:watch": "karma start --autoWatch=true --singleRun=false"
},
diff --git a/monkey/monkey_island/cc/ui/src/components/Main.js b/monkey/monkey_island/cc/ui/src/components/Main.js
index 09038292e..9f4b18bc8 100644
--- a/monkey/monkey_island/cc/ui/src/components/Main.js
+++ b/monkey/monkey_island/cc/ui/src/components/Main.js
@@ -14,7 +14,7 @@ import ZeroTrustReportPage from 'components/pages/ZeroTrustReportPage';
import LicensePage from 'components/pages/LicensePage';
import AuthComponent from 'components/AuthComponent';
import LoginPageComponent from 'components/pages/LoginPage';
-import Notifier from "react-desktop-notification"
+import Notifier from 'react-desktop-notification'
import 'normalize.css/normalize.css';
@@ -22,7 +22,7 @@ import 'react-data-components/css/table-twbs.css';
import 'styles/App.css';
import 'react-toggle/style.css';
import 'react-table/react-table.css';
-import VersionComponent from "./side-menu/VersionComponent";
+import VersionComponent from './side-menu/VersionComponent';
let logoImage = require('../images/monkey-icon.svg');
let infectionMonkeyImage = require('../images/infection-monkey.svg');
@@ -63,7 +63,7 @@ class AppComponent extends AuthComponent {
};
renderRoute = (route_path, page_component, is_exact_path = false) => {
- let render_func = (props) => {
+ let render_func = () => {
switch (this.state.isLoggedIn) {
case true:
return page_component;
@@ -92,7 +92,7 @@ class AppComponent extends AuthComponent {
infection_done: false,
report_done: false,
isLoggedIn: undefined
- },
+ }
};
}
@@ -194,7 +194,7 @@ class AppComponent extends AuthComponent {